1 4+c+++arjun

You might also like

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

STUDENT’S NAME – ANAND KUMAR JHA

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

1. AIM OF THE EXPERIMENT– WAP to find area of


rectangle using constructor overloading. Also define
destructor to delete the memory allocated to
objects.

FLOWCHART/ALGORITHM:

Step1->declare the class area and the variable l and b.

Step2->now declare the constructor with no parameter (default) and


constructor with two parameter.

Step3->also declare the destructor.

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.

Step5->end the program

SUBJECT NAME-Object Oriented Programming using C++ SUBJECT CODE-21CSH103


PROGRAM CODE:

#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;
}

SUBJECT NAME-Object Oriented Programming using C++ SUBJECT CODE-21CSH103


ENCOUNTERED DURING PROGRAM’S EXECUTION
NO ERROR|

PROGRAMS’ EXPLANATION (in brief):


In this program, first we have first declared the class area and
the variable l and b, then we have overloaded the constructor
as one default constructor and another parameter constructor
and also declared destructor to clear the data and in the main
function we have declared the object for the area class and
printed the required area.

OUTPUT:

2. AIM OF THE EXPERIMENT– WAP to create database


of the following items: Name of the student(String),
Roll number of the student(int), Height of the
student(cm),
SUBJECT NAME-Object Oriented Programming using C++ SUBJECT CODE-21CSH103
Weight of the student(kg/gms)
1) Create a Constructor to initialize values
2) Create display () function to display the details
3) Illustrate the use of copy constructor
4) Also implement the concept of destructor.

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.

Step3->declare the show () function in the public block to print the

details. Step4->declare the copy constructor and destructor respectively.

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.

Step6->end the program

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;

SUBJECT NAME-Object Oriented Programming using C++ SUBJECT CODE-21CSH103


cin>>weight;
cout<<endl;
student s1(name,rollno,height,weight);
s1.display();
cout<<endl;
student s2(s1);
s2.display();
}

PROGRAMS’ EXPLANATION (in brief):


In this program, first we have declared the class student and
the variables then we have declared the display() function to
print the values and declared constructor and copy constructor
respectively and declared destructor and in the main function
we have inputted the value of the variables from the user and
printed them after declaring the object for the class and
accessing display() function to print it.

ENCOUNTERED DURING PROGRAM’S EXECUTION


NO ERROR|

OUTPUT:

SUBJECT NAME-Object Oriented Programming using C++ SUBJECT CODE-21CSH103


LEARNING OUTCOMES

 Understand the concepts of object-oriented


programming including programming process and
compilation process.

SUBJECT NAME-Object Oriented Programming using C++ SUBJECT CODE-21CSH103


 Apply different techniques to decompose a
problem and programmed a solution with its sub
modules.

 Analyze and explain the behavior of simple


programs involving the programming addressed in
the course.

 Implement and evaluate the programs using the


syntax and semantics of object-oriented
programming.

 Design the solution of real-world problems in order


to determine that the program performs as
expected.

EVALUATION COLUMN (To be filled by concerned faculty only)

Sr. No. Parameters Maximum Marks


Marks Obtained
1. Worksheet Completion including 10
writing learning objective/ Outcome
2. Post-Lab Quiz Result 5

3. Student engagement in Simulation/ 5


Performance/ Pre-Lab Questions
4. Total Marks 20

SUBJECT NAME-Object Oriented Programming using C++ SUBJECT CODE-21CSH103

You might also like