This document outlines an assignment for Object Oriented Programming, detailing various questions and tasks related to class definitions, member functions, constructors, and operator overloading. It includes specific programming tasks such as creating classes for a tollbooth, time, and employee, along with function overloading examples. The assignment is due on 03/06/2025 and requires handwritten submissions only.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
8 views2 pages
Assignment No. 1 OOP
This document outlines an assignment for Object Oriented Programming, detailing various questions and tasks related to class definitions, member functions, constructors, and operator overloading. It includes specific programming tasks such as creating classes for a tollbooth, time, and employee, along with function overloading examples. The assignment is due on 03/06/2025 and requires handwritten submissions only.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Object Oriented Programming
Assignment No.1 Due Date: 03/06/2025
Hand written solved assignment will only be accepted.
Q 1. What is Object Oriented Programming? What are its advantages?
Q 2. What is the overall structure for defining a class, its member variables, and member functions? Q 3. Write a class definition that creates a class called leverage with one private data member, crowbar, of type int and one public function whose declaration is void pry(). Q 4. What is a constructor function? Write at least its three characteristics. Q 5. Write a member function called getcrow() for the leverage class described in Question 3. This function should return the value of the crowbar data. Assume the function is defined within the class definition. Q 6. Assume that the member function getcrow() described in Question 5 is defined outside the class definition. Write the declaration that goes inside the class definition. Q 7. Write a revised version of the getcrow() member function from Question 5 that is defined outside the class definition. Q 8. If three objects of a class are defined, how many copies of that class’s data items are stored in memory? How many copies of its member functions? Q 9. Imagine a tollbooth at a bridge. Cars passing by the booth are expected to pay a 50 cent toll. Mostly they do, but sometimes a car goes by without paying. The tollbooth keeps track of the number of cars that have gone by, and of the total amount of money collected. Model this tollbooth with a class called tollBooth. The two data items are a type unsigned int to hold the total number of cars, and a type double to hold the total amount of money collected. A constructor initializes both of these to 0. A member function called payingCar() increments the car total and adds 0.50 to the cash total. Another function, called nopayCar(), increments the car total but adds nothing to the cash total. Finally, a member function called display() displays the two totals. Make appropriate member functions const. Include a program to test this class. This program should allow the user to push one key to count a paying car, and another to count a nonpaying car. Pushing the Esc key should cause the program to print out the total cars and total cash and then exit. Q 10. Create a class called time that has separate int member data for hours, minutes, and seconds. A constructor should initialize this data to 0, and a member function to read the time (hours, minutes, and seconds) from use. Another member function should display it, in 11:59:59 format. The final member function should add two objects of type time passed as arguments. A main() program should create two time objects and one that isn’t initialized. Then it should add the two time objects together, leaving the result in the third time variable. Finally, it should display the value of this third object. Q 11. Create an employee class. The member data should comprise an int for storing the employee number and a float for storing the employee’s compensation. Member functions should allow the user to enter this data and display it. Write a main() that allows the user to enter data for three employees and display it. Q 12. What is function overloading? What are its advantages? Q 13. Write a program to overload the function area() to find out the area of circle, rectangle, and triangle. Q 14. Why the member functions in a class are defined in public and member variables are defined in private? What will be the result, if member functions in a class are defined in private and member variables are defined in public? Q 15. What is destructor? What is its purpose? Q 16. What is operator overloading? Which operators can be overloaded and which cannot be? Q 17. What are the advantages of operator overloading? Q 18. Overload * operator to calculate the following series. Sum = a2+(a+1)2+(a+3)2+……..+(a+b)2 Where a and b are member variables of a class. The program should create an object of the class, read a and b, and apply * on the object to find out sum. A member function should display the result. Q 19. Create a class distance with member variables feet and inches. Overload * operator to convert the distance in feet and inches to meter. Q 20. Overload + operator to find the sum of two Time quantities (hh:mm:ss), stored in two objects of class Time.
Python Advanced Programming: The Guide to Learn Python Programming. Reference with Exercises and Samples About Dynamical Programming, Multithreading, Multiprocessing, Debugging, Testing and More