Class Photo | Course Home | Homework | Programming | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science 220
Computer Science II
Michael Goldwasser

Fall 2004

Dept. of Math & Computer Science

Homework Assignment 01

Object-Oriented Programming

Contents:


Overview

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.


Practice Problems


Problems to be Submitted (20 points)

  1. (6 points)

    Reinforcement Exercise R-1.2 on page 57 of the text.

  2. (6 points)

    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;
      }
      
    

  3. (8 points)

    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?
    1. hyundai.price = 4999.99;
    2. jaguar.profit = 4000.00;
    3. jaguar.setPrice(30000.97);
    4. aPrice = jaguar.getPrice();
    5. aProfit = jaguar.getProfit();
    6. aProfit = hyundai.getProfit();
    7. if (hyundai==jaguar) cout << "Want to swap cars?";
    8. hyundai = jaguar;


Extra Credit

We'll begin offering extra credit with the next assignment
CSA-220, Fall 2004
Michael Goldwasser
goldwamh at our university domain.

Last modified: Tuesday, 26 October 2004
Class Photo | Course Home | Homework | Programming | Schedule & Lecture Notes | Submit