C++ Quiz: Looking for quick completion.

profileBearbear
test.txt

Give reasonably brief, but complete answers to the following. -------------------------------------------------------------------- Write the Account *class definition* necessary for the following code fragment to work (i.e. what goes in the class header file). You do not need to show the member function implementations. int main() { Account john("john's", 234.00); Account beth("beth's", 567.00); john += 34.00; // deposit money to john's Account beth -= 100.00; // withdraw money from beth's Account beth << john; // transfer john's entire Account balance to beth } ------------------------------------------------------------------- Write the member function definition (including code) for the << operator in the above question that transfers money. -------------------------------------------------------------------- Given the following code: struct Circle { int radius; }; struct Cylinder : public Circle { int height; }; Circle *cirptr, cir; Cylinder *cylptr, cyl; Which of the following statements are legal? cirptr = &cyl; cylptr = &cir; cirptr = cylptr; cylptr = cirptr; -------------------------------------------------------------------- Which of the following operator functions are legal? For those not legal, indicate why not. a. Complex Complex::operator+(const Complex& a) const {...} b. Clock Clock::operator++(int) {...} c. Menu Menu::operator++(const Menu& a, const Menu& b) {...} d. Menu Menu::operator**(const Menu& a) const {...} -------------------------------------------------------------------- a) What behavior can occur when overloaded conversion operators and/or single argument constructors are defined for a class? b) What can you do in the class design to eliminate the problem for single argument constructors? c) Assuming the class needs to provide conversion capabilities, what can you do in the class design to eliminate the problem for conversion operators? -------------------------------------------------------------------- When a function has an object parameter that it doesn't modify, what is the best way to declare the parameter (in the function signature), and why? Show an example using a function with a string object parameter. -------------------------------------------------------------------- What is the error in the way that the ifstream object infile is used in the following copy program? #include <iostream> #include <fstream> using namespace std; int main(int argc, char *argv[]) { istream *fin = &cin; if(argc > 1) { ifstream infile(argv[1], ios::in); if (!infile) return 1; fin = &infile; } while (1) { char c; fin->get(c); if (! *fin) break; cout.put(c); } return 0; } -------------------------------------------------------------------- a) Suppose class Y is derived from class X. Each class declares a constructor and a destructor. Class Y has a string member object that has a constructor and destructor. In what order do the three constructors and destructors run when instances of class Y are created and destroyed? b) Should X's destructor be declared virtual? Why or why not, and what difference would it make? -------------------------------------------------------------------- Write the C++ code to create an STL List of strings, add three elements to the list, then use an iterator object to iterate through the list and print the list element values. --------------------------------------------------------------------