Revision.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Advertisements

CS 240 Computer Programming 1
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Chapter 16 Exception Handling. What is Exception Handling? A method of handling errors that informs the user of the problem and prevents the program from.
Exercise (1).
Tinaliah, S. Kom.. * * * * * * * * * * * * * * * * * #include using namespace std; void main () { for (int i = 1; i
Triana Elizabeth, S.Kom. #include using namespace std; void main () { for (int i = 1; i
FUNCTIONS Section 3.6. Functions Section 3.6 Identify functions.
Introduction to Programming Lecture 5. In the Previous Lecture Basic structure of C program Basic structure of C program Variables and Data types Variables.
Introduction to Functions Programming. COMP102 Prog Fundamentals I: Introduction to Functions /Slide 2 Introduction to Functions l A complex problem is.
Writing and Testing Programs Drivers and Stubs Supplement to text.
1 Lecture 16 Chapter 6 Looping Dale/Weems/Headington.
Functions:Passing Parameters by Value Programming.
Summary of Loops Programming. COMP102 Prog Fundamentals I: Summary of Loops /Slide 2 Which Loop to Use? l for loop n for calculations that are repeated.
What is the out put #include using namespace std; void main() { int i; for(i=1;i
C++ programming I Lab#3 Control Statements Instructor: Eng. Ruba A. Salamah Tuseday: 17/10/2010.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
Software Engineering 1 (Chap. 1) Object-Centered Design.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
Functions Parameters & Variable Scope Chapter 6. 2 Overview  Using Function Arguments and Parameters  Differences between Value Parameters and Reference.
Flowol subroutines Subroutines are used to:  Simplify your code to make it easier to read (or for someone.
Recursion Chapter Nature of Recursion t Problems that lend themselves to a recursive solution have the following characteristics: –One or more.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Prime numbers Jordi Cortadella Department of Computer Science.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 4.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
CS1201: Programming Language 2 Recursion By: Nouf Almunyif.
A definition: Photosynthesis!. Five things are needed for photosynthesis: (3 are inputs) Travels up from the roots of the plant WATER CARBON DIOXIDE Enters.
Current Assignments Homework 3 is due tonight. Iteration and basic functions. Exam 1 on Monday.
Looping II (for statement). CSCE 1062 Outline  for statement  Nested loops  Compound assignment operators  Increment and decrement operators.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
Previously Repetition Structures While, Do-While, For.
Creating Table using LOOP By Adnan and M.Qazi Programmers.
Control structures Algorithm Development Conditional Expressions Selection Statements 1.
CS Class 08 Today  Exercises  Nested loops  for statement  Built-in functions Announcements  Homework #3, group solution to in-class.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
1 Original Source : and Problem and Problem Solving.ppt.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering Problem Solving and Logic.
Modular Programming – User Defined Functions. CSCE 1062 Outline  Modular programming – user defined functions  Value returning functions  return statement.
Introduction to Functions.  A complex problem is often easier to solve by dividing it into several smaller parts, each of which can be solved by itself.
Simple Data Types Chapter Constants Revisited t Three reasons to use constants –Constant is recognizable –Compiler prevents changes in value.
April 11, 2005 More about Functions. 1.Is the following a function call or a function header? calcTotal(); 2.Is the following a function call or a function.
LESSON 4 Decision Control Structure. Decision Control Structures 1. if statement 2. if-else statement 3. If-else-if statement 4. nested if statement 5.
Programming Fundamentals by Dr. Nadia Y. Yousif1 Control Structures (Selections) Topics to cover here: Selection statements in the algorithmic language:
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Lecture 7 Computer Programming -1-. Conditional Statements 1- if Statement. 2- if ….. else Statement. 3- switch.
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
User-Defined Functions (cont’d) - Reference Parameters.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Review 1.
LESSON 4 Decision Control Structure
© T Madas.
Enum ,Char Functions& Math Library Functions I.Mona Alshehri
Programming fundamentals 2 Chapter 2:Function
Longitude and Latitude Review
Compound Assignment Operators in C++
Introduction to Programming
Programming Funamental slides
Name: _______________________________
CSC 102 Chabli Boler.
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
Two ways to discuss color 1) Addition 2) Subtraction
Can I color yellow?. Can I color yellow?
What Color is it?.
Arrays of Two-Dimensions
Statements and flow control
Introduction to Functions
Color Box Button - Gray Type : object Type : object Type : object
Introduction to Algorithms and Programming COMP151
Presentation transcript:

Revision

Using pseudo code and flow chart to write an algorithm 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

Note: (if X=5 enter value of X again) 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 Flow Chart start Input X If X=5 yes No Y=(X-2)/5-X Print Y stop

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"

Write C++ program to find and print the value of Z from the following equations: #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 ; z = x * 10 ; cout<< " the value of Z = " << z << endl; }

Write c++ program that accept integer number from the user 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 . C= 2* (L+W) start Input L,W Print International End Start Input L , W C= 2× ( L + W) If c ≥ 600 then Print “ international” Else Print “ local” End if print c End No If C>=600 Yes Print Local

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;   case -4: case 4: y=x-4*x*x*x; } 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"; 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.