LEC03-ControlStructures

LEC03-ControlStructures - COEN 243 WINTER 2007 Instructor:...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: COEN 243 WINTER 2007 Instructor: Dr. Abdelwahab Hamou-Lhadj Lecture 3 Control Structures 2 ALGORITHMS Algorithm describes a set of steps to be executed to achieve a certain task Example: recipe Is not a program Algorithms help solve the problem before writing C++ code Before writing a program Have a thorough understanding of problem Carefully plan your approach for solving it 3 PSEUDOCODE Pseudocode Artificial, informal language used to develop algorithms Similar to everyday English Not executed on computers Used to think out program before coding Easy to convert into C++ program Only executable statements No need to declare variables 4 if - SELECTION STRUCTURE Selection structure Choose among alternative courses of action Pseudocode example: If students grade is greater than or equal to 60 Print Passed If the condition is true Print statement executed, program continues to next statement If the condition is false Print statement ignored, program continues 5 if - SELECTION STRUCTURE (CONT.) Translation into C++ If students grade is greater than or equal to 60 Print Passed if ( grade >= 60 ) cout << "Passed"; Indenting makes programs easier to read C++ ignores whitespace characters (tabs, spaces, etc.) 6 1 // EX1. if selection structure 2 // Program that determines if a student passed the course 3 #include <iostream> 4 5 // function main begins program execution 6 int main() 7 { 8 int grade; // number representing the grade of the student 9 10 std::cout << "Enter students grade\n" ; // prompt 11 std::cin >> grade; // read an integer 12 13 if (grade >= 60) std::cout << Student passed the course\n" ; 15 16 return ; // indicate that program ended successfully 17 18 } // end function main Enter students grade 65 Student passed the course 7 FLOWCHART A diagram used to express algorithms true false grade >= 60 print Passed 8 IF-ELSE...
View Full Document

Page1 / 28

LEC03-ControlStructures - COEN 243 WINTER 2007 Instructor:...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online