<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><!--Converted with LaTeX2HTML 96.1-beta (Jan 15, 1996) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds -->CS471 Programming Language Structure I
Fall 2001

Homework 4

Consider the following two combinations of class and function in C++.

1.      Explain the difference in using the function addi as the user of the classes would see it. Give sample code for the two cases, including object creation.

2.      If the declaration of i in the two classes is changed from public to private, what will happen a) at compile-time, and b) at run-time?

3.      Explain the difference at run-time if the declaration of the parameter x in global function addi is changed to example1 x.

class example1 {

public:

   int i;

};

 

int addi(example1 &x, int j) {

  x.i = x.i + j;

  return x.i;

}

 

class example2 {

public:

   int i;

   int addi(int j) {

      i = i + j;

      return i;

   }

};

 

Grading

This assignment is worth 50 points. Part 1 is worth 25 points, part 2, 15 points and part 3, 10 points..

Submission

This assignment must be submitted through WebCT, so it must be prepared electronically. Read the drop box information page before submitting it. Pay close attention to the availability “window” of the assignment. When the window closes, you will not be able to submit an answer.