0% found this document useful (0 votes)
54 views

OOP LAB 2 Cs

The document discusses three tasks related to object oriented programming in C++. Task 1 creates a class called "Add" to calculate the sum of two decimal numbers by taking input from the user and storing the result. Task 2 creates a class called "Rectangle" to calculate the area of a rectangle by taking length and width as input from the user. Task 3 creates a class called "Date" to display a date in a specific format (DD-MM-YYYY) by taking date and month as input, setting the year as a fixed value, and outputting the date.

Uploaded by

artistryrival
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

OOP LAB 2 Cs

The document discusses three tasks related to object oriented programming in C++. Task 1 creates a class called "Add" to calculate the sum of two decimal numbers by taking input from the user and storing the result. Task 2 creates a class called "Rectangle" to calculate the area of a rectangle by taking length and width as input from the user. Task 3 creates a class called "Date" to display a date in a specific format (DD-MM-YYYY) by taking date and month as input, setting the year as a fixed value, and outputting the date.

Uploaded by

artistryrival
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Object Oriented Programming

Lab #02

Task 1
Create a class “Add” to calculate the sum of two decimal values by simply using
class syntax and access member functions through objects. Take both the values
from user at run time and store it in a variable named “result”.
#include <iostream>
using namespace std;

class add

private:

double a , b, result;

public:

void inputdata();

void displaydata();

};

void add::inputdata()

cout<<"Enter the values of a and b "<<endl;

cin>>a>>b;

void add::displaydata()

result= a+b;

cout<<" addition of "<<a<<" & "<<b<<" = "<<result<<endl;

int main()

add obj1;

obj1.inputdata();

obj1.displaydata();

Output
Task 2
Create a class “Rectangle” to calculate the area of rectangle by simply
using class syntax and access member functions through objects.
#include <iostream>
using namespace std;
class rectangle
{
private:

int area,len,wid;

public:
void inputarea();
void displayarea();
};

void rectangle::inputarea()
{
cout<<"Enter the length and width of rectangle"<<endl;
cin>>len>>wid;
}
void rectangle::displayarea()
{
area=len*wid;
cout<<" Area of rectangle is "<<area<<endl;
}
int main()
{
rectangle obj1;
obj1.inputarea();
obj1.displayarea();
}

Output
Task 3
Create a class called Date that has separate int member data for date, month
and year. One member function should take the input from the user. Another
member function should contain fixed values. Another member function should
display the date, in 15-03-2021 format.
#include <iostream>

using namespace std;

class Date

private:

int date,month,year;

public:

void inputdata();

void fixdata();

void displaydata();

};

void Date::inputdata()

cout<<"Enter the date and month"<<endl;


cin>>date>>month;

void Date::fixdata()

year=2002;

void Date::displaydata()

cout<<" The Format is "<<date<<"-"<<month<<"-"<<year<<endl;

int main()

Date obj1;

obj1.inputdata();

obj1.fixdata();

obj1.displaydata();

Output

You might also like