Presentation is loading. Please wait.

Presentation is loading. Please wait.

Structured Programming (4 Credits) HNDIT11034. Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial,

Similar presentations


Presentation on theme: "Structured Programming (4 Credits) HNDIT11034. Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial,"— Presentation transcript:

1 Structured Programming (4 Credits) HNDIT11034

2 Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial, total of a series etc. using pseudo codes Identify Basic Structure of a C++ program Use comments in a program Familiar with the escape sequence characters

3 More flow chart examples 75 - 100 “A” 65 - 74 “B” 55 - 64 “C” 45 - 54 “S” 0 - 44 “F” Draw a flow chart to input Average Marks and find the grade according to the grade System given below.

4 Input Avg If Avg>=75 If Avg>=65 If Avg>=55 If Avg>=45 Stop Start Display A Display B Display C Display S Yes No Display F

5 Pseudo Code One of the textual representation of algorithm is Pseudo code.

6 Begin Pseudo Code for adding two numbers End. Input first number and second number Total = first Number + Second Number output Total

7 Begin Input Maths Marks,Science Marks Total = Maths + Science Average = Total / 2 If Average >= 60 then Grade= “PASS” Else Grade= “FAIL” End if Display Total, Average, Grade End Write a pseudo code to take maths and science marks, calculate total, average and display grade. (If average >=60, “Pass” otherwise “Fail”.

8 75 - 100 “A” 65 - 74 “B” 55 - 64 “C” 45 - 54 “S” 0 - 44 “F” Write a pseudo code to input Average Marks and find the grade according to the grade System given below.

9 Begin Input Avg Mks If Avg >=75 then Grade = “A” Else If Avg >=65 then Grade =“ B” Else If Avg >=55 then Grade = “C” Else If Avg >= 45 then Grade =“ S” Else Grade = “W” End if Display Grade End

10 Begin Number=1 Do While Number <=10 Print Number Number=Number + 1 End while End Write a Pseudo code to display numbers from 1 to 10

11 A C++ program //include headers; these are modules that include functions that you may use in your program; we will almost always need to include the header that defines cin and cout; the header is called iostream.h #include void main() { //variable declaration //read values input from user //computation and print output to user } After you write a C++ program you compile it; that is, you run a program called compiler that checks whether the program follows the C++ syntax ◦ if it finds errors, it lists them ◦ If there are no errors, it translates the C++ program into a program in machine language which you can execute

12 When learning a new language, the first program people usually write is one that salutes the world Here is the Hello world program in C++. #include void main() { cout << “Hello world!”; }

13 The Standard output Statement cout << “Hello World”; The output operator, <<, is used to direct a value to the standard output device.

14 The statement: cout << “I am “ << var << “ years old.”; Can also be written as: cout << :”I am “; cout << var; cout << “years old.”; Or as: cout << “ I am “ << var << “years old.” var is a variable. When we want to display the content of a variable it should not written inside quotes.

15 Comment Entries You can place comment entries to provide clarity to the code. Comment entries are ignored by the compiler and are meant to describe the code. Comments can be written between /* and */, or can be preceded by a //.

16 ESCAPE SEQUENCES ESCAPE SEQUENCE NAMEDESCRIPTION \aBell (alert)Make a sound from computer \bBackspaceTakes the cursor back \tHorizontal tabTakes the cursor to the next tab position \nNew lineTakes the cursor to tne beginning of the next line \rCarriage return Cause a carriage return \”Double quotesDisplays a quotation mark \\BackslashDisplays a back slash \?Question markDisplays a question mark

17 Variable Types A variable type is a description of the kind of information a variable will store. Programming languages vary regarding how strict they require you to be when declaring a variable's type. Some languages, like Perl, python,do not require you to announce the type o fa variable. Other languages require you to declare some variables as numbers and others as text-strings, for example. C++, a strongly typed language, requires you to be even more specific than that. Instead of declaring a variable as a number, you must say whether it will store integers or decimals

18 Rules for Naming Identifiers in C++ The name of an identifier needs to be without any embedded space or symbols such as ? ! - + @ # & () [] {}. However, underscores can be used wherever a space is required. Identifier names must be unique. An identifier name can have any number of characters. An identifier name must begin with a letter or an underscore (‘-‘), which may be followed by a sequence of letters, digits (0-9), or ‘-‘. The first character in an identifier name cannot be a digit. Starting an identifier with an underscore is not recommended. Keywords cannot be used as identifiers. Example : main, include, int, float etc.

19 Q & A


Download ppt "Structured Programming (4 Credits) HNDIT11034. Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial,"

Similar presentations


Ads by Google