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

Version 1

1. The document provides instructions for a lab midterm exam on object-oriented programming. It allows 90 minutes to complete the exam and must be submitted through a specified portal. 2. Files must be organized by question in folders and submitted as a zip file with the student's registration number. Constant functions should be used where possible. Built-in string and memory functions are not allowed. Codes should avoid memory leaks and dangling pointers. 3. The exam contains two questions worth 10 and 20 marks respectively. Question 1 tests implementation of a Triangle class. Question 2 tests a Smartphone class without using strings or built-in memory functions, and avoiding memory leaks and dangling pointers.

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)
13 views

Version 1

1. The document provides instructions for a lab midterm exam on object-oriented programming. It allows 90 minutes to complete the exam and must be submitted through a specified portal. 2. Files must be organized by question in folders and submitted as a zip file with the student's registration number. Constant functions should be used where possible. Built-in string and memory functions are not allowed. Codes should avoid memory leaks and dangling pointers. 3. The exam contains two questions worth 10 and 20 marks respectively. Question 1 tests implementation of a Triangle class. Question 2 tests a Smartphone class without using strings or built-in memory functions, and avoiding memory leaks and dangling pointers.

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 1 (ONE)

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 "Triangle.h"

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

Triangle t1;
t1.display();
cout << "Area = " << t1.area() << endl << endl;

Triangle t2(6,10.2);
t2.display();
cout << "Area = " << t2.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 "Smartphone.h"

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

Smartphone s1;

char brand[6] = {'A','p','p','l','e','\0'};


float price = 999.99;
int releaseYear = 2022;
Smartphone s2(brand, price, releaseYear);
cout << "Brand of s2 = " << s2.getBrand() << endl;
brand[0] = 'S';
brand[1] = 'a';
brand[2] = 'm';
brand[3] = 's';

Smartphone s3 = s2;
s3.increasePriceBy(100.0);
char brand2[8] = {'O','n','e','P','l','u','s','\0'};
s3.setBrand(brand2);
s3.setReleaseYear(2023);
cout << "Brand of s3 = " << s3.getBrand() << endl;
brand2[0] = 'G';
brand2[1] = 'o';
brand2[2] = 'o';
brand2[3] = 'g';

Smartphone s4;
s4 = s3;

cout << endl << "S1" << endl;


s1.display();
cout << endl << "S2" << endl;
s2.display();
cout << endl << "S3" << endl;
s3.display();
cout << endl << "S4" << endl;
s4.display();
cout << "--------------------" << endl << endl;

return 0;
}

Page 3 of 3

You might also like