The Learning Hub College
BSIT & CS 2023-27
Object Oriented Programming
Program Statements
Question no 1:
Create a program in C++ where:
a. Define a class named Car.
b. The class should have two properties: brand and speed.
c. Add a method in the class called displayDetails() that shows the brand and speed of the
car.
d. Create an object of the Car class in the main function and assign values to its properties.
e. Call the displayDetails() method to show the details of the car.
Here's another question involving classes, objects, and constructors in C++:
Question no 2:
Create a class named Rectangle. The class should have two attributes length and breadth each
of which default value set by 1 with the help of constructor .
a. Add a parameterized constructor to initialize the length and breadth of the rectangle.
b. Add a method called calculateArea() to compute and return the area of the rectangle.
c. Create an object of the Rectangle class in the main function by passing values to the
constructor.
d. Use the calculateArea() method to print the area of the rectangle.
Question no 3:
Write a class named Shape with the data members X and Y (coordinates with integer type)
and name of shape (defined as an array of string or char). Shape class has following member
functions:
a. No-argument constructor.
b. GetData() that takes all the coordinate vale and name of shape from user.
c. ShowData() to display the data on screen.
d. Overloaded assignment (= =) operator
Create two objects of shape in the main () function, inputs the value from the user and compare
two objects of shape. If all the coordinates and name of shape are same than both the shape are
equal.
Question no 4:
Create a program in C++ where:
a. Define a class named Student.
b. The class should have the following private properties:
o name (string)
o age (integer)
c. Add a parameterized constructor to initialize the name and age of the student.
d. Add a copy constructor to create a copy of a Student object.
e. Add a method called displayDetails() to print the details of the student.
f. In the main function:
o Create a Student object and initialize it with the parameterized constructor.
o Use the copy constructor to create a copy of the first object.
o Display the details of both objects using the displayDetails() method.
Question no 5:
Create Distance class with the following: feet(integer) and inches (float) as data members.
Overload Strean exertion Operator (>>) for input and insertion operator (<<) for output of data
members.
Write a main() to test all the functions in the class and allow users to enter data, and display the
data that is entered by the user. The main() function should display an appropriate throw error
message if the user enter negative distance value from the command prompt.
Question no 6:
Create a program in C++ where:
1. Define a base class named Person with the following:
o Private properties: name (string) and age (integer).
o A parameterized constructor to initialize the properties.
o A method displayInfo() to print the name and age of the person.
2. Define a derived class named Student that inherits from Person with the following:
o A private property: grade (string).
o A parameterized constructor that initializes the name and age (using the base
class constructor) and grade.
o A method displayStudentInfo() that calls the displayInfo() method from the
base class and also displays the grade of the student.
3. In the main function:
o Create an object of the Student class and initialize it with appropriate values.
o Call the displayStudentInfo() method to display the student's complete details.