write c++ program to calculate the area and perimeter of a rectangle. note that the area of the...

14
Write C++ program to calculate the area and Write C++ program to calculate the area and perimeter of a rectangle. perimeter of a rectangle. Note that the area of the rectangle = length × Note that the area of the rectangle = length × width. width. Perimeter = 2*(length+width) Perimeter = 2*(length+width) 1 #include <iostream> using namespace std; Int main() { int length, width; cout<<"length = "; cin>>length; cout<<"width = "; cin>>width; cout<<"perimeter = "<<2*(length+width)<<"\n"; cout<<"area = "<<length*width; return 0; }

Upload: duane-lambert

Post on 03-Jan-2016

257 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

Write C++ program to calculate the area and perimeter of a Write C++ program to calculate the area and perimeter of a rectangle.rectangle.Note that the area of the rectangle = length × width.Note that the area of the rectangle = length × width.

Perimeter = 2*(length+width)Perimeter = 2*(length+width)

11

#include <iostream>using namespace std;Int main(){

int length, width;cout<<"length = ";

cin>>length; cout<<"width = "; cin>>width; cout<<"perimeter = "<<2*(length+width)<<"\n"; cout<<"area = "<<length*width;

return 0;}

Page 2: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

Write C++ Program to calculate and print the area of a right-angled triangle .Write C++ Program to calculate and print the area of a right-angled triangle .

The base of the triangle = aThe base of the triangle = a

The height of triangle= bThe height of triangle= b

Equation of area= (1/2)*a*bEquation of area= (1/2)*a*b

#include<iostream>using namespace std;int main(){ int a,b; cout<<“Please enter the base of triangle \n”; cin>>a; cout<<“Please enter the height of triangle \n”; cin>>b; cout<<“Area of triangle= “<<(0.5)*a*b<<endl; return 0;}

Page 3: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

Write c++ program that print the following form: Write c++ program that print the following form:

\ Hello " C ' pp ' \ Hello " C ' pp '   

#include <iostream>#include <iostream>

using namespace std;using namespace std;

void main()void main()

{{

cout<<" cout<<" \\\\ Hello Hello \" \" C C \'\' pp pp \' \' "; ";

}}

Page 4: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

Write a program to print your name in the first line in the Write a program to print your name in the first line in the left side, and the address in the middle of the third line, left side, and the address in the middle of the third line, and nationality in the right side in the same line.and nationality in the right side in the same line.

#include <iostream>#include <iostream>

using namespace std;using namespace std;

void main()void main()

{{

cout<<“Sara Mohamed \n\n\t\t\t";cout<<“Sara Mohamed \n\n\t\t\t";

cout<<“Al Kharj \t\t\t Saudi";cout<<“Al Kharj \t\t\t Saudi";

}}

Page 5: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

Write c++ program to accept integer number from user and then Write c++ program to accept integer number from user and then calculate the area of a circle.calculate the area of a circle.Note: The equation of area circle = π * R2, where π is a constant Note: The equation of area circle = π * R2, where π is a constant value of approximately 3.14.value of approximately 3.14.

perimeter = 2 * PI * Rperimeter = 2 * PI * R

#include <iostream>Using namespace std;Int main(){

float r, PI; PI = 3.1415926; cout<<“ Please enter radius of circle \n”; cin>>r; cout<<"area = "<< PI * r * r<<"\n";

cout<<" perimeter = "<< 2 * PI * r;return 0;

}

Page 6: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

Write a Program that does the following:-Write a Program that does the following:-

– Promotes the user to enter 5 numbers.Promotes the user to enter 5 numbers.

– Print the Numbers.Print the Numbers.

– Print the sum and average of these five numbers.Print the sum and average of these five numbers.

#include<iostream>#include<iostream>

using namespace std;using namespace std;

int main()int main()

{{

int a,b,c,d,e,sum;int a,b,c,d,e,sum;

float avg;float avg;

cout<<"Enter the five numbers: \n";cout<<"Enter the five numbers: \n";

cin>>a>>b>>c>>d>>e;cin>>a>>b>>c>>d>>e;

sum = a + b + c + d + e;sum = a + b + c + d + e;

avg = sum/5;avg = sum/5;

cout<<"the sum is "<<sum;cout<<"the sum is "<<sum;

cout<<" and the average is "<<avg<<endl;cout<<" and the average is "<<avg<<endl;

return 0;return 0;

}}

  

Page 7: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

Write c++ program to find the Perimeter and area of the square.The perimeter and area of the square are given by the following formula.Perimeter = sideLength* 4Area = sideLength * sideLengthInput Square sideLengthProcessing Area= sideLength * sideLength Perimeter= sideLength*4Output Print Out the perimeter and area#include <iostream>using namespace std;int main(){ int length, width; cout<<“Please enter length of square \n”; cin>>length; cin>>width; cout<<“Area= “<<length*length<<endl; cout<<“Perimeter= “<<4*length<<endl; return 0;}

Page 8: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

Write the output of (x)X = 3 * ( 8 - 6 ) + 4 *4

X = 3*2+4*4X = 3*2+4*4X = 6+4*4X = 6+4*4X = 6+16X = 6+16X = 22X = 22

Page 9: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

Write the output (x)X = 8 – 3 * 2 + 4 / 2 ^ 2

X = X = 8 – 3 * 2 + 4 / 4X = X = 8 – 6 + 4 / 4X = X = 8 – 6 + 1X = 2 + 1X = 2 + 1X = 3X = 3

Page 10: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

Write the output (x)X = ( 6 - 1 ) * 2 – 7 + 4

X = 5 * 2 – 7 + 4X = 5 * 2 – 7 + 4X = X = 10 – 7 + 4X = X = 3 + 4X = 7X = 7

Page 11: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

Write the output (x)X = 5 + 2 * 4 / 2

X = X = 5 + 8 / 2X = X = 5 + 4X = 9X = 9

Page 12: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

Write the output (x)X = ( 3 + 2 ) * 2 * 2

X = 5X = 5 * 2 * 2X = X = 10 * 2X = 20X = 20

Page 13: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

What is the result of each compare A = 1 , B = 5

exampleexampleResult of compareResult of compare

A = BA = B

B = A + 4B = A + 4

A < > 1A < > 1

A < BA < B

A < 0A < 0

A < = 3A < = 3

B < = 3B < = 3

A > BA > B

A > 0A > 0

B > = 5B > = 5

B > = 6B > = 6

falsefalse

truetrue

falsefalse

truetrue

falsefalse

truetrue

falsefalse

falsefalse

truetrue

truetrue

falsefalse

Page 14: Write C++ program to calculate the area and perimeter of  a rectangle. Note that the area of  the rectangle = length × width. Perimeter = 2*(length+width)

What is the result of each compare A = 1 , B = 2 , C = 3

exampleexampleCompare resultCompare result

A + 4 = B + CA + 4 = B + C

A + B < C – 1A + B < C – 1

A + 3 < > B * C - 1A + 3 < > B * C - 1

) )B + 3B + 3 * ( * ( 2 > C * A - 12 > C * A - 1

truetrue

falsefalse

truetrue

truetrue