Professional Documents
Culture Documents
1 4+c+++arjun
1 4+c+++arjun
1 4+c+++arjun
E X P E R IM E N T NUMBER -1.4
STUDENT’S U I D – 2 1 BC S23 6 9
CLASS AND GROUP – ON21BCS217-A
SEMESTER - 2nd SEMESTER
SUBJECT: - OBJECT ORIENTEDPROGRAMMING USING C++ SUBJECT CODE: - 22E-21CSH-103_21BCS-421_
DATE OF PERFORMANCE:- 05/03/2022
FLOWCHART/ALGORITHM:
Step4->now in the main function declare the object of the class and
with the help of object print the area and see the required result.
#include<iostream>
using namespace
std; class area{
private:
int l,b;
public:
area(){
l=0;
b=0;
cout<<"The area is: "<<l*b<<endl;
}
area(int x,int y)
{ l=x;
b=y;
cout<<"The area is: "<<l*b<<endl;
}
~area(){
cout<<"Destructor has destroyed the area: "<<l*b<<endl;
}
};
int main()
{
cout<<"ANAND KUMAR JHA 21BCS2369"<<endl;
area obj1(10,20);
area obj2;
}
OUTPUT:
FLOWCHART/ALGORITHM:
Step1->declare the class student and declare the variables name, roll no, height
and student.
Step2->now declare the constructor in the class and assign the values to the
variable.
Step5->now in the main function ask the user to enter the details and declare the
object for the class and pass the values to the function parameter to print the
desired result.
PROGRAM CODE:
#include<iostream>
using namespace
std;
SUBJECT NAME-Object Oriented Programming using C++ SUBJECT CODE-21CSH103
class student{
string name;
int rollno;
int height;
int weight;
public:
student(string x,int y,int z,int w)
{ name=x;
rollno=y;
height=z;
weight=w;
}
void display(){
cout<<"Name is: "<<name<<endl;
cout<<"Rollno is: "<<rollno<<endl;
cout<<"Height is: "<<height<<endl;
cout<<"Weight is:
"<<weight<<endl; cout<<endl;
}
student(student &a){
cout<<"Copy constuctor
called:"<<endl; name=a.name;
rollno=a.rollno;
height=a.height;
weight=a.weight;
}
~student(){
cout<<"Data is destroyed"<<endl;
}
};
int main()
{
cout<<"ANAND KUMAR JHA 21BCS2369"<<endl;
string name;
int rollno;
int height;
int weight;
cout<<"Enter the name:
"<<endl; getline(cin,name);
cout<<"Enter the rollno:
"<<endl; cin>>rollno;
cout<<"Enter the height(in cm):
"<<endl; cin>>height;
cout<<"Enter the weight(in kg): "<<endl;
OUTPUT: