Object-oriented Programming and Data Member

Only available on StudyMode
  • Download(s) : 120
  • Published : March 31, 2013
Open Document
Text Preview
Lab Task

Q1: Create a class that includes a data member that holds a “serial number” for each object created from the class. That is, the first object created will be numbered 1, the second 2, and so on. To do this, you’ll need another data member that records a count of how many objects have been created so far. (This member should apply to the class as a whole; not to individual objects. What keyword specifies this?) Then, as each object is created, its constructor can examine this count member variable to determine the appropriate serial number for the new object. Add a member function that permits an object to report its own serial number. Then write a main() program that creates three objects and queries each one about its serial number. They should respond I am object number 2, and so on. Use copy constructor for this task both deep and shallow copy.

Q2: Create a class calculator. It would have two data members, both integer types. There would be four functions add(), sub(), mul() and div(). The mul() and div() functions would be friend functions. Create four objects of the class. Also use copy constructor both shallow and deep copy. There would be a static data member which would count the number of objects.

Q3: Create a class GPACalculator. This class would have gpa, cgpa, sessionalMarks, midMarks and finalMarks data members. There would be two functions calculateGPA() and calculateCGPA(). calculateCGPA() would be friend function. You need to create an array of GPACalculator class. The array would be of 5. You also need to give the user option of whether he wants to calculate gpa or cgpa. The grades are as follows: 50 and 53 and 57 and 61 and 64 and 68 and 72 and 75 and 80 and 86 and
tracking img