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

Labmdterm

The document describes three questions for a lab midterm exam on object oriented programming. Question 1 asks students to model a toll booth using a class with attributes to track the number of cars and amount of money collected. Question 2 asks students to write a class to represent travel with attributes for kilometers and hours. Question 3 asks students to create classes to represent time in both 12-hour and 24-hour formats, including conversion between the formats.

Uploaded by

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

Labmdterm

The document describes three questions for a lab midterm exam on object oriented programming. Question 1 asks students to model a toll booth using a class with attributes to track the number of cars and amount of money collected. Question 2 asks students to write a class to represent travel with attributes for kilometers and hours. Question 3 asks students to create classes to represent time in both 12-hour and 24-hour formats, including conversion between the formats.

Uploaded by

aitzazat789
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/ 2

COMSATS University Islamabad

Sahiwal Campus
(Department of Computer Science)

Lab Midterm Spring-2024


Course Title: Object Oriented Programming Course Code: CSC241 Credit Hours: 3+1
Course Instructor: M. Fayez Afzaal Programme Name: BSCS
Semester: 3rd Batch: SP-23 Section: Date:
Time Allowed: Maximum Marks: 25
Student’s Name: Reg. No. CUI/ /SWL
Important Instructions / Guidelines:
Read the question paper carefully and answer the questions according to their statements.
Mobile phones are not allowed. Calculators must not have any data/equations etc. in their memory.

Q.no.1 Imagine a tollbooth at a bridge. Cars passing by the booth are expected to pay a
50 cent toll. Mostly they do, but sometimes a car goes by without paying.
The tollbooth keeps track of the number of cars that have gone by, and of the total
amount of money collected.
Model this tollbooth with a class called tollBooth. The two data items are a type
unsigned int to hold the total number of cars, and a type double to hold the total
amount of money collected. A constructor initializes both of these to 0. A member
function called payingCar() increments the car total and adds 0.50 to the cash total.
Another function, called nopayCar(), increments the car total but adds nothing to the
cash total. Finally, a member function called display() displays the two totals. Make
appropriate member functions const.
Include a program to test this class. This program should allow the user to push one
key to count a paying car, and another to count a nonpaying car. Pushing the Esc key
should cause the program to print out the total cars and total cash and then exit.

Q2. Write a class travel that has attributes of kilometers and hours. A constructor with
no parameters initializes both data members to 0.
A member function get() inputs the values and function show() display the values.
It has a member function add() that takes an object of type Travel to add the
kilometres and hours of calling object and parameter and returns an object with the
added value. All member functions should be defined outside class and declared
inside the class

Q3. These methods of telling time are sometimes called civilian time and military
time. Our time12 class will represent civilian time, as used in digital clocks and airport
flight departure displays. We’ll assume that in this context there is no need for
seconds, so time12 uses only hours (from 1 to 12), minutes, and an “a.m.” or “p.m.”
designation. Our time24 class, which is for more exacting applications such as air
navigation, uses hours (from 00 to 23), minutes, and seconds.
Page 1 of 2
12-Hour Time 24-Hour Time
12:00 a.m. (midnight) 00:00
12:01 a.m. 00:01
1:00 a.m. 01:00
6:00 a.m. 06:00
11:59 a.m 11:59
12:00 p.m. (noon) 12:00
12:01 p.m. 12:01
6:00 p.m. 18:00
11:59 p.m. 23:59

Create a class time12 that has three attributes bool pm, int hrs and int mins. A default
constructor that assigns value pm to true, hrs to 0 and mins to 0. A parameterized
constructor that assigns values to data members. A member function display() show
the time in civilian format (1:00 a.m.). Write another class time24 that has three
attributes hours, minutes and seconds. A default constructor that assigns value 0 to
hours, minutes to 0 and seconds to 0. A parameterized constructor that assigns values
to data members. A member function display() show the time in military time format
(01:00). A conversion operator time12 converts time24 into time12.
Convert time24 object into time12 object using conversion operator time12.

Output

Enter 24-hour time:


Hours (0 to 23): 17
Minutes: 59
Seconds: 45
You entered: 17:59:45
12-hour time: 6:00 p.m.
The seconds value is rounded up, pushing the 12-hour time from 5:59 p.m. to 6:00 p.m. Entering an hours
value greater than 23 causes the program to exit.

Page 2 of 2

You might also like