Presentation is loading. Please wait.

Presentation is loading. Please wait.

Revision 1. Using pseudo code and flow chart to write an algorithm. Enter number (X) and then find and print the value (Y), as shown in the following.

Similar presentations


Presentation on theme: "Revision 1. Using pseudo code and flow chart to write an algorithm. Enter number (X) and then find and print the value (Y), as shown in the following."— Presentation transcript:

1 Revision 1

2 Using pseudo code and flow chart to write an algorithm. Enter number (X) and then find and print the value (Y), as shown in the following equation: Y=(X-2)/5-X Pseudo code input X process if x=0 Re-enter the new value of x because you can not divide by 0 “ Y=(X-2)/X output Y

3 Using pseudo code and flow chart to write an algorithm. Enter number (X) and then find and print the value (Y), as shown in the following equation: Y=(X-2)/5-X Note: (if X=5 enter value of X again) Pseudo code input X process if x=0 Re-enter the new value of x because you can not divide by 0 “ Y=(X-2)/X output Y start stop Input X Y=(X-2)/5-X Print Y If X=5 yes No Flow Chart

4 Use Nested if….else…. structure to test an input char-value and print the corresponding color; as follows: - If the value is ‘b’ or ‘B’ the program must output "Blue" - If the value is ‘r’ or ‘R’ the program must output "Red" - If the value is ‘g’ or ‘G’ the program must output "Green" - If the value is ‘y’ or ‘Y’ the program must output "Yellow"

5 #include using namespace std ; void main () { int x, z ; cout<< " Enter the value of X : " << endl; cin>>x ; if ( x > 20 ) z = x + 10 ; else if ( x==20) z = x - 10 ; else z = x * 10 ; cout<< " the value of Z = " << z << endl; } Write C++ program to find and print the value of Z from the following equations:

6 W RITE C ++ PROGRAM THAT ACCEPT INTEGER NUMBER FROM THE USER. I N CASE THE NUMBER IS POSITIVE CHECK AND PRINT OUT IT IS EVEN OR ODD

7 1) Using the methods (pseudo code and flow chart), we need to find and print the vicinity of the football stadium, and determine whether international (greater than or equal to 600 m) or local (less so), Note: The perimeter of the rectangle is equal to (length + width) × 2. Start Input L, W C= 2× ( L + W) If c ≥ 600 then Print “ international” Else Print “ local” End if print c End C= 2* (L+W) star t Input L,W Print International End If C>=600 Print Local Yes No

8 W RITE C++ PROGRAM TO READ THREE INTEGERS VALUES, THEN THE PROGRAM FIND AND PRINT THE MAXIMUM VALUE BETWEEN THEM. #include using namespace std ; void main ( ) { int a,b,c; cout<< " This program find maximum number among three numbers "<< endl; cout<< “Please, Enter the first number " << endl ; cin>>a; cout<<“Please, Enter the Second number " << endl ; cin>>b; cout<< “Please, Enter the third number " << endl ; cin>> c ; if ((a > b ) && (a > c) ) cout<< “The First number is maximum number is"<< a<< endl; if ((b > a ) && (b > c) ) cout<< “The Second number is maximum number is"< a ) && ( c > b ) ) cout<< “The third number is maximum number is"<< c << endl; }

9 Write C++ program to find and print the value of Z from the following equations: #include using namespace std ; void main () { int X, Y, Z ; cout<< " Enter the value of X : " << endl; cin>>X ; cout<< " Enter the value of Y : " << endl; cin>> Y ; if ( X>= Y ) Z = X + y; else if ( X< Y ) Z = X - y ; cout<< " the value of Z = " << Z << endl; }

10 W RITE C++ PROGRAM THAT ASK THE USER TO ENTER 2 INTEGER NUMBERS AND PRINT OUT THE LARGER OF THEM

11 Write the output of the following segments of code. a.) int x = 3; cout << x << 2*x; b.) cout << "\"Hello\\\n Gandalf!"; c.) int x = 7; int y = 3; cout << x/y << " and " << x%y

12 Write c++ program to find the value of y Y=(3*x-7) if (x=-5) Y=(5*x *x ) if (x=2) or (x=5) Y=(x-4*x*x*x) if (x=-4) or (x=4) #include Using namespace std; main() { int x, y; cout >x; switch(x) { case -5: y=3*x-7; break; case 2: case 5: y=5*x*x; break; case -4: case 4: y=x-4*x*x*x; break; } cout<<"y = "<< y; }

13 W HAT IS THE OUTPUT FOR EACH OF THE FOLLOWING STATEMENTS : #include using namespace std; int main() { int a=7; int b=13; if ((a>10) & (++b>7)) { cout<<"that is right \n"; cout<10) & (++b>7)) cout<<"that is right \n"; cout<10) &&(++b>7)) cout<<"that is right \n"; cout<

14 W HAT IS THE OUTPUT FOR EACH OF THE FOLLOWING STATEMENTS : #include using namespace std; int main() { int x=10; if (x=15) cout<<“True \n"; else cout<<“False\n”; return 0; } #include using namespace std; int main() { int x=10; if (x=0) cout<<“True \n"; else cout<<“False \n”; return 0; } #include using namespace std; int main() { int x=10; if (x==12) cout<<“True \n"; else cout<<“False \n”; return 0; }

15 Write a program that reads values of the triangle sides (L1, L2, L3) and then a. in the case of equal (L1 = L2 and L1 = L3 and L2 = L3) print out "Equilateral" b. in the case of an isosceles (L1 = L2 or L1 = L3 or L2 = L3) print out "Isosceles " c. in the case of different side (L1!=L2 and L1!=L3 and L2!=L3) print out "Scalene" #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"; }

16 Write C++ that performs the four basic arithmetic operations (+, -, *, / ) depending on the choice that is read from user. #include using namespace std ; int main ( ) { int x, y ; float z ; char c ; cout<< "+ : Addition \n " ; cout<< "- : Subtraction\n " ; cout<< "* : Multiplication\n" ; cout<< "/ : Division \n " ; cout > c ; switch (c) { case'+' : cout > x ; cin>> y ; z= x+y ; cout<<"the result of Addition ="<< z < x ; cin>> y ; z= x-y ; cout<<"the result of Subtraction ="<< z < x ; cin>> y ; z= x*y ; cout<<"the result of Multiplication ="< x ; cin>> y ; if (y!=0) { z= float(x)/y ; cout<<"the result of Division ="<< z <

17 Write C++ which takes two double values length and width then calculates and print the area of rectangle.


Download ppt "Revision 1. Using pseudo code and flow chart to write an algorithm. Enter number (X) and then find and print the value (Y), as shown in the following."

Similar presentations


Ads by Google