Answer to Question #209119 in C++ for Skye Jordan

Question #209119

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 


1
Expert's answer
2021-06-21T04:41:39-0400
 
#include<iostream>
using namespace std;
 
 
 double pi = 22 / 7;
 double radius;
 double side;
 double perimeter;
 
 void  calPerimeterCircle(){
 	
 	 perimeter = 2 * pi * radius;
 	 cout<<"The perimeter of the circle is\t"<<perimeter<<endl;
 }
 void calPerimeterSquare(){
 	perimeter = 4 * side;
 	cout<<"The perimeter of the square is\t"<<perimeter<<endl;
 }
 void  calPerimeterTriangle(int a, int b, int c){
 	perimeter = a + b + c;
 	cout<<"The perimeter of the triangle is\t"<<perimeter<<endl;
 }
 double calPerimeterRectangle(int l, int w){
 perimeter = 2*(l + w);	
 return perimeter;
 }
 int main(){
 	side = 4;
 	radius = 7;
 	calPerimeterCircle(); //Testing the function for calculating the perimeter of a circle
 	calPerimeterSquare(); //Testing the function for calculating the perimeter of a square
 	calPerimeterTriangle(5,5,5) ;//Testing the function for calculating the perimeter of Triangle
 	cout<<"The perimeter of the rectangle is \t"<<calPerimeterRectangle(9, 9);//Testing the function for calculating the perimeter of a rectangle
 }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS