17
Revision 1

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

Embed Size (px)

Citation preview

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

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

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"

#include<iostream>

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:

WRITE C++ PROGRAM THAT ACCEPT INTEGER NUMBER FROM THE USER. IN CASE THE NUMBER IS POSITIVE CHECK AND PRINT OUT IT IS EVEN OR ODD

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 .

StartInput L , W

C= 2× ( L + W) If c ≥ 600 then

Print “ international”

Else

Print “ local”End if print c End

C= 2* (L+W)

start

start

Input L,W

Print International

EndEnd

If C>=600

Print LocalYesNo

WRITE C++ PROGRAM TO READ THREE INTEGERS VALUES,THEN THE PROGRAM FIND AND PRINT THE MAXIMUM VALUE BETWEEN THEM.

#include <iostream >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"<<b << endl; if ((c > a ) && ( c > b ) ) cout<< “The third number is maximum number is"<< c << endl; }

Write C++ program to find and print the value of Z from the following equations:

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

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

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

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 <iostream>Using namespace std;main() {

int x, y;cout<<"x = "; cin>>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;

}

WHAT IS THE OUTPUT FOR EACH OF THE FOLLOWING STATEMENTS:

#include<iostream>

using namespace std;

int main()

{

int a=7;

int b=13;

if ((a>10) & (++b>7))

{

cout<<"that is right \n";

cout<<b;

}

return 0;

}

#include<iostream>

using namespace std;

int main()

{

int a=13;

int b=13;

if ((a>10) & (++b>7))

cout<<"that is right \n";

cout<<b;

return 0;

}

#include<iostream>

using namespace std;

int main()

{

int a=7;

int b=8;

if ((a>10) &&(++b>7))

cout<<"that is right \n";

cout<<b;

return 0;

}

WHAT IS THE OUTPUT FOR EACH OF THE FOLLOWING STATEMENTS:

#include<iostream>

using namespace std;

int main()

{

int x=10;

if (x=15)

cout<<“True \n";

else

cout<<“False\n”;

return 0;

}

#include<iostream>

using namespace std;

int main()

{

int x=10;

if (x=0)

cout<<“True \n";

else

cout<<“False \n”;

return 0;

}

#include<iostream>

using namespace std;

int main()

{

int x=10;

if (x==12)

cout<<“True \n";

else

cout<<“False \n”;

return 0;

}

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 <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"; else if (L1 != L2 && L1!=L3 && L2!

=L3) cout<<"Scalene";}

Write C++ that performs the four basic arithmetic operations (+, - , * , / ) depending on the choice that is read from user .

#include<iostream>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<< "Enter your choice\n" ;  cin>> c ;  switch (c) { case'+' : cout<<"Enter two values:"; cin>> x ; cin>> y ;

z= x+y ; cout<<"the result of Addition ="<< z <<endl ; break ;

  case'-' :cout<<"Enter two values:"; cin>> x ; cin>> y ; z= x-y ; cout<<"the result of Subtraction ="<< z <<endl; break ;

  case'*' :cout<<"Enter two values:“; cin>> x ; cin>> y ; z= x*y ; cout<<"the result of Multiplication ="<<z<<endl; break ;

   case'/' :cout<<"Enter two values:“; cin>> x ; cin>> y ;  if (y!=0)

{ z= float(x)/y ; cout<<"the result of Division ="<< z <<endl; }

  else {

z= 0 ; cout<<"ERROE: Divided by Zero" << endl; 

} break ;

  default: cout<<"Error in your choice"<< endl ; }}

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