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

Mid Oop

oop in c++

Uploaded by

hirrah21
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
12 views

Mid Oop

oop in c++

Uploaded by

hirrah21
Copyright
© © All Rights Reserved
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/ 4

90 65

minutes marks

University of Central Punjab


Faculty of Information Technology

Mid-Term Exam fall-


2022
BSSE

Object Oriented
Programming
Section 06

Instructions:
• Indent your code.
• Comment your code.
• Use meaningful variable names.
• Plan your code carefully on a piece of paper before you implement
it.
• Name of the program should be same as the task name.
i.e. the first programshould be Task_1.cpp
• 20 marks will deduct if not done in multiple files.
• Make sure your submitted file is not corrupted.
• In case of ambiguity, make a suitable assumption
• Plagiarism will result in severe consequence.
• Lastly, do not forget to stay confident
Good luck

Students are required to work in multiple files i.e .h and .cpp


90 65
minutes marks

Task 1: (35 marks)

In this task, we are going to create a small-scale Library Management System.


First make three files: Book.cpp, Book.h and driver.cpp to separate class header and
implementation.
1. Create a class Book with following variables:
char* Book_name;
float Book_price;
int Book_pages;
int Book_code;
static int count;
(3 marks)
2. Implement default constructor, overloaded constructor and copy constructor. Print
“Default Constructor Called” , “parameterized Constructor Called ”and “copy
constructor called ” in the respective constructors.
Book(char *Book_name,float Book_Price,int Book_Pages,int Book_code)
Book(const Book&obj)
Do deep copy in overloading constructors (6 marks)
3. Implement all setters and getters for class Book. (do deep copy in setters function)
(6 marks)
4. Implement display function to display all information of class Book.
(4 marks).
5. Deallocate all the dynamically allocated memory of class data
members. (2 marks)

6. Maintain an array of three Book objects in the driver.cpp. i.e.


- Book* books = new Book[3]; (2 marks)

7. Set the values of first index of an array by parameterized constructor. (1 marks)

8. Set the value of second index of an array by setter function. (1 marks)


9. Set the value of third index of an array by copy constructor. Assign it first index
values.
(1 marks)
10. Create a function searchBook(). That will search the book from Book array with help
of book_code if book is found it will display all its information, else it shows a
message that “book is not found”
(5 marks)
11. Display all object information.it should also display how many books created in your
program. (2 marks)
12. Search a book having code 1234, by using searchBook function. (2 marks)
90 65
minutes marks

Task 2: (30
marks)
Create a class Distance which will have the following attributes (2 marks)

- int feet
- int inches
As we know
12 inches= 1 feet
So your program should modify feet’s whenever inches count is grater then 12
For example if your enter 12 feet 30 inches it will display distance as 14 feet 6
inches

1. Implement the class having a default and parametrized. (6


marks)
2. Implement all setters and getters for class Distance. (6
marks)
3. Implement display function to display Distance in this format feet :: Inches
(4 marks)
 Create operator overloading for the following:
4. = = : To check whether two distance are same or not. (4
marks)
5. + : To add two distance. (4
marks)
6. ++ : post Increment distance. (4
marks)

Your main function should be same as below


int main(){
Distance d1(90,
100); Distance d2;
d2.setFeet(20);
d2.setInches(88);
Distance d3 = d1 +
d2;
cout << "distance of d1 is " << d1.getFeet() << " :: " <<
d1.getInches() <<
endl
cout << "distance of d2 is " << d2.getFeet() << " :: " <<
;
d2.getInches() << cout << "by adding two distance answer is: " << endl;
endl d3.disply();
if (d1 ==
; d2)
cout << "d1 and d2 distance are equal" << endl;

else
cout << "d1 and d2 distance are not equal" << endl;
d1+
+;
d1.disply();

return 0;
}
90 65
minutes marks
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy