Object Oriented Programming and Data Member

Topics: Object-oriented programming, Object, Number Pages: 1 (304 words) Published: March 31, 2013
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
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Object Oriented Programming Essay
  • Object Oriented Programming Essay
  • Object Oriented Programming Midterm Essay
  • Object-oriented Programming and Java Statement Essay
  • Reusability: Object Oriented Programming Essay
  • Object-oriented Programming and Discussion Question Essay
  • Comparison of Object Oriented and Structured Programming Essay
  • Introduction to Object Oriented Programming Concepts Essay

Become a StudyMode Member

Sign Up - It's Free