Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lab Tasks

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Lab tasks

Task 1:
Create a class Time, with data members Minutes and seconds. . Overload the constructor in Time, and Take
two times from user i.e First Time for Check-In and the second time for Check-Out. Subtract these two times to
calculate the working hours per day. And display the result in Hours-Minutes.

Task 2:
Create a class Date, with data members Day, Month and year. . Overload the constructor in Date, and Take two
dates from user i.e First Date of starting work, and the second date of Ending work. Subtract these two dates to calculate
the working days per month. And display the result in days.
Task 3:
Define a class employee. Take name, designation, age, DoB, address and years of experience as data members
and getdata and showdata as methods. Now enter the details of 5 employee using array of objects.
1. Perform task 1 using new operator.
2. Perform task 1 using array of pointer to objects.
3. Define a class string. Use overloaded == operators to compare two strings.
4. Create a class loc. Take longitude and latitude as data members to represent the location. Overload +, -, *,
++, --, =, +=, -= operators to perform operations on loc type objects.

Task 4:
Write a program with a class that contains an array of integers. Initialize the integer array in the constructor of
the class. Then create two friend functions to the class to find the largest and smallest integers in the array.
Create a destructor that sets all of the elements in the array to 0.
Task 5:
(RationalNumber Class) Create a class RationalNumber (fractions) with the following capabilities:
Create a constructor that prevents a 0 denominator in a fraction, reduces or simplifies fractions that are not in
reduced form and avoids negative denominators.
Overload the addition, subtraction, multiplication and division operators for this class.
Overload the relational and equality operators for this class.

Task 6:
(Polynomial Class) Develop class Polynomial. The internal representation of a Polynomial is an array of terms.
Each term contains a coefficient and an exponent, e.g., the term 2x4 has the coefficient 2 and the exponent 4.
Develop a complete class containing proper constructor and destructor functions as well as set and get
functions. Assume that the polynomial is in one variable and maximum possible degree is 5. The class should
also provide the following overloaded operator capabilities:

a) Overload the addition operator (+) to add two Polynomials.


b) Overload the subtraction operator (-) to subtract two Polynomials.
c) Overload the assignment operator to assign one Polynomial to another.
d) Overload the multiplication operator (*) to multiply two Polynomials.
e) Overload the addition assignment operator (+=), subtraction assignment operator (-=), and multiplication as-
signment operator (*=).

Task 7:
Write a program with a class that contains an array of integers. Initialize the integer array in the constructor of
the class. Then create two friend functions to the class to find the largest and smallest integers in the array.
Create a destructor that sets all of the elements in the array to 0
Task 8:
Make a University class with objects of following classes:
1. ClassRoom
2. ComputerLab

Class must have following member variables


1. String RoomNumber
2. int area
3. int NoOfChairs
4. bool projector

ComputerLab must have following member variables


1. String RoomNumber
2. int NoOfComputer
3. bool projector

Task 9 (Composition):
Make a Computer System class with objects of following classes
1 monitor
2 CPU
3 keyboard
Monitor must have following member variables
1. String CompanyName

2. int Size

3. float price

CPU must have following member variables

1. String CompanyName

2. int Speed

3. float price

Key Board must have following member variables

4. String CompanyName

5. int NumOfKeys

6. Float price
In main user should see any information about his/her system.

NOTE: Also write the constructor & destructor sequence for every class.

Task 10 (Aggregation):
Create a class Student which has attribute Name, Age and a method GetName, Get Age, SetName, SetAge.
Create another class Class which has reference of student object as its member and a method PrintStudent.
Write test program to show aggregation relationship between these two objects.

Task 11

Write a program in which class A is base class for class B. While Class C is derived from class B and class D is
derived from class E. Provide explicit implementation of default constructors and destructors. Write a test
program which initializes each class object and shows execution order of constructor and destructor by printing
appropriate messages.

Task 12

Modify the above classes and provide overloaded constructor implementation for each class. (Note: Use base
initialize for this purpose)

Task 13:

Declare classes Person and Student where Student is derived from Parent class. Parent has Name and Student
has RollNo as its private member.

a) Create a Student class object and initialize it with the already existing object of Student class. Analyze the
behavior of default copy constructors of Person and Student classes.

b) Explicitly write copy constructor for Person class. Analyze the behavior.

c) Now, Explicitly write copy constructor for the Student class.

Task 14:
Create Class Person with variables weight,height, gender. Create another Class Employee with variables
designation, HoursPerDay. Now create another class Teacher and inherit it from Person and Employee and add
function display() which should show all the details related to teacher.
Task 15:
Create Class Person with variables weight,height, gender and functions walk() sit(). Ceate another Class
Sudent with variable ID,First name, Last name, Graduation and function PrintDetail() Write(). Now create a
class GraduationStudent with variables UniversityName, YearGraduation and functions Display().
Note: In both parent classes simply add a printf() statement about the task. In child display function show all
data

Task 16:
Create Class Date with variables day,month,year and a function display() and another class Time with variables
hour,minutes,seconds and a function display(). Now create a third class named Time_Date it will inherit from
both Classes Date and Time it should have a function display() which will display time and date.

Task 17:
Create class named shape with variables height and width. Create another class named color with variable
color_name. Now create third class named Rectangle with variable area. Inherit rectangle class from shape
class and color class. Now calculate area of rectangle and define color of rectangle as well.

Task 18:

Create parent class Polygon with protected parameters width and height and function printarea() and a virtual
function area(). Create two sub classes Rectangle , Square and Triangle.
In main() create 3 pointers of Polygon and assign Rectangle , Square and Triangle to it. Call printarea function
with the pointers

Task 19:
(Polymorphic Banking Program Using Account Hierarchy) Develop a polymorphic banking program using the
Account hierarchy created in last lab. Create a vector of Account pointers to SavingsAccount and
CheckingAccount objects. For each Account in the vector, allow the user to specify an amount of money to
withdraw from the Account using member function debit and an amount of money to deposit into the Account
using member function credit. As you process each Account, determine its type. If an Account is a
SavingsAccount, calculate the amount of interest owed to the Account using member function
calculateInterest, then add the interest to the account balance using member function credit. After processing an
Account, print the updated account balance obtained by invoking base-class member function getBalance

Task 20:
(Simple Payroll Application) Develop a simple payroll application. There are three kinds of employees in the
system: salaried employee, hourly employee, and commissioned employee. The system takes as input an array
containing employee objects, calculates salary polymorphically, and generates report.

You might also like