0% found this document useful (0 votes)
4 views

Practice Programming II

Uploaded by

himakishk55
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Practice Programming II

Uploaded by

himakishk55
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Question 1 :Design a class named Bookstore in C++.

The class should have the following


specifications:

• Private data members:


o storeName (a string)
o books (an array of Book structures)
o numBooks (an integer)
• The Book structure should have the following members: title (a string), author (a
string), and isbn (a string).
• A static data member numBookstores that keeps track of the number of Bookstore
objects that have been created.
• Appropriate constructor and a destructor.
• Get and set methods for each data member.
• A method named printDetails that prints the bookstore’s details in the format:
“Bookstore Name: [storeName], Number of Books: [numBooks], Book1: [title,
author, isbn], Book2: [title, author, isbn], …”
• A static member function getTotalBookstores that returns the total count of Bookstore
objects.
• A friend function addBookToBookstore that can access the private members of the
Bookstore class and adds a Book to the books array.
• A function removeBookFromBookstore that takes a Book structure and removes it
from the books array.
• Overload the + operator to merge the books of two bookstores and return a new
bookstore.
• The class should have a function named saveToFile that saves the bookstore’s details
to a file. This function should handle exceptions appropriately, specifically when the
file cannot be opened for writing.
• The class should have a function named loadFromFile that loads the bookstore’s
details from a file. This function should handle exceptions appropriately, specifically
when the file cannot be opened for reading.
• Handle exceptions appropriately, specifically when adding a book that already exists
in the bookstore, removing a book that doesn’t exist, and accessing an out-of-bounds
book. Write a program that demonstrates the functionality of the Bookstore class by
doing the following:
• Create a few Bookstore objects and print their details.
• Add and remove books from the bookstores.
• Merge two bookstores using the overloaded + operator.
• Print the total count of Bookstore objects.

Question 2 :Design a class named Manager in C++ with the following specifications:

• The class should inherit from the Employee class.


• The class should have the following private data members: teamSize (an integer),
department (a string), and bonus (a float).
• Appropriate constructors and a destructor.
• Get and set methods for each data member.
• Override the printDetails method from the Employee class to include the manager’s
details in the format: “Name: [name], Age: [age], ID: [id], Position: [position], Salary:
[salary], Team Size: [teamSize], Department: [department], Bonus: [bonus]”
• A function giveBonus that increases the manager’s bonus by a certain percentage. The
function should throw an exception if the percentage is negative.
• A function changeDepartment that changes the manager’s department to a new
department passed as a string argument. Write a program that demonstrates the
functionality of the Manager class by doing the following:
• Create a few Manager objects and print their details.
• Give bonuses and change departments of the managers.

Question :Design a class template named Matrix in C++ with the following specifications:

• The class should have a private data member matrix for the matrix.
• A constructor that initializes the matrix, and a destructor that deletes the matrix.
• Get and set methods for the matrix, and a method getSize that returns the size of the
matrix.
• Overload the () operator to access elements of the matrix. The function should throw
an exception if the index is out-of-bounds. Write a program that demonstrates the
functionality of the Matrix class by doing the following:
• Create a few Matrix objects and print their details.
• Access and modify elements of the matrices using the overloaded () operator.

Question :Design a class named Aircraft in C++ with the following specifications:

• The class should have the following private data members: manufacturer (a string),
model (a string), and year (an integer).
• A pure virtual function named printDetails.
• A destructor that prints a message saying the aircraft is being deleted. Then, design
two classes named Helicopter and Airplane that inherit from the Aircraft class. These
classes should override the printDetails function. Next, design a class named
FlyingCar that inherits from both the Helicopter and Airplane classes (demonstrating
multiple inheritance). This class should also override the printDetails function.
Finally, design a class named VirtualHelicopter that virtually inherits from the
Helicopter class (demonstrating virtual inheritance). This class should also override
the printDetails function. Write a program that demonstrates the functionality of the
Aircraft, Helicopter, Airplane, FlyingCar, and VirtualHelicopter classes by doing the
following:
• Create a few Helicopter, Airplane, FlyingCar, and VirtualHelicopter objects and print
their details.

