Вы находитесь на странице: 1из 3

LAB TASKS

(Practice Questions)

Question 1:
Create a student class that stores name, registration number and percentage. Add member
functions to enter and display the data.

Question 2:
Create an account class that stores account number, name and balance of a person. Add member
functions to enter and display the data, withdraw and deposit amount.

Question 3:
Imagine a tollbooth at a bridge. Cars passing by the booth are expected to pay a 50 paisa 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 call 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 rupees 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. 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.

Question 4:
If you have two fractions, a/b and c/d, their sum can be obtained from the formula
a c = a*d + b*c
b d b*d

Create a class fraction with member data the fraction’s numerator and denominator and
Member functions should accept input from the user in the form 3/5, and output the fraction’s
value in the same format. A member function that displays their sum in fractional form. Write
a main() program that allows the user to repeatedly input two fractions and then displays their
sum. After each operation, ask whether the user wants to continue.
Question 5:
Create a class Rectangle with attributes length and width, each of which defaults to 1. Provide
member functions that calculate the perimeter and the area of the rectangle. Also, provide set
and get functions for the length and width attributes. The set functions should verify that length
and width are each floating-point numbers larger than 0.0 and less than 20.0.

Question 6:
Create a class called time that has three data members hours, minutes and second. The class
has the following member functions:
- One constructor should initialize this data to 0, and another should initialize to fixed
values.
- Display function to display it in 11:59:59 format
- SetTime( )
- IsValid( ), checks if time is valid or not
- Increment( ) – Time after a second
- Decrement( ) - Time a second earlier
Provide menu option to user to use the time class.

Question 7:
Create a class called date that has three data members day, month and year. The class has the
following member functions:
- One constructor should initialize this data to 0, and another should initialize to fixed
values.
- Display function to display it in dd/mm/yy format
- SetDate( )
- IsValid( ), checks if date is valid or not
- Increment( ) – Date after a day
- Decrement( ) - Date a day earlier
Provide menu option to user to use the date class.

Question 8:
In the program given above (date class) add the member functions which allows to add and
subtract the dates. User should input two dates and then choose whether he wants to add or
subtract the dates. After addition or subtraction the user should get an output in valid format
i.e. dd/mm/yy where limitation should be considered as real life example (days (01-30), months
(01-12), years (0001- 9999).
Question 9:
Create a class Student which calculates the GPA. Student class stores ID, Name, Batch, Grade
information about the student. Additional data items can be added accordingly
(Obtained_Grade, Credit_Hours etc). Add a default constructor. One data member should get
the information about the student from user. Another function should do all the calculations
regarding GPA. The last data member should display the GPA with all information to the user.
This declaration must be done in Header File. In Implementation file, the definitions of the
functions must be given. In Source File, objects of the class must call the functions.

Question 10:
Write a C++ program using Static Data Member to record the occurrences of all the object.

Question 11:
Write a C++ program to use Multiple Constructors in a Class for displaying Complex value.

Question 12:
Write a Program to Implement a Class STUDENT having following members:
Data members:
sname - Name of the student
Marks array - Marks of the student
total - Total marks obtained
Tmax - Total maximum marks
Member functions:
assign() - Assign Initial Values
compute() - to Compute Total, Average
display() - to Display the Data.

Question 13:
Write a program for a bakery that contains 5 products and for each product it stores id, name,
quantity and cost. Automatically assign unique product id to each product added. Add
following member function to the class bakery:
- DisplayInfo( ) – should display all the information about all the products.
- BuyProduct( ) – should perform searching by name, if the entered name is present in
the program array, display a message to the user “Product Available”
- AddItem( ) – creates new record of product having id, name, quantity and cost
- FindProductByID( ) – displays all the information against the ID entered.
- TotalCost( ) – displays the cost of all the products present in the bakery.

Вам также может понравиться