Object Oriented Programming with C++ [CE144] Enrolment No.
: 23DCS056
CHAROTAR UNIVERSITY OF SCIENCE & TECHNOLOGY
DEVANG PATEL INSTITUTE OF ADVANCE TECHNOLOGY & RESEARCH
Department of Computer Science & Engineering
Subject Name: Object Oriented Programming with C++
Semester: II
Subject Code: CE144
Academic year: 2023-23
Practical List
No. Aim of the Practical
4. Develop a system to calculate the area of a shape.
SYSTEM REQUIREMENT:
A system calculates the area of circle, rectangle and cuboid. Every time it called the same
function for calculating the area. Depending on the number of parameters passed, it
chooses whether to find area for circle / rectangle / cuboid.
PROGRAM CODE:
#include <iostream>
#include <math.h>
using namespace std;
void area(float r){
float pi=2*acos(0);
float area= pi*r*r;
cout<<"the area of circle of radius "<<r<<" is "<<area<<endl;
}
void area(float l, float b){
float area=l*b;
1
Object Oriented Programming with C++ [CE144] Enrolment No.: 23DCS056
cout<<"the area of the rectangle of sides "<<l<<" and "<<b<<" is "<<area<<endl;
void area(float l,float b, float h){
float tsa=l*b+b*h+h*l;
cout<<"the total surface area of cuboid is "<<2*tsa<<endl;}
int main(){
float radius;
cout<<"enter the radius of the circle:"<<endl;
cin>>radius;
area(radius);
float height,breadth;
cout<<"enter the height of the rectangle:"<<endl;
cin>>height;
cout<<"enter the breadth of the rectangle:"<<endl;
cin>>breadth;
area(height,breadth);
float depth;
cout<<"enter the height of the cuboid:"<<endl;
cin>>height;
cout<<"enter the breadth of the cuboid :"<<endl;
cin>>breadth;
cout<<"enter the depth of the cuboid:"<<endl;
cin>>depth;
area(height,breadth,depth);
cout<<"23dcs056 Vansh Malani"<<endl;
return 0;
2
Object Oriented Programming with C++ [CE144] Enrolment No.: 23DCS056
OUTPUT:
CONCLUSION:
This program teaches us how to take inputs of different dimensions of shapes and calculate the area of
different shapes based on the number of parameters. The same function is being called in each case, but
the output depends upon the number of parameters/arguments passed. This is known as function
overloading in c++. It can allow us to define the same function name multiple times.