1. Write a program using Function Concept to Calculate Perimeter of Circle, Square, Triangle and Rectangle.
i. Function calPerimeterCircle that do not accept arguments and do not return value.
ii. Function calPerimeterSquare that do not accept arguments and return value.
iii. Function calPerimeterTriangle that accept arguments and do not return value.
iv. Function calPerimeterRectangle that accept arguments and return value
2. Please refer the following formula as guidance :
a. Perimeter of Circle = 2 π r : r = radius , use π= 22/7
b. Perimeter of Square = 4a : a = side
c. Perimeter of Triangle = a+b+c : a=side1, b=side2 and c= side3
d. Perimeter of Rectangle = 2 +(l+w) : l=length, w= width
#include <iostream>
using namespace std;
const float r=5;
const float a=5;
void calPerimeterCircle();
float calPerimeterSquare();
void calPerimeterTriangle(float a,float b,float c);
float calPerimeterRectangle(float l,float w);
int main()
{
calPerimeterCircle();
cout<<"Perimeter of Square = "<<calPerimeterSquare()<<"\n";
calPerimeterTriangle(5,3,4);
cout<<"Perimeter of Rectangle = "<<calPerimeterRectangle(2,5)<<"\n";
system("pause");
return 0;
}
//i. Function calPerimeterCircle that do not accept arguments and do not return value.
//a. Perimeter of Circle = 2 pi r : r = radius , use pi= 22/7
void calPerimeterCircle(){
float PI=22.0/7.0;
float perimeter=2*PI*r;
cout<<"Perimeter of Circle = "<<perimeter<<"\n";
}
//ii. Function calPerimeterSquare that do not accept arguments and return value.
//b. Perimeter of Square = 4a : a = side
float calPerimeterSquare(){
return 4*a;
}
//iii. Function calPerimeterTriangle that accept arguments and do not return value.
//c. Perimeter of Triangle = a+b+c : a=side1, b=side2 and c= side3
void calPerimeterTriangle(float a,float b,float c){
float perimeter=a+b+c;
cout<<"Perimeter of Triangle = "<<perimeter<<"\n";
}
//iv. Function calPerimeterRectangle that accept arguments and return value
//d. Perimeter of Rectangle = 2 +(l+w) : l=length, w= width
float calPerimeterRectangle(float l,float w){
return 2*(l+w);
}
Comments
Leave a comment