Download presentation

Presentation is loading. Please wait.

Published byTyra Horsman Modified about 1 year ago

1
Exercise 2 1

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) Perimeter = 2*(length+width) 2 #include using namespace std; main() { int length, width; cout<<"length = "; cin>>length; cout<<"width = "; cin>>width; cout<<"perimeter = "<<2*(length+width)<<"\n"; cout<<"area = "<

3
Write C++ Program to calculate and print the area of a right-angled triangle. The base of the triangle = a The height of triangle= b Equation of area= (1/2)*a*b Equation of area= (1/2)*a*b #include 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<

4
Write c++ program that print the following form: \ Hello " C ' pp ' \ Hello " C ' pp ' #include #include using namespace std; void main() { cout<<" \\ Hello \" C \' pp \' "; }

5
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, and nationality in the right side in the same line. #include #include 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"; }

6
Write c++ program to accept integer number from user and then calculate the area of a circle. Note: The equation of area circle = π * R2, where π is a constant value of approximately perimeter = 2 * PI * R perimeter = 2 * PI * R #include Using namespace std; main() { float r, PI; PI = ; cout<<“ Please enter radius of circle \n”; cin>>r; cout<<"area = "<< PI * r * r<<"\n"; cout<<" perimeter = "<< 2 * PI * r; }

7
Write a Program that does the following:- –Promotes the user to enter 5 numbers. –Print the Numbers. –Print the sum and average of these five numbers. #include

8
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* 4 Area = sideLength * sideLength Input square sideLength Processing Area= sideLength * sideLength Perimeter= sideLength*4 Output Print Out the perimeter and area #include using namespace std; int main() { int length, width; cout<<“Please enter length of square \n”; cin>>length; cin>>width; cout<<“Area= “<

9
Write c++ program to print y If you now y is (3x-7) if (x=-5) (3x-7) if (x=-5) (5x2) if (x=2) or (x=5) (x-4x3) if (x=-4) or (x=4) #include main() { int x, y; cout >x; switch(x) { case -5: y=3*x-7; break; case 2: case 5: y=5*pow(x,2); break; case -4: case 4: y=x-4*pow(x,3); break; } cout<<"y = "<< y; }

10

11
Write a program that reads sides of the triangle (L1, L2, L3) and then a. Equilateral printed word in the case of equal ribs (L1 = L2 and L1 = L3 and L2 = L3) b. Isosceles printed word in the case of an isosceles (L1 = L2 or L1 = L3 or L2 = L3) c. Scalene printed word in the case of different ribs (L1!=L2 and L1!=L3 and L2!=L3) #include #using namespace std; main() { float L1, L2, L3; cout<<"Enter L1, L2, L3 \n"; cin>>L1>>L2>>L3; if(L1==L2&&L1==L3&&L2==L3) cout<<"Equilateral"; else if(L1==L2||L1==L3||L2==L3) cout<<"Isosceles"; else if(L1!=L2&&L1!=L3&&L2!=L3) cout<<"Scalene"; }

12
Write the output of (x) X = 3 * ( ) + 4 *4

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

14
Write the output (x) X = ( ) * 2 – X = 5 * 2 – X = X = 10 – X = X = X = 7

15
Write the output (x) X = * 4 / 2 X = X = / 2 X = X = X = 9

16
Write the output (x) X = ( ) * 2 * 2 X = 5 X = 5 * 2 * 2 X = X = 5 * 4 X = 20

17
What is the result of each compare A = 1, B = 5 Result of compare example false A = B true B = A + 4 false A 1 true A < B false A < 0 true A < = 3 false B < = 3 false A > B true A > 0 true B > = 5 false B > = 6

18
What is the result of each compare A = 1, B = 2, C = 3 Compare result example true A + 4 = B + C false A + B < C – 1 true A + 3 B * C - 1 true ( B + 3 ) * 2 > C * A - 1

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google