Basic Test: Car

We can't just assume that all variables go in the private section and that all functions go in the public section. Attributes/Member data are typically private and operations/member functions are typically public, but it is possible to have public data (which is rare) and private functions. So you must look at the visibility symbol on the left-hand side of each feature: "+" indicates a public feature while "-" indicates a private feature. You have the option of putting the private features together, and the public features together. Alternatively, you can create multiple public and private sections as needed to keep the variables and the functions separate.

Version 1: Variables and Functions Separate

class Car
{
	private:
		string	model;
		int	wheels;
		double	engine_size;

	public:
			Car(string a_name, int a_wheels, double a_engine_size);
		string	get_model();
		bool	is_running();
		void	set_wheels(int w);
		double	accelerate(int fuel_rate);

	public:
		string	vin;

	private:
		int	diagnostics(char system);
};

Version 2: Private and Public Features Together

class Car
{
	private:
		string	model;
		int	wheels;
		double	engine_size;
		int	diagnostics(char system);

	public:
			Car(string a_name, int a_wheels, double a_engine_size);
		string	get_model();
		bool	is_running();
		void	set_wheels(int w);
		double	accelerate(int fuel_rate);
		string	vin;
};


  1. Unlike Java, the public and private keywords are not applied to the class or to individual features. In C++, public and private label sections of a class and every feature that appears after a label exhibits the labeled accessibility. A class typically has two labeled sections but may have more if needed.
    		class ________
    		{
    			private:
    				feature1;
    				feature2;
    			public:
    				feature3;
    				feature4;
    		};
  2. UML class diagrams do not specify any of the details of the class behaviors or operations (although other UML diagrams may). So, when we translate UML class diagrams into C++, the translation process only specifies the function prototypes or signatures and does not specify the contents of the function bodies.