0% found this document useful (0 votes)
21 views6 pages

Labtask3 OOPS

The document discusses 7 tasks related to defining classes in C++. Task 1 involves declaring a Date class. Task 2 involves declaring a Point class. Task 3 involves declaring a Circle class. Task 4 involves declaring a Sale class. Task 5 involves declaring a Holiday class. Task 6 involves declaring a Container class. Task 7 involves declaring a Rational class.

Uploaded by

232423
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)
21 views6 pages

Labtask3 OOPS

The document discusses 7 tasks related to defining classes in C++. Task 1 involves declaring a Date class. Task 2 involves declaring a Point class. Task 3 involves declaring a Circle class. Task 4 involves declaring a Sale class. Task 5 involves declaring a Holiday class. Task 6 involves declaring a Container class. Task 7 involves declaring a Rational class.

Uploaded by

232423
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/ 6

Name : Muhamma Saad Khan

Roll no : 232423
Oops lab tak
Lab no 4
TASK 1:
Declare a class Date with data members day, month, year
2. Declare two objects of class Date.
3. Declare an object of class Date, a pointer to Date and an array of 10 Dates. Assign the
address
of the object you declared to the pointer.
4. What is constructor?
5. Suggest appropriate constructors for the Date class.
6. How do you call the destructor?
Task 2 :
Write a complete C++ program with the following features.
a. Declare a class Point with two integer data members x and y.
b. Provide appropriate constructors to initialize the data members.
c. Provide separate get(getX(), getY()) and set(setX(), setY()) methods for each of the data
members.
d. Provide a method display() to print the x and y coordinates.
e. In the main(), declare two objects of Point and call the method display() for each of them.
Change
the values of x and y using the set() functions.
f. From main(), call the functions g
TASK 3:
Define a class Circle with its radius and center(x,y) as data members. Provide appropriate
constructors and methods to compute the area and circumference of the circle. Call these
methods from the main() program.

TASK 4 :
ld a class Sale with private member variables
double itemCost; // Cost of the item
double taxRate; // Sales tax rate
and functionality mentioned below:
• Write a default constructor to set the member variable itemCost to 0 and taxRate to 0.
Sale( )
• Write a parameterized constructor that accepts the parameter for each member variable such
as cost for ItemCost and rate for taxRate
Sale( double cost, double rate)
• Generate only accessors for itemCost and taxRate
• Write a function getTax( ) to calculate tax i.e take a product of itemCost and itemRate.
double getTax( ) Write a function getTotal( ) to calculate the total price of item i.e. take a sum
of itemCost and getTax( ) (calling getTax() will return the calculated tax on item) .double
getTotal( )etX() and getY()for each of the points, add the x and ycoordinates together and print
the result.

TASK 5:
Design a class Holiday that represents a holiday during the year. This class has three private
data
members:
name: A string that represents the name of holiday.
day: An integer that holds the day of the month of holiday.
month: A string that holds the month the holiday is in.
TASK 6:
Define a class Container for storing integer values, regardless of the sequence and duplication
checks. Your class should consist of the member variables.
int * values; // A pointer to an int . This member points to the dynamically allocated array of
integers (which you will be allocating in constructor).
int capacity; // An integer that shows total capacity of your container

TASK 7:
Create a class Rational for performing arithmetic with fractions.
numerator
denominator
Provide a default and a parameterized constructor that enables an object of this class to be
initialized when it is declared. The constructors should store the fraction in reduced form. For
example, the fraction 2/4 should be stored in object as 1 in the numerator and 2 in the
denominator. In case of 3/4, store 3 in the numerator and 4 in the denominator.Provide public
member functions that perform each of the following tasks:

You might also like