Download presentation

Presentation is loading. Please wait.

1
Exercise 2

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

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

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 #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; }

4
**Write c++ program that print the following form: \ Hello " C ' pp '**

#include <iostream> 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 <iostream> using namespace std; void main() { cout<<“Sara Mohamed \n\n\t\t\t"; 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 3.14. perimeter = 2 * PI * R #include <iostream> 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<iostream> using namespace std; int main() { int a,b,c,d,e,sum; float avg; cout<<"Enter the five numbers: \n"; cin>>a>>b>>c>>d>>e; sum = a + b + c + d + e; avg = sum/5; cout<<"the sum is "<<sum; cout<<" and the average is "<<avg<<endl; return 0; }

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 <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; }

9
**Write c++ program to print y If you now y is**

(3x-7) if (x=-5) (5x2) if (x=2) or (x=5) (x-4x3) if (x=-4) or (x=4) #include <iostream.h> #include <math.h> main() { int x, y; cout<<"x = "; cin>>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); } cout<<"y = "<< y;

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 <iostream> #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"; 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 = 8 – 3 * / 4 X = 8 – / 4 X = 8 – 6 + 1 X = 2 + 1 X = 3

14
**X = ( 6 - 1 ) * 2 – 7 + 4 X = 5 * 2 – 7 + 4 X = 10 – 7 + 4 X = 3 + 4**

Write the output (x) X = ( ) * 2 – 7 + 4 X = 5 * 2 – 7 + 4 X = 10 – 7 + 4 X = 3 + 4 X = 7

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

16
Write the output (x) X = ( ) * 2 * 2 X = 5 * 2 * 2 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 A < > 1 A < B A < 0 A < = 3 B < = 3 A > B A > 0 B > = 5 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 A + 3 < > B * C - 1 ( B + 3 ) * 2 > C * A - 1

Similar presentations

OK

5 ft 3ft 5ft 3ft Always write your answer with the unit of measurement.

5 ft 3ft 5ft 3ft Always write your answer with the unit of measurement.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on regional trade agreements advantages Hrm ppt on recruitment process Ppt on formation of company for class 11 Ppt on afforestation in india Topics for ppt on technology Ppt on basic etiquettes Ppt on college management system project Ppt on chapter why do we fall ill for class 9 Ppt on solar based traffic light control system Ppt on pin diode radiation