Question 5 :Design a class named University in C++. The class should have the following
specifications:

• Private data members:


o universityName (a string)
o departments (an array of Department structures)
o numDepartments (an integer)
• The Department structure should have the following members: deptName (a string),
head (a string), and numStudents (an integer).
• A static data member numUniversities that keeps track of the number of University
objects that have been created.
• Appropriate constructor and a destructor.
• Get and set methods for each data member.
• A method named printDetails that prints the university’s details in the format:
“University Name: [universityName], Number of Departments: [numDepartments],
Department1: [deptName, head, numStudents], Department2: [deptName, head,
numStudents], …”
• A static member function getTotalUniversities that returns the total count of
University objects.
• A friend function addDepartmentToUniversity that can access the private members of
the University class and adds a Department to the departments array.
• A function removeDepartmentFromUniversity that takes a Department structure and
removes it from the departments array.
• Overload the + operator to merge the departments of two universities and return a new
university.
• The class should have a function named saveToFile that saves the university’s details
to a file. This function should handle exceptions appropriately, specifically when the
file cannot be opened for writing.
• The class should have a function named loadFromFile that loads the university’s
details from a file. This function should handle exceptions appropriately, specifically
when the file cannot be opened for reading.
• Handle exceptions appropriately, specifically when adding a department that already
exists in the university, removing a department that doesn’t exist, and accessing an
out-of-bounds department. Write a program that demonstrates the functionality of the
University class by doing the following:
• Create a few University objects and print their details.
• Add and remove departments from the universities.
• Merge two universities using the overloaded + operator.
• Print the total count of University objects.

Question 6 :Design a class named Director in C++ with the following specifications:

• The class should inherit from the Employee class.


• The class should have the following private data members: numEmployees (an
integer), division (a string), and bonus (a float).
• Appropriate constructors and a destructor.
• Get and set methods for each data member.
• Override the printDetails method from the Employee class to include the director’s
details in the format: “Name: [name], Age: [age], ID: [id], Position: [position], Salary:
[salary], Number of Employees: [numEmployees], Division: [division], Bonus:
[bonus]”
• A function giveBonus that increases the director’s bonus by a certain percentage. The
function should throw an exception if the percentage is negative.
• A function changeDivision that changes the director’s division to a new division
passed as a string argument. Write a program that demonstrates the functionality of
the Director class by doing the following:
• Create a few Director objects and print their details.
• Give bonuses and change divisions of the directors.

Question 7 :Design a class template named Vector in C++ with the following specifications:

• The class should have a private data member vector for the vector.
• A constructor that initializes the vector, and a destructor that deletes the vector.
• Get and set methods for the vector, and a method getSize that returns the size of the
vector.
• Overload the () operator to access elements of the vector. The function should throw
an exception if the index is out-of-bounds. Write a program that demonstrates the
functionality of the Vector class by doing the following:
• Create a few Vector objects and print their details.
• Access and modify elements of the vectors using the overloaded () operator.

Question 8 :Design a class named Ship in C++ with the following specifications:

• The class should have the following private data members: manufacturer (a string),
model (a string), and year (an integer).
• A pure virtual function named printDetails.
• A destructor that prints a message saying the ship is being deleted. Then, design two
classes named Yacht and Cruise that inherit from the Ship class. These classes should
override the printDetails function. Next, design a class named FlyingShip that inherits
from both the Yacht and Cruise classes (demonstrating multiple inheritance). This
class should also override the printDetails function. Finally, design a class named
VirtualYacht that virtually inherits from the Yacht class (demonstrating virtual
inheritance). This class should also override the printDetails function. Write a
program that demonstrates the functionality of the Ship, Yacht, Cruise, FlyingShip,
and VirtualYacht classes by doing the following:
• Create a few Yacht, Cruise, FlyingShip, and VirtualYacht objects and print their
details.

