Friday, August 16, 2019
Object-oriented Programming and Data Member
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 functio ns 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
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.