[ Pobierz całość w formacie PDF ]
.Can member data be public?7.If you declare two Cat objects, can they have different valuesin their itsAge member data?8.Do class declarations end with a semicolon? Do class method definitions?9.What would the header for a Cat function, Meow, thattakes no parameters and returns void look like?10.What function is called to initialize a class?Exercises1.Write the code that declares a class called Employee withthese data members: age, yearsOfService, and Salary.2.Rewrite the Employee class to make the data members private, andprovide public accessor methods to get and set each of the data members.3.Write a program with the Employee class that makes two Employees;sets their age, YearsOfService, and Salary; and printstheir values.4.Continuing from Exercise 3, provide a method of Employee that reportshow many thousands of dollars the employee earns, rounded to the nearest 1,000.5.Change the Employee class so that you can initialize age,YearsOfService, and Salary when you create the employee.6.BUG BUSTERS: What is wrong with the following declaration?class Square{public:int Side;}7.BUG BUSTERS: Why isn't the following class declaration very useful?class Cat{int GetAge()const;private:int itsAge;};8.BUG BUSTERS: What three bugs in this code will the compiler find?class TV{public:void SetStation(int Station);int GetStation() const;private:int itsStation;};main(){TV myTV;myTV.itsStation = 9;TV.SetStation(10);TV myOtherTv(2);}
[ Pobierz całość w formacie PDF ]