Question 9 :Design a class named Hospital in C++. The class should have the following
specifications:

• Private data members:


o hospitalName (a string)
o departments (an array of Department structures)
o numDepartments (an integer)
• The Department structure should have the following members: deptName (a string),
head (a string), and numPatients (an integer).
• A static data member numHospitals that keeps track of the number of Hospital objects
that have been created.
• Appropriate constructor and a destructor.
• Get and set methods for each data member.
• A method named printDetails that prints the hospital’s details in the format: “Hospital
Name: [hospitalName], Number of Departments: [numDepartments], Department1:
[deptName, head, numPatients], Department2: [deptName, head, numPatients], …”
• A static member function getTotalHospitals that returns the total count of Hospital
objects.
• A friend function addDepartmentToHospital that can access the private members of
the Hospital class and adds a Department to the departments array.
• A function removeDepartmentFromHospital that takes a Department structure and
removes it from the departments array.
• Overload the + operator to merge the departments of two hospitals and return a new
hospital.
• The class should have a function named saveToFile that saves the hospital’s details to
a file. This function should handle exceptions appropriately, specifically when the file
cannot be opened for writing.
• The class should have a function named loadFromFile that loads the hospital’s details
from a file. This function should handle exceptions appropriately, specifically when
the file cannot be opened for reading.
• Handle exceptions appropriately, specifically when adding a department that already
exists in the hospital, removing a department that doesn’t exist, and accessing an out-
of-bounds department. Write a program that demonstrates the functionality of the
Hospital class by doing the following:
• Create a few Hospital objects and print their details.
• Add and remove departments from the hospitals.
• Merge two hospitals using the overloaded + operator.
• Print the total count of Hospital objects.

Question 10 :Design a class named CEO in C++ with the following specifications:

• The class should inherit from the Employee class.


• The class should have the following private data members: numEmployees (an
integer), company (a string), and bonus (a float).
• Appropriate constructors and a destructor.
• Get and set methods for each data member.
• Override the printDetails method from the Employee class to include the CEO’s
details in the format: “Name: [name], Age: [age], ID: [id], Position: [position], Salary:
[salary], Number of Employees: [numEmployees], Company: [company], Bonus:
[bonus]”
• A function giveBonus that increases the CEO’s bonus by a certain percentage. The
function should throw an exception if the percentage is negative.
• A function changeCompany that changes the CEO’s company to a new company
passed as a string argument. Write a program that demonstrates the functionality of
the CEO class by doing the following:
• Create a few CEO objects and print their details.
• Give bonuses and change companies of the CEOs.

Question 11 :Design a class template named Stack in C++ with the following specifications:

• The class should have a private data member stack for the stack.
• A constructor that initializes the stack, and a destructor that deletes the stack.
• Get and set methods for the stack, and a method getSize that returns the size of the
stack.
• Overload the () operator to access elements of the stack. The function should throw an
exception if the index is out-of-bounds. Write a program that demonstrates the
functionality of the Stack class by doing the following:
• Create a few Stack objects and print their details.
• Access and modify elements of the stacks using the overloaded () operator.

Question 12 :Design a class named Boat in C++ with the following specifications:

• The class should have the following private data members: manufacturer (a string),
model (a string), and year (an integer).
• A pure virtual function named printDetails.
• A destructor that prints a message saying the boat is being deleted. Then, design two
classes named Sailboat and Motorboat that inherit from the Boat class. These classes
should override the printDetails function. Next, design a class named FlyingBoat that
inherits from both the Sailboat and Motorboat classes (demonstrating multiple
inheritance). This class should also override the printDetails function. Finally, design
a class named VirtualSailboat that virtually inherits from the Sailboat class
(demonstrating virtual inheritance). This class should also override the printDetails
function. Write a program that demonstrates the functionality of the Boat, Sailboat,
Motorboat, FlyingBoat, and VirtualSailboat classes by doing the following:
• Create a few Sailboat, Motorboat, FlyingBoat, and VirtualSailboat objects and print
their details.

