Chapter 10: Problem 36
What is the relationship between cin and a variable of type ifstream?
Chapter 10: Problem 36
What is the relationship between cin and a variable of type ifstream?
All the tools & learning materials you need for study success - in one app.
Get started for freeWhen 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?
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:
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)
Give a function definition corresponding to the following function declaration. (The type ShoeType is given in Self-Test Exercise \(2 .)\) ShoeType discount(ShoeType old_record); //Returns a structure that is the same as its argument, //but with the price reduced by \(10 \%\).
Define a function called copy_line that takes one argument that is an input stream. When called, copy_line reads one line of input from the input stream given as its argument and writes that line 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_line. (If the argument is an input-file stream, then the stream is connected to a file before the function is called, so copy_line will not open or close any files.) For example, the first of the following two calls to copy_line will copy a line from the file stuff. dat to the screen, and the second will copy a line from the keyboard to the screen: ifstream fin; fin.open("stuff.dat"); copy_line(fin); copy_line(cin);
What do you think about this solution?
We value your feedback to improve our textbook solutions.