You are on page 1of 2

Air University Multan Campus

MID LAB Examination - Spring 2023


Subjective Paper
Student ID: _________________________
Subject: Object Oriented Total Marks: 30 Marks
Programing
Course Code: CS 112 (L) Date: 10-April-2023
Class: BSCS Time: 9:00 AM to 10: 30 AM
Semester: Spring 23 Max. Time Allowed: 100 Minutes
Section(s): A FM’s Name: Mughees Ahmad
Instructions:
 All questions are mandatory.
FM’s Signature: _________________________

HOD’s Signature:

Question 1 CLO2 PLO2 Taxonomy Level: Apply (5Marks)

Car Class
Write a class named Car that has the following member variables:
* yearModel. An int that holds the car s year model.
* make. A string that holds the make of the car.
* speed. An int that holds the car s current speed.
In addition, the class should have the following constructor and other member functions.
* Constructor. The constructor should accept the car s year model and make as
arguments. These values should be assigned to the object s yearModel and make
member variables. The constructor should also assign 0 to the speed member
variables.
* Accessor. Appropriate accessor functions to get the values stored in an object s
yearModel, make, and speed member variables.
* accelerate. The accelerate function should add 5 to the speed member variable
each time it is called.
* brake. The brake function should subtract 5 from the speed member variable
each time it is called.

Demonstrate the class in a program that creates a Car object, and then calls the
accelerate function five times. After each call to the accelerate function, get the
current speed of the car and display it. Then, call the brake function ve times. After
each call to the brake function, get the current speed of the car and display it.

Question 2 CLO2 PLO2 Taxonomy Level: Apply (10 Marks)

In ocean navigation, locations are measured in degrees and minutes of latitude and
longitude. Thus if you’re lying off the mouth of Papeete Harbor in Tahiti, your location is 149
degrees 34.8 minutes west longitude, and 17 degrees 31.5 minutes south latitude. This is
written as 149°34.8’ W, 17°31.5’ S. There are 60 minutes in a degree. (An older system also
divided a minute into 60 seconds, but the modern approach is to use decimal minutes
instead.) Longitude is measured from 0 to 180 degrees, east or west from Greenwich,

Page 1 of 2
England, to the international dateline in the Pacific. Latitude is measured from 0 to 90
degrees, north or south from the equator to the poles.
Create a class angle that includes three member variables: an int for degrees, a float for
minutes, and a char for the direction letter (N, S, E, or W). This class can hold either a
latitude variable or a longitude variable. Write one member function to obtain an angle value
(in degrees and minutes) and a direction from the user, and a second to display the angle
value in 179°59.9’ E format. Also write a three-argument constructor. Write a main() program
that displays an angle initialized with the constructor, and then, within a loop, allows the user
to input any angle value, and then displays the value. You can use the hex character
constant ‘\xF8’, which usually prints a degree (°) symbol.

Question 4 CLO6 PLO4 Taxonomy Level: Applying (10Marks)


The following table lists the freezing and boiling points of several substances.

Design a class that stores a temperature in a temperature member variable and has
the appropriate accessor and mutator functions. In addition to appropriate constructors,
the class should have the following member functions:
* isEthylFreezing. This function should return the bool value true if the temperature
stored in the temperature field is at or below the freezing point of ethyl
alcohol. Otherwise, the function should return false.
* isEthylBoiling. This function should return the bool value true if the temperature
stored in the temperature field is at or above the boiling point of ethyl
alcohol. Otherwise, the function should return false.
* isOxygenFreezing. This function should return the bool value true if the temperature
stored in the temperature field is at or below the freezing point of oxygen.
Otherwise, the function should return false.
* isOxygenBoiling. This function should return the bool value true if the temperature
stored in the temperature field is at or above the boiling point of oxygen.
Otherwise, the function should return false.
* isWaterFreezing. This function should return the bool value true if the temperature
stored in the temperature field is at or below the freezing point of
water. Otherwise, the function should return false.
* isWaterBoiling. This function should return the bool value true if the temperature
stored in the temperature field is at or above the boiling point of water.
Otherwise, the function should return false.
Write a program that demonstrates the class. The program should ask the user to
enter a temperature, and then display a list of the substances that will freeze at that
temperature and those that will boil at that temperature. For example, if the temperature
is *20 the class should report that water will freeze and oxygen will boil at that
temperature.

Page 2 of 2

You might also like