Saint Louis University |
Computer Science 220
|
Dept. of Math & Computer Science |
Topic: Object-Oriented Programming
Related Reading: Ch. 1
Due:
9:30am Thursday, 2 September 2004
Please make sure you adhere to the policies on academic integrity.
class Top { public: Top (); int look(); private: int value; void change(int v); }For each of the commented statements below, indicated whether they are legal or illegal.
int main() { Top t; t.value = 3; // legal or illegal? int k = t.look(); // legal or illegal? t.change(3); // legal or illegal? return 0; }
What (if anything) is different about the behavior of the following three functions f(), g() and h()?
void f(int x) { x = x + 1; cout << x; } void g(int& x) { x = x + 1; cout << x; } void h(const int& x) { x = x + 1; cout << x; }
Suppose your program contains the following class definition:
class Automobile { public: void setPrice(double newPrice); void setProfit(double newProfit); double getPrice(); private: double price; double profit; double getProfit(); };and assume that the main part of your program contains the following declarations, and that a constructor sets all values to all member variables to some default values.
Automobile hyundai, jaguar; double aPrice, aProfit;Which of the following statements are allowed?