Codes C++

Submitted by: Submitted by

Views: 158

Words: 1048

Pages: 5

Category: Other Topics

Date Submitted: 08/08/2013 06:13 AM

Report This Essay

1.) A program that will accept the length of the side of a square and it will display the perimeter. Where perimeter = 4 * S.

CODE:

#include <iostream.h>

int main()

{

int side, perimeter;

cout<< "Enter a Length of the side of Square: ";

cin>> side;

perimeter = 4 * side;

cout<< "The Perimeter of the Square is: " <<perimeter<<endl;

return 0;

}

Flow Chart:

Start

Input S

S= length of the side of the square

Perimeter = 4 * S

Stop

Print Perimeter

2.) A program that will accept the length of the side of a square and it will display the Area. Where Area=S2

CODE:

#include <iostream.h>

int main()

{

int side, area;

cout<< "Enter a Length of the side of Square: ";

cin>> side;

area = side * side;

cout<< "The Area of the Square is: " <<area<<endl;

return 0;

}

Flow Chart:

Start

Input S

S= length of the side of the square

Area = S ^2

Stop

Print Area

3.) A program that will accept the height (h), base(b1), and base2(b2) of a trapezoid and it will display the area. Where Area = ½ h (b1+b2).

CODE:

#include <iostream.h>

int main()

{

int h, b1,b2;

double area;

cout<< "Enter the height of a trapeziod: ";

cin>> h;

cout<< "Enter the Base1 of a trapeziod: ";

cin>> b1;

cout<< "Enter the Base2 of a trapeziod: ";

cin>> b2;

area = (0.5*h)*(b1+b2);

cout<< "The area of the Trapeziod is: " <<area<<endl;

return 0;

}

Flow Chart:

Start

Input H, B1, B2

H = height

B1 = Base1

B2 = Base2

Area = ½ h (b1+b2)

Stop

Print Area

4.) A program that will accept the length of the side of a cube and it will display the volume. Where V= S3

CODE:

#include <iostream.h>

int main()

{

int side, volume;

cout<< "Enter a Length of the side of Cube: ";

cin>> side;

volume = side * side * side;

cout<< "The Volume of the Cube is: "...