CSE201R01_OOP using C++_Manual_2025 (1)
CSE201R01_OOP using C++_Manual_2025 (1)
Laboratory
Course Code
Code: CSE201R01
Semester: II
Lab Manual
2025
SCHOOL OF COMPUTING
SHANMUGHA ARTS, SCIENCE, TECHNOLOGY AND RESEARCH
ACADEMY
(SASTRA Deemed to be) University
Tirumalaisamudram, Than
Thanjavur-613 401
Ex No 1 – Input/Output and Manipulators
3. Write a program that prompts the user to input that number of quarters,
dimes, and nickels. The program then outputs the total value of the coins
in dollars and cents. For example your output may look like this.
Enter the number of quarters: 5
Enter the number of dimes: 3
Enter the number of nickels: 4
Your charge totals to $1.75
4. When a value is smaller than a field specified with setw(), the unused
locations are, by default, filled in with spaces. The manipulator setfill()
takes a single character as an argument and causes this character to be
substituted for spaces in the empty parts of a field. Rewrite the WIDTH
program so that the characters on each line between the location name
and the population number are filled in with periods instead of spaces, as
in Portcity.....2425785
1. Write a C++ program to update the given numbers. Use the following
functions: getInput() function should take n1 and n2 as reference
arguments and get input for them. swap() function should take n1 and n2
as reference arguments and swap their values. The main function should
call the above functions and display the modified values.
1. Write a program to find the largest of three numbers using inline functions.
1. Create a Book class with attributes such as title, author, and ISBN. Include
appropriate member functions to get book information’s and display book
details.
2. Design a Class called Polygon with attributes as number of sides and length
of each side. Implement appropriate member functions to calculate the
perimeter and area of different polygon, then display the results.
4. Build a Mobile-Phone class with attributes like brand, model, price, and
Battery-Life. Implement appropriate member functions to store mobile
details and check if the phone is affordable or not based on the user given
budget.
2. Write a C++ code to create class String class. Declare a character array
str to store a string and a variable len to store the length of the string.
Implement default constructor to initialize the string to be empty and a
parameterized constructor to initialize it with a user specified string.
Define a member function Length() to find the length of the string and
assign it to len. Provide a display function to show the string and its length
to the user.
4. Create a C++ program with a Distance class to calculate the sum of two
distances given in feet and inches using a function Design the class
Distance with two data members: feet and inches. Use a parameterized
constructor to initialize the distances. Develop a member function to add
two Distance objects by passing the second object as an argument to the
function and display the result. Ensure that the inches are properly
converted to feet if they exceed 12. Write a program to demonstrate the
functionality by creating two Distance objects, add them, and display the
result.
5. Create a class called Person that has three private data members name,
age and height and thefollowing public member functions:
Default constructor – To initialize the data members
2. Write a C++ program to manage car rentals for a rental company. Each car
in the rental fleet should have attributes such as carID (integer) , make
(string) to store the car manufacturer name, model (string) for the car's
model, year (integer) representing the year of manufacturing, rentalPrice
(float) indicating the daily rental price, and availabilityStatus (bool) to
indicate whether the car is available in the fleet or rented (true if available,
false if rented). The program should use an array of objects to represent the
cars in the rental fleet. Provide functionalities to input car details, to rent a
car using the car id (modify availability status to false) and to display all
available cars
1. Write a C++ program to get a line of text by using string obj and implement
the following operations
Find empty spaces in the given text
If only one space between words, add one more extra space
If more than two spaces, reduce to two
3. Create a Class String with private string objects (eg: string s1,s2) and two
methods: int merge (string s1, string s2) : this method will return 1 for
merging two different strings and return 0 for merging two same strings. int
compare (): this method should compare two strings and return 1 if first
string is greater; 0 otherwise.
4. Define two classes as class A and class B. A contains a string and B contains
a character array. Initialize them using constructors. Define two
overloaded isPalindrome functions in both the class A and B. Class A
should check whether the string stored in class A’s object is a palindrome. If
so, it should return true, else return false. class B should do the same for the
string in class B’s object.
2. Write a program with a generic function to swap two values any type.
The values to be swapped needs to be passed as call by reference from
main function and display the swapped values.
1. Create a class Distance with attributes for feet and inches. Overload the +
operator to add two Distance objects and return the resulting distance.
2. Create a class Player with attributes such as name and score. Overload the
> operator to compare two players based on their scores and determine
which player has a higher score.
5. Implement a Date class that represents date as day, month and year.
Overload the various operators to perform operations on the Date object.
Overload + operator to add days to the Date to find a future date. Overload
- operator to subtract days from the Date to find a past date. Overload == to
find whether two Date objects have the same date. Overload ++ operator to
increment the Date by one day.
1. Define a class called Person which has the members to represent a person
with the values of name, gender, age, type and nationality. Implement a
constructor in the Person class to initialize its members. Derive two classes
from the Person class as Singer and Author. The singer class should
contain the member variables for number of songs sung and number of
awards won. Type of singer can be carnatic or western or fork. Singer class
should have the member variables for language of writing (English or
Tamil or Telugu ) and number of books published. Type of writer can be
novel or history or technical. Both these classes must have constructors to
initialize their own members as well as the members of their base class.
Include read() and print() functions in the derived classes to get input and
to display the values of their members.
2. Create a class called Payroll with the members of Basic pay, HRA, DA,
PF, Gross pay and Netpay. Add a default constructor to initialize all the
values to 0. Define a member function named getSalary() with the formula
for salary calculation provided below. Derive a class Employee from
Payroll with the members of Name, Age, Date of joining and Designation.
Include a member function as getEmployeeDetails() to get input for the
member variables. Declare an object of Employee and invoke the two
functions.
Gross Pay(GP) = Basic Pay(BP) + HRA( 17% of BP) + DA( 45 % of BP)
Net Pay = GP – PF( 12% of GP)
3. Define a base class named Blue bus with the member of customer details:
Name, Email, Phone number and total cost. Use a constructor to assign
their values as per user choice. Derive a class as Bus booking with the
members of Bus no, date of journey, from, to and no of passengers.
Define a bookBus function to book bus ticket by providing the required
details. Display the ticket using a member function displayTicket. Compute
total cost as 500 X no of passengers. Derive another class named Hotel
booking with the members of Hotel name, city, date of check in, date of
check out and no of guests. Define a function as bookHotel to book room
by collecting details and a displayHotel function to display details of
booking. Calculate total cost as 1000 X no of days X no of guests. Provide
5% discount if no of days of stay exceeds two.
Where:
Ci = Credit for the ith course
Gi = Grade Point earned in the ith course
The summation (∑) is done for all the courses in the semester.
5. Create a base class Amazon which is a online store selling items. There are
two types of accounts provided by Amazon, Customer and Seller.
Implement a program with a base class Amazon and two derived classes
as customer and seller.
Amazon class includes the data members:
Amazon_Id(integer), Name(string), Email(string) and phone
number(integer).
Provide a parameterized constructor to assign values for them.
Create objects for the Customer and Seller classes in the main function by
passing values through their constructors. Then Invoke the member
functions through the objects.
3. Create a base class Vehicle with a member variable mileage and a pure
virtual function fuelEfficiency(). Derive three classes Car, Truck, and
Bike that each override the fuelEfficiency() function. They Use a base
class pointer to call the fuelEfficiency() method for each derived object. It
must return the mileage of the vehicle per litre of petrol.
5. Develop a program for the ICICI insurance company that offers both
Life insurance for people and General insurance for vehicles. Define the
hierarchy of classes as per the description provided below.
1. Create a file called "DATA.txt" to store the set of integer elements. Read
an integer element from the user and search whether the given integer
element is present or not within the file.
2. Write a C++ program to design a student class with name, reg_no and
design a derived class called Score with ml and m2. Derive a class called
Result from student and score classes. In Result class, include a function
to display the student results along with name and reg_no. Assume a class
having 10 students. After calculating the results write the students details
(as object) into a file called "result.dat". Later retrieve from data from the
file and display it. Include necessary member functions.
4. Write a program to create a file to store numbers. Read the numbers from
the file and store the prime numbers in one file and non-prime numbers
in another file. Read and display the content of all the files. The interaction
should look like this, Enter the integers to be stored: 11 14 15 17 8 3
Content in the input file is: 11 14 15 17 8 3. Content in prime file: 11 17 3
Content in non-prime file: 14 15 8.
5. Create a file called "DATA" to store the set of integer elements. Search
whether the given element is present or not within the file. If the element is
present, then write the factors of that searching element in the
"FACTORS" file. Write a formatted IO file program to demonstrate the
above operation and display the contents of "FACTORS" file.