Chapter 10: Problem 17
Explain what publ ic: and private: do in a class definition. In particular, explain why we do not just make everything public: and save difficulty in access.
Chapter 10: Problem 17
Explain what publ ic: and private: do in a class definition. In particular, explain why we do not just make everything public: and save difficulty in access.
All the tools & learning materials you need for study success - in one app.
Get started for freeWrite a definition for a structure type for records consisting of a person's wage rate, accrued vacation (which is some whole number of days), and status (which is either hourly or salaried). Represent the status as one of the two char values 'H' and 'S'. Call the type EmployeeRecord.
Give a definition for the function with the following function declaration. The class BankAccount is defined in Display 10.5 BankAccount new_account(BankAccount old_account); //Precondition: old_account has previously been given a value // (that is, its member variables have been given values). //Returns the value for a new account that has a balance of zero / / and the same interest rate as the old_account. For example, after this function is defined, a program could contain the following: BankAccount account3, account4; account3.set(999, 99, 5.5) ; account4 \(=\) new_account(account 3) account4.output(cout); This would produce the following output:
Given the following struct definition: struct \(A\) \\{ int member \(_{-} b\) int member_c; \\}; declare \(x\) to have this structure type. Initialize the members of \(x\) member \(_{-} b\) and member_c, to the values 1 and 2 , respectively. Note: This requests an initialization, not an assignment of the members. This distinction is important and will be made in the text in a later chapter.
Define a function called copy_char that takes one argument that is an input stream. When called, copy_char will read one character of input from the input stream given as its argument and will write that character to the screen. You should be able to call your function using either cin or an input-file stream as the argument to your function copy_char. (If the argument is an input-file stream, then the stream is connected to a file before the function is called, so copy_char will not open or close any files.) For example, the first of the following two calls to copy_char will copy a character from the file stuff. dat to the screen, and the second will copy a character from the keyboard to the screen: ifstream fin; fin.open("stuff.dat") copy_char(fin) copy_char(cin)
The private member function DayofYear: :check_date in Display 10.4 allows some illegal dates to get through, such as February \(30 .\) Redefine the member function DayofYear: :check_date so that it ends the program whenever it finds any illegal date. Allow February to contain 29 days, so you account for leap years. (Hint: This is a bit tedious and the function definition is a bit long, but it is not very difficult.
What do you think about this solution?
We value your feedback to improve our textbook solutions.