Question 13 :Design a class named School in C++. The class should have the following
specifications:

• Private data members:


o schoolName (a string)
o classes (an array of Class structures)
o numClasses (an integer)
• The Class structure should have the following members: className (a string), teacher
(a string), and numStudents (an integer).
• A static data member numSchools that keeps track of the number of School objects
that have been created.
• Appropriate constructor and a destructor.
• Get and set methods for each data member.
• A method named printDetails that prints the school’s details in the format: “School
Name: [schoolName], Number of Classes: [numClasses], Class1: [className,
teacher, numStudents], Class2: [className, teacher, numStudents], …”
• A static member function getTotalSchools that returns the total count of School
objects.
• A friend function addClassToSchool that can access the private members of the
School class and adds a Class to the classes array.
• A function removeClassFromSchool that takes a Class structure and removes it from
the classes array.
• Overload the + operator to merge the classes of two schools and return a new school.
• The class should have a function named saveToFile that saves the school’s details to a
file. This function should handle exceptions appropriately, specifically when the file
cannot be opened for writing.
• The class should have a function named loadFromFile that loads the school’s details
from a file. This function should handle exceptions appropriately, specifically when
the file cannot be opened for reading.
• Handle exceptions appropriately, specifically when adding a class that already exists
in the school, removing a class that doesn’t exist, and accessing an out-of-bounds
class. Write a program that demonstrates the functionality of the School class by
doing the following:
• Create a few School objects and print their details.
• Add and remove classes from the schools.
• Merge two schools using the overloaded + operator.
• Print the total count of School objects.

Question 14 :Design a class named Supervisor in C++ with the following specifications:

• The class should inherit from the Employee class.


• The class should have the following private data members: numEmployees (an
integer), department (a string), and bonus (a float).
• Appropriate constructors and a destructor.
• Get and set methods for each data member.
• Override the printDetails method from the Employee class to include the supervisor’s
details in the format: “Name: [name], Age: [age], ID: [id], Position: [position], Salary:
[salary], Number of Employees: [numEmployees], Department: [department], Bonus:
[bonus]”
• A function giveBonus that increases the supervisor’s bonus by a certain percentage.
The function should throw an exception if the percentage is negative.
• A function changeDepartment that changes the supervisor’s department to a new
department passed as a string argument. Write a program that demonstrates the
functionality of the Supervisor class by doing the following:
• Create a few Supervisor objects and print their details.
• Give bonuses and change departments of the supervisors.

Question 15 :Design a class template named Queue in C++ with the following specifications:

• The class should have a private data member queue for the queue.
• A constructor that initializes the queue, and a destructor that deletes the queue.
• Get and set methods for the queue, and a method getSize that returns the size of the
queue.
• Overload the () operator to access elements of the queue. The function should throw
an exception if the index is out-of-bounds. Write a program that demonstrates the
functionality of the Queue class by doing the following:
• Create a few Queue objects and print their details.
• Access and modify elements of the queues using the overloaded () operator.

Question 16 :Design a class named Train in C++ with the following specifications:

• The class should have the following private data members: manufacturer (a string),
model (a string), and year (an integer).
• A pure virtual function named printDetails.
• A destructor that prints a message saying the train is being deleted. Then, design two
classes named FreightTrain and PassengerTrain that inherit from the Train class.
These classes should override the printDetails function. Next, design a class named
FlyingTrain that inherits from both the FreightTrain and PassengerTrain classes
(demonstrating multiple inheritance). This class should also override the printDetails
function. Finally, design a class named VirtualFreightTrain that virtually inherits from
the FreightTrain class (demonstrating virtual inheritance). This class should also
override the printDetails function. Write a program that demonstrates the functionality
of the Train, FreightTrain, PassengerTrain, FlyingTrain, and VirtualFreightTrain
classes by doing the following:
• Create a few FreightTrain, PassengerTrain, FlyingTrain, and VirtualFreightTrain
objects and print their details.

You might also like