0% found this document useful (0 votes)
11 views3 pages

PS 5 Class and Object

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)
11 views3 pages

PS 5 Class and Object

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/ 3

PSG College of Technology, Coimbatore- 04

Department of Applied Mathematics and Computational Sciences


I-M.Sc. TCS
23XT27 – Object Oriented Programming Lab
Problem Sheet – 5 (Class & Object)

1. Design a class that holds the following personal data: name, address, age, and phone
number. Write appropriate accessor and mutator functions. Demonstrate the class by
writing a program that creates three instances of it. One instance should hold your
information, and the other two should hold your friends’ or family members’
information.
2. Design A class called DATE. The class should store a date in three integers: moth,
day, and year. There should be member functions to print the date in following forms:
a. 12/25/2024
b. December 25, 2024
c. 25 December 2024.
3. Write a class named EMPLOYEE that has the following member variables:
a. NAME: a string that holds employee’s name
b. idNumber: A int variable that holds the employee’s ID number,
c. Department: A string that holds the name of department.
d. Position: A string that holds the employee’s job title.
e. The class should have
i. function that stores values in these member variables
ii. function that return the values in these member variables.
iii. The program should store this data in the four objects and then display
he data for each employee.
4. Write a class named Car that has the following member variables:
a. yearModel . An int that holds the car’s year model.
b. make . A string that holds the make of the car.
c. speed . An int that holds the car’s current speed.
d. The class should have the following member functions.
i. Accessor: functions to get the values stored in an object’s yearModel,
make, and speed member variables.
ii. accelerate . The accelerate function should add 5 to the speed member
variable each time it is called.
iii. brake . The brake function should subtract 5 from the speed member
variable each time it is called.
e. 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 five
times. After each call to the brake function, get the current speed of the car
and display it.
5. Write a class named RetailItem that holds data about an item in a retail store. The
class should have the following member variables:
a. description . A string that holds a brief description of the item.
b. unitsOnHand . An int that holds the number of units currently in inventory.
c. price . A double that holds the item’s retail price.
d. Write a appropriate mutator functions that store values in these member
variables, and accessor functions that return the values in these member
variables. Once you have written the class, write a program that creates three

RetailItem objects and stores the following data in them.


6. Write a Circle class that has the following member variables:
a. radius: a double
b. pi: a double initialized with the value 3.14159
c. The class should have the following member functions:
i. setRadius. A mutator function for the radius variable. • getRadius. An
accessor function for the radius variable.
ii. getArea. Returns the area of the circle, which is calculated as area = pi
* radius * radius
iii. getDiameter. Returns the diameter of the circle, which is calculated as
diameter = radius * 2
iv. getCircumference. Returns the circumference of the circle, which is
calculated as circumference = 2 * pi * radius
v. Write a program that demonstrates the Circle class by asking the user
for the circle’s radius, creating a Circle object, and then reporting the
circle’s area, diameter, and circumference.
7. In a population, the birth rate and death rate are calculated as follows:
a. Birth Rate = Number of Births ÷ Population
b. Death Rate = Number of Deaths ÷ Population
c. For example, in a population of 100,000 that has 8,000 births and 6,000 deaths
per year, the birth rate and death rate are:
i. Birth Rate = 8,000 ÷ 100,000 = 0.08
ii. Death Rate = 6,000 ÷ 100,000 = 0.06
d. Design a Population class that stores a population, number of births, and
number of deaths for a period of time.
e. Member functions should return the birth rate and death rate.
f. Implement the class in a program. Input Validation: Do not accept
population figures less than 1, or birth or death numbers less than 0.
8. Design a TestScores class that has member variables to hold three test scores. The
class should have a accessor, and mutator functions for the test score fields and a
member function that returns the average of the test scores. Demonstrate the
Programming Challenges 805 class by writing a Program that creates an instance of
the class. The program should ask the user to enter three test scores, which are stored
in the TestScores object. Then the program should display the average of the scores,
as reported by the TestScores object.

You might also like