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

Version 2

The document provides instructions for a lab midterm exam on object-oriented programming. It consists of 2 questions worth 10 and 20 marks respectively. For question 1, students must implement a Circle class to output the area of circles with and without a radius parameter in the main function. For question 2, students must implement a Planet class to create and display planet objects by name, mass, and diameter without using strings or built-in functions in the provided main function. The instructions specify submission guidelines and restrictions on the use of certain data types and functions to avoid errors and leaks.

Uploaded by

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

Version 2

The document provides instructions for a lab midterm exam on object-oriented programming. It consists of 2 questions worth 10 and 20 marks respectively. For question 1, students must implement a Circle class to output the area of circles with and without a radius parameter in the main function. For question 2, students must implement a Planet class to create and display planet objects by name, mass, and diameter without using strings or built-in functions in the provided main function. The instructions specify submission guidelines and restrictions on the use of certain data types and functions to avoid errors and leaks.

Uploaded by

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

Object-Oriented Programming

(CS Department)
Lab Midterm Exam
Spring 2023
Version 2 (TWO)

Allowed Time = 90 minutes

Instructions:
1. Kindly submit the work on the new portal (http://odoo.ucp.edu.pk/).
2. Submission instructions are given below:
i. Create one folder for each question
ii. All files related to a particular question must be inside their
respective folder.
iii. For each class, students MUST create a .h and a .cpp file.
iv. There would therefore be three files for each question (main.cpp +
class header + class cpp)
v. Zip the folders together and submit the zipped file
vi. The name of the zipped file MUST be your registration number.
3. Use constant functions wherever required.
4. Students are NOT ALLOWED to use:
i. the data type string
ii. built-in functions such as strcopy(), strcpy_s, or
.length().
5. The codes should not have memory leakage.
6. There shouldn’t be dangling pointers in the solution provided.
7. Marks cannot be given on codes with run-time or compile-time errors.
8. Lab or course Instructors will NOT answer queries related to the exam.
9. If required, make necessary assumptions and write the same in the code
as comments.
10.Do not ask questions during the exam.
Question 1: 10 marks
Look at the main()function and the output given below. Provide the complete
implementation of the required class so that the main() executes without any errors.

main.cpp
#include "Circle.h"

int main()
{
cout << endl <<"-----Question 1-----" << endl;

Circle c1;
c1.display();
cout << "Area = " << c1.area() << endl << endl;

Circle c2(10.2);
c2.display();
cout << "Area = " << c2.area() << endl;

cout <<"--------------------" << endl << endl;

return 0;
}

Output

Page 2 of 3
Question 2: 20 marks
Look at the main()function below. Provide the complete implementation of the required
class so that the main() executes without any errors. You are NOT ALLOWED to use the
data type string or built-in functions such as strcopy(), strcpy_s, or .length().
We should not have memory leakage in our program. Furthermore, there shouldn’t be
dangling pointers in the solution provided.
main.cpp
#include "Planet.h"

int main()
{
cout << endl << "-----Question-----" << endl;

Planet p1;

char name[7] = {'E','a','r','t','h','\0'};


float mass = 5.97;
float diameter = 12742.0;
Planet p2(name, mass, diameter);
cout << "Name of p2 = " << p2.getName() << endl;
name[0] = 'M';
name[1] = 'a';
name[2] = 'r';
name[3] = 's';

Planet p3 = p2;
p3.increaseMassBy(0.1);
char name2[8] = {'J','u','p','i','t','e','r','\0'};
p3.setName(name2);
p3.setDiameter(13982);
cout << "Name of p3 = " << p3.getName() << endl;
name2[0] = 'S';
name2[1] = 'a';
name2[2] = 't';

Planet p4;
p4 = p3;

cout << endl << "P1" << endl;


p1.display();
cout << endl << "P2" << endl;
p2.display();
cout << endl << "P3" << endl;
p3.display();
cout << endl << "P4" << endl;
p4.display();
cout << "--------------------" << endl << endl;

return 0;
}

Page 3 of 3

You might also like