Chapter 10: Problem 25
When you define an ADT as a C++ class, should you make the member variables public or private? Should you make the member functions public or private?
Chapter 10: Problem 25
When you define an ADT as a C++ class, should you make the member variables public or private? Should you make the member functions public or private?
All the tools & learning materials you need for study success - in one app.
Get started for freeGive 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:
How does inheritance support code reuse and make code easier to main\(\operatorname{tain} ?\)
Suppose your program contains the following class definition: class Automobile \\{ public: void set_price(double new_price) void set_profit(double new_profit) double get_price(); private: double price double profit; double get_profit(); \\}; and suppose the main part of your program contains the following declaration and that the program somehow sets the values of all the member variables to some values: Automobile hyundai, jaguar; Which of the following statements are then allowed in the main part of your program? hyundai.price \(=4999.99\) jaguar.set_price(30000.97) double a_price, a_profit; \(a_{-}\) price \(=\) jaguar \(.\) get \(_{-}\) price () \(a_{-}\) profit \(=\) jaguar \(\cdot\) get \(_{-}\) profit () \(a_{-}\) profit \(=\) hyundai \(.\) get_profit () if (hyundai \(==\) jaguar) cout \( < < \) "Want to swap cars?"; hyundai = jaguar;
Define a function called send_line that takes one argument that is an output stream. When called, send_line reads one line of input from the keyboard and outputs the line to the output stream given as its argument. You should be able to call your function using either cout or an outputfile stream as the argument to your function send_line. (If the argument is an output-file stream, then the stream is connected to a file before the function is called, so send_line will not open or close any files.) For example, the first of the following calls to send_line copies a line from the keyboard to the file morestuf.dat, and the second copies a line from the keyboard to the screen: ofstream fout; fout.open("morestuf.dat") cout \(<<\) "Enter 2 lines of input: \(\backslash n "\) send_line(fout); send_line(cout)
Write 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.
What do you think about this solution?
We value your feedback to improve our textbook solutions.