1 EEE1008 C Programming

Size: px
Start display at page:

Download "1 EEE1008 C Programming"

Transcription

1 1 1 EEE1008 C Programming Dr. A.M. Koelmans

2 2 Administrative details Dr. A.M. Koelmans Location: Merz Court, room E4.14 Telephone: 8155 Web:

3 3 BOOK C How to Program, by P.J. Deitel, H.M. Deitel, published by Pearson International, 6 th edition.

4 4 Web page The web page contains information about the course, and downloads of all the source code used in the lecture slides. Other material may be made available on Blackboard. We will follow Deitel's book closely. There are many other books and web sites dedicated to C.

5 5 Course structure Basics of computer languages First look at C: a basic program Data types and variables Basic I/O, using keyboard and screen The main building blocks: expressions, conditionals, and repetition Advanced data types: arrays Functions

6 6 Why study software? This course intends to show you that software design is very logical and modular. It is a good case study of good engineering practice. A lot of software development is intimately tied to computer architectures: Compilers generate code for certain processors Operating systems control the system hardware Motors are often controlled by software Many embedded systems (from cars, mobile phones and TVs down to microwave ovens and washing machines) need both hardware and software.

7 7 Why study software? It is therefore no exaggeration to say that most Electrical and/or Electronic Engineering related jobs have some kind of software aspect. Many traditional Electrical Engineering functions are now performed by microprocessors. If you end up in a management position you may well have to take important (and potentially expensive) decisions that are affected by your knowledge about both software and hardware. Therefore, understanding and being comfortable with software will greatly enhance your career prospects. Professional organisations (such as IET and IEEE) demand that you develop some software skills.

8 8 Course structure There are practicals every week, where you do exercises and projects. Details are always on the web page. Project deadlines must be strictly adhered to. Some of the lectures will be devoted to exercises, quizzes, and self-assessments.

9 9 Second year In the first year, you also learn the basics of Computer Architecture (as part of the Digital Electronics I course) In the second year, we combine the two topics in EEE2007, where you learn more advanced Machine Architecture, Embedded C, and Assembly language You then build and program your own computer, based around a Motorola microprocessor

10 What is a Computer? Computer Device capable of performing computations and making logical decisions Computers process data under the control of sets of instructions called computer programs Hardware Various devices comprising a computer Keyboard, screen, mouse, disks, memory, CD-ROM, and processing units Software Programs that run on a computer

11 11 The ENIAC

12 12 Computer technology evolution Feature 1945: ENIAC Scale factor 2005: PENTIUM complexity tubes M transistors size 200 m cm 3 speed 150 ops/s M ops/s power consumption 10 kw W cost $ 10M 10-4 $ 1000 reliability 3 hours 10 3 years

13 13 What if cars had improved like that speed 70 m/hour of light fuel 50 mpg mpg cost 10K pounds pound reliability 1 year years weight 1 ton mg

14 Computer Organization Six logical units in every computer: Input unit Obtains information from input devices (keyboard, mouse) Output unit Outputs information (to screen, to printer, to control other devices) Memory unit Rapid access, low capacity, stores input information Arithmetic and logic unit (ALU) Performs arithmetic calculations and logic decisions Central processing unit (CPU) Supervises and coordinates the other sections of the computer Secondary storage unit Cheap, long-term, high-capacity storage Stores inactive programs

15 1.6 Machine Languages, Assembly Languages, and High-level Languages 15 Three types of programming languages Machine languages Strings of numbers giving machine specific instructions Example: Assembly languages English-like abbreviations representing elementary computer operations (translated via assemblers) Example: LOAD BASEPAY ADD OVERPAY STORE GROSSPAY

16 1.6 Machine Languages, Assembly Languages, and High-level Languages 16 Three types of programming languages (continued) 1. High-level languages - Codes similar to everyday English - Use mathematical notations (translated via compilers) - Example: grosspay = basepay + overtimepay

17 History of C C Evolved by Ritchie from two previous programming languages, BCPL and B Used to develop UNIX Used to write modern operating systems Hardware independent (portable) Standardization Many slight variations of C existed, and were incompatible Committee formed to create a "unambiguous, machineindependent" definition Standard created in 1989, updated in 1999

18 18 Portability Tip Because C is a hardware-independent, widely available language, applications written in C can run with little or no modifications on a wide range of different computer systems.

19 C Standard Library C programs consist of pieces/modules called functions A programmer can create her own functions Advantage: the programmer knows exactly how it works Disadvantage: time consuming Programmers will often use the C library functions Use these as building blocks Avoid re-inventing the wheel If a pre-made function exists, generally best to use it rather than write your own Library functions carefully written, efficient, and portable

20 20 Performance Tips Using Standard C library functions instead of writing your own comparable versions can improve program performance, because these functions are carefully written to perform efficiently. This can also improve program portability, because these functions are used in virtually all Standard C implementations.

21 1.14 Typical C Program Development Environment 21 Phases of C Programs: Edit: Using a text editor, you create the program and put it into a file Preprocess: The C Preprocessor includes system definitions and removes comments from the file. The result is stored in another file Compile: The C compiler turns the file into object code, and stores the result in a file Link: The Linker combines the object code with libraries, to create a complete executable file Load: The Loader (part of the Operating System) puts the executable file in memory Execute: The microprocessor executes (runs) the program Fig. 1.1 Typical C development environment.

22 1.18 General Notes About C 22 Program clarity Programs that are convoluted are difficult to read, understand, and modify C is a portable language Programs can run on many different computers However, portability is an elusive goal We do a careful walk-through of C Some details and subtleties are not covered If you need additional technical details Read the C standard document Read other books there are many

23 23 Good Programming Practice Write your C programs in a simple and straightforward manner. This is sometimes referred to as KIS ( keep it simple ). Do not stretch the language by trying bizarre usages.

24 24 Software Engineering Observation Your computer and compiler are good teachers. If you are not sure how a feature of C works, write a sample program with that feature, compile and run the program and see what happens.

25 25 2 Introduction to C Programming

26 26 Line numbers are not part of the program! 1 /* Fig. 2.1: fig02_01.c 2 A first program in C */ 3 #include <stdio.h> comments ignored by compiler load a particular file 4 5 /* function main begins program execution */ 6 int main( void ) beginning of main function 7 { 8 printf( "Welcome to C!\n" ); perform an action 9 10 return 0; /* program ended successfully */ ends the function } /* end function main */ end of main function Welcome to C! 2007 Pearson Education, Inc. All rights reserved.

27 2.2 A Simple C Program: Printing a Line of Text 27 Comments Text surrounded by /* and */ is ignored by computer Used to describe program #include <stdio.h> Preprocessor directive Tells computer to load contents of a certain file <stdio.h> allows standard input/output operations

28 28 Common Programming Errors Forgetting to terminate a comment with */. Starting a comment with the characters */ or ending a comment with the characters /*.

29 2.2 A Simple C Program: Printing a Line of Text 29 int main() C programs contain one or more functions, exactly one of which must be main Parenthesis used to indicate a function int means that main "returns" an integer value Braces ({ and }) indicate a block The bodies of all functions must be contained in braces

30 30 Good Programming Practice Every function should be preceded by a comment describing the purpose of the function.

31 2.2 A Simple C Program: Printing a Line of Text 31 printf( "Welcome to C!\n" ); Instructs computer to perform an action Specifically, prints the characters within quotes (" ") Entire line called a statement All statements must end with a semicolon (;) Escape character (\) Indicates that printf should do something out of the ordinary \n is the newline character

32 Escape Description 32 \n Newline. Put the cursor at the beginning of the next line. \t Horizontal tab. Move the cursor to the next tab stop. \a Alert. Sound the system bell. \\ Backslash. Insert a backslash character in a string. \" Double quote. Insert a double-quote character in a string. Fig. 2.2 Some common escape sequences.

33 33 Common Programming Error Typing the name of the output function printf as print in a program.

34 2.2 A Simple C Program: Printing a Line of Text 34 return 0; A way to exit a function return 0, in this case, means that the program terminated normally Right brace } Indicates end of main has been reached Linker When a function is called, linker locates it in the library Inserts it into object program If function name is misspelled, the linker will produce an error because it will not be able to find function in the library

35 35 Good Programming Practices Add a comment to the line containing the right brace, }, that closes every function, including main. The last character printed by a function that displays output should be a newline (\n). This ensures that the function will leave the screen cursor positioned at the beginning of a new line. Conventions of this nature encourage software reusability a key goal in software development environments.

36 36 Good Programming Practice Indent the entire body of each function one level of indentation (we recommend three spaces) within the braces that define the body of the function. This indentation emphasizes the functional structure of programs and helps make programs easier to read. How would you like this instead: /* Fig. 2.1: fig02_01.c A first program in C*/ #include <stdio.h>/*function main begins program*/ int main(void){printf("welcome to C!\n");return 0; /*program ended successfully*/}/*end function main*/

37 37 Good Programming Practice Set a convention for the size of indent you prefer and then uniformly apply that convention. The tab key may be used to create indents, but tab stops may vary. We recommend using three spaces per level of indent.

38 1 /* Fig. 2.3: fig02_03.c 2 Printing on one line with two printf statements */ 3 #include <stdio.h> 4 5 /* function main begins program execution */ 6 int main( void ) 7 { 8 printf( "Welcome " ); 9 printf( "to C!\n" ); 10 printf statement starts printing from where the last statement ended, so the text is printed on one line. 11 return 0; /* indicate that program ended successfully */ } /* end function main */ 38 Welcome to C! 2007 Pearson Education, Inc. All rights reserved.

39 1 /* Fig. 2.4: fig02_04.c 2 Printing multiple lines with a single printf */ 3 #include <stdio.h> 4 5 /* function main begins program execution */ 6 int main( void ) 7 { 8 printf( "Welcome\nto\nC!\n" ); Newlines move the cursor to the next line 9 10 return 0; /* indicate that program ended successfully */ } /* end function main */ 39 Welcome to C! 2007 Pearson Education, Inc. All rights reserved.

40 1 /* Fig. 2.5: fig02_05.c 2 Addition program */ 3 #include <stdio.h> 4 5 /* function main begins program execution */ 6 int main( void ) 7 { 8 int integer1; /* first number to be input by user */ 9 int integer2; /* second number to be input by user */ 10 int sum; /* variable in which sum will be stored */ printf( "Enter first integer\n" ); /* prompt */ 13 scanf( "%d", &integer1 ); /* read integer */ printf( "Enter second integer\n" ); /* prompt */ 16 scanf( "%d", &integer2 ); /* read integer */ 17 variables 18 sum = integer1 + integer2; /* assign total to sum */ Assigns a value to sum printf( "Sum is %d\n", sum ); /* print sum */ return 0; /* program ended successfully */ } /* end function main */ 40 scanf obtains a value from the user and assigns it to a variable 2007 Pearson Education, Inc. All rights reserved.

41 41 Enter first integer 45 Enter second integer 72 Sum is Pearson Education, Inc. All rights reserved.

42 2.3 Another Simple C Program: Adding Two Integers 42 As before Comments, #include <stdio.h> and main int integer1, integer2, sum; Definition of variables, called a declaration Variables: locations in memory where a value can be stored int (its type) means the variables can hold integers (-1, 3, 0, 47) Variable names (identifiers) integer1, integer2, sum Identifiers: consist of letters, digits (cannot begin with a digit) and underscores( _ ) Case sensitive Definitions appear before executable statements If an executable statement references and undeclared variable it will produce a syntax (compiler) error

43 43 Common Programming Errors Using a capital letter where a lowercase letter should be used (for example, typing Main instead of main). Placing variable definitions among executable statements causes syntax errors.

44 44 Good Programming Practice Choosing meaningful variable names helps make a program self-documenting, i.e., fewer comments are needed. The first letter of an identifier used as a simple variable name should be a lowercase letter. Later in the text we will assign special significance to identifiers that begin with a capital letter and to identifiers that use all capital letters.

45 45 Good Programming Practice Multiple-word variable names can help make a program more readable. Avoid running the separate words together as in totalcommissions. Rather, separate the words with underscores as in total_commissions, or, if you do wish to run the words together, begin each word after the first with a capital letter as in totalcommissions. The latter style is preferred.

46 46 Good Programming Practice Separate the definitions and executable statements in a function with one blank line to emphasize where the definitions end and the executable statements begin.

47 2.3 Another Simple C Program: Adding Two Integers 47 scanf( "%d", &integer1 ); Obtains a value from the user scanf uses standard input (usually keyboard) This scanf statement has two arguments %d - indicates data should be a decimal integer conversion specifier &integer1 - location in memory to store variable address operator & is confusing in beginning for now, just remember to include it with the variable name in scanf statements When executing the program the user responds to the scanf statement by typing in a number, then pressing the enter (return) key

48 2.3 Another Simple C Program: Adding Two Integers 48 = (assignment operator) Assigns a value to a variable (assignment statement) Is a binary operator (has two operands) sum = variable1 + variable2; sum gets the value (variable1 + variable2); Variable receiving value on left The right hand side is an expression printf( "Sum is %d\n", sum ); Similar to scanf %d means decimal integer will be printed sum specifies what integer will be printed Calculations can be performed inside printf statements printf( "Sum is %d\n", integer1 + integer2 );

49 49 Good Programming Practice Place spaces on either side of a binary operator. This makes the operator stand out and makes the program more readable. Place a space after each comma (,) to make programs more readable.

50 50 Common Programming Errors A calculation in an assignment statement must be on the right side of the = operator. It is a syntax error to place a calculation on the left side of an assignment operator. Forgetting one or both of the double quotes surrounding the format control string in a printf or scanf.

51 51 Common Programming Errors Forgetting the % in a conversion specification in the format control string of a printf or scanf. Placing an escape sequence such as \n outside the format control string of a printf or scanf.

52 52 Common Programming Errors Forgetting to include the expressions whose values are to be printed in a printf containing conversion specifiers. Not providing a conversion specifier when one is needed in a printf format control string to print the value of an expression.

53 53 Common Programming Errors Placing inside the format control string the comma that is supposed to separate the format control string from the expressions to be printed. Forgetting to precede a variable in a scanf statement with an ampersand when that variable should, in fact, be preceded by an ampersand.

54 54 Common Programming Error Preceding a variable included in a printf statement with an ampersand when, in fact, that variable should not be preceded by an ampersand.

55 Memory Concepts Variables Variable names correspond to locations in the computer's memory Every variable has a name, a type, a size and a value Types are: int (integer), char (character), float, double (both floating point they have decimal points in them) Whenever a new value is placed into a variable (through scanf, for example), it replaces (and destroys) the previous value (destructive operation) Reading variables from memory does not change them, so in: sum = variable1 + variable2; variable1 and variable2 are unchanged (nondestructive operation), but sum is likely to change

56 56 integer1 integer2 sum Fig. 2.8 Memory locations after a calculation.

57 Arithmetic Arithmetic calculations Use * for multiplication and / for division Integer division truncates remainder 7 / 5 evaluates to 1 Modulus operator(%) returns the remainder 7 % 5 evaluates to 2, because 7 = 5*1 + 2 Operator precedence Some arithmetic operators act before others (i.e. multiplication before addition) Use parenthesis when needed Example: Find the average of three variables a, b and c Do not use: a + b + c / 3 Use: (a + b + c ) / 3

58 C operation operator Algebraic C 58 Addition + f + 7 f + 7 Subtraction p c p - c Multiplication * bm b * m Division / x / y x / y Remainder % r mod s r % s Fig. 2.9 Arithmetic operators.

59 59 Common Programming Error An attempt to divide by zero is normally undefined on computer systems and generally results in a fatal error, i.e., an error that causes the program to terminate immediately without having successfully performed its job. Nonfatal errors allow programs to run to completion, often producing incorrect results.

60 60 Operator(s) Operation(s) Order of evaluation (precedence) ( ) Parentheses Evaluated first. If the parentheses are nested, the expression in the innermost pair is evaluated first. If there are several pairs of parentheses on the same level (i.e., not nested), they are evaluated left to right. * / % Multiplication Division Remainder Evaluated second. If there are several, they are evaluated left to right. + - Addition Subtraction Evaluated last. If there are several, they are evaluated left to right. Fig Precedence of arithmetic operators.

61 Step 1. y = 2 * 5 * * 5 + 7; /* leftmost multiplication */ 2 * 5 is Step 2. y = 10 * * 5 + 7; /* leftmost multiplication */ 10 * 5 is 50 Step 3. y = * 5 + 7; /* multiplication first */ 3 * 5 is 15 Step 4. y = ; /* leftmost addition */ is 65 Step 5. y = ; /* last addition */ Step 6. y = 72; Fig Order in which a second-degree polynomial is evaluated.

62 62 Good Programming Practice Using redundant parentheses in complex arithmetic expressions can make the expressions clearer.

63 2.6 Decision Making: Equality and Relational Operators 63 Statements: Perform actions (calculations, input/output of data) Perform decisions May want to print "pass" or "fail" given the value of a test grade if control statement Simple version in this section, more detail later If a condition is true, then the body of the if statement executed 0 is false and non-zero is true Control always resumes after the if structure Keywords Special words reserved for C Cannot be used as identifiers or variable names

64 64 Keywords auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while C s keywords.

65 65 Standard algebraic equality operator or relational operator C equality or relational operator Example of C condition Meaning of C condition Equality operators = == x == y x is equal to y!= x!= y x is not equal to y Relational operators > > x > y x is greater than y < < x < y x is less than y >= x >= y x is greater than or equal to y <= x <= y x is less than or equal to y Fig Equality and relational operators.

66 66 Common Programming Errors A syntax error will occur if the two symbols in any of the operators ==,!=, >= and <= are separated by spaces. A syntax error will occur if the two symbols in any of the operators!=, >= and <= are reversed as in =!, => and =<, respectively.

67 67 Common Programming Errors Confusing the equality operator == with the assignment operator =. Placing a semicolon immediately to the right of the right parenthesis after the condition in an if statement.

68 68 Good Programming Practices Indent the statement(s) in the body of an if statement. Place a blank line before and after every if statement in a program for readability. Although it is allowed, there should be no more than one statement per line in a program.

69 69 Good Programming Practice Consistently applying responsible indentation conventions greatly improves program readability. In this course, we use three blanks per indent.

70 1 /* Fig. 2.13: fig02_13.c 2 Using if statements, relational 3 operators, and equality operators */ 4 #include <stdio.h> 5 6 /* function main begins program execution */ 7 int main( void ) 8 { 9 int num1; /* first number to be read from user */ 10 int num2; /* second number to be read from user */ printf( "Enter two integers, and I will tell you\n" ); 13 printf( "the relationships they satisfy: " ); scanf( "%d%d", &num1, &num2 ); /* read two integers */ if ( num1 == num2 ) { Checks if num1 is equal to num2 18 printf( "%d is equal to %d\n", num1, num2 ); 19 } /* end if */ if ( num1!= num2 ) { Checks if num1 is not equal to num2 22 printf( "%d is not equal to %d\n", num1, num2 ); 23 } /* end if */ Continued on next slide Pearson Education, Inc. All rights reserved.

71 25 if ( num1 < num2 ) { Checks if num1 is less than num2 26 printf( "%d is less than %d\n", num1, num2 ); 27 } /* end if */ if ( num1 > num2 ) { 30 printf( "%d is greater than %d\n", num1, num2 ); 31 } /* end if */ if ( num1 <= num2 ) { Checks if num1 is greater than num2 Checks if num1 is less than or equal to num2 34 printf( "%d is less than or equal to %d\n", num1, num2 ); 35 } /* end if */ if ( num1 >= num2 ) { Checks if num1 is greater than equal to num2 38 printf( "%d is greater than or equal to %d\n", num1, num2 ); 39 } /* end if */ return 0; /* indicate that program ended successfully */ 42 } Pearson Education, Inc. All rights reserved.

72 Enter two integers, and I will tell you the relationships they satisfy: is not equal to 7 3 is less than 7 3 is less than or equal to 7 72 Enter two integers, and I will tell you the relationships they satisfy: is not equal to is greater than is greater than or equal to 12 Enter two integers, and I will tell you the relationships they satisfy: is equal to 7 7 is less than or equal to 7 7 is greater than or equal to Pearson Education, Inc. All rights reserved.

73 73 Good Programming Practice A lengthy statement may be spread over several lines. If a statement must be split across lines, choose breaking points that make sense (such as after a comma in a comma-separated list). If a statement is split across two or more lines, indent all subsequent lines.

74 74 Good Programming Practice Refer to the operator precedence chart when writing expressions containing many operators. Confirm that the operators in the expression are applied in the proper order. If you are uncertain about the order of evaluation in a complex expression, use parentheses to group expressions or break the statement into several simpler statements.

75 75 Operators Associativity ( ) left to right * / % left to right + - left to right < <= > >= left to right ==!= left to right = right to left Fig Precedence and associativity of the operators discussed so far.

76 76 3 Structured Program Development in C

77 Introduction Before writing a program: Have a thorough understanding of the problem Carefully plan an approach for solving it While writing a program: Know what building blocks are available Use good programming principles

78 Algorithms Computing problems All can be solved by executing a series of actions in a specific order Algorithm: procedure in terms of Actions to be executed The order in which these actions are to be executed Program control Specify order in which statements are to be executed

79 Pseudocode Pseudocode Artificial, informal language that helps us develop algorithms Similar to everyday English Not actually executed on computers Helps us think out a program before writing it Easy to convert into a corresponding program Consists only of executable statements

80 Control Structures Sequential execution Statements executed one after the other in the order written Transfer of control When the next statement executed is not the next one in sequence Building blocks All programs written in terms of 3 control structures Sequence structures: Built into C. Programs executed sequentially by default Selection structures: C has three types: if, if else, and switch Repetition structures: C has three types: while, do while and for

81 81 Add grade to total total = total + grade; Add 1 to counter counter = counter + 1; Fig. 3.1 Flowcharting C s sequence structure.

82 Control Structures Flowchart Graphical representation of an algorithm Drawn using certain special-purpose symbols connected by arrows called flowlines Rectangle symbol (action symbol): Indicates any type of action Oval symbol: Indicates the beginning or end of a program or a section of code Single-entry/single-exit control structures Connect exit point of one control structure to entry point of the next (control-structure stacking) Makes programs easy to build

83 The if selection statement Selection structure: Used to choose among alternative courses of action Pseudocode: If student s grade is greater than or equal to 60 Print Passed If condition true Print statement executed and program goes on to next statement If false, print statement is ignored and the program goes onto the next statement Indenting makes programs easier to read C ignores whitespace characters

84 84 Good Programming Practice Pseudocode is often used to think out a program during the program design process. Then the pseudocode program is converted to C.

85 The if selection statement Pseudocode statement in C: if ( grade >= 60 ) printf( "Passed\n" ); C code corresponds closely to the pseudocode Diamond symbol (decision symbol) Indicates decision is to be made Contains an expression that can be true or false Test the condition, follow appropriate path

86 86 grade >= 60 true print passed false Fig. 3.2 Flowcharting the single-selection if statement.

87 3.6 The if else selection statement 87 if Only performs an action if the condition is true if else Specifies an action to be performed both when the condition is true and when it is false Pseudocode: If student s grade is greater than or equal to 60 Print Passed else Print Failed Note spacing/indentation conventions

88 88 Good Programming Practices Indent both body statements of an if...else statement. If there are several levels of indentation, each level should be indented the same additional amount of space.

89 3.6 The if else selection statement C code: if ( grade >= 60 ) printf( "Passed\n"); else printf( "Failed\n"); Ternary conditional operator (? :) Takes three arguments (condition, value if true, value if false) Our pseudocode could be written: printf( "%s\n", grade >= 60? "Passed" : "Failed" ); Or it could have been written: grade >= 60? printf( Passed\n ) : printf( Failed\n ); 89

90 90 print failed false grade >= 60 true print passed Fig. 3.3 Flowcharting the double-selection if...else statement.

91 3.6 The if else selection statement 91 Nested if else statements Test for multiple cases by placing if else selection statements inside if else selection statement Once condition is met, rest of statements skipped Deep indentation usually not used in practice

92 3.6 The if else selection statement 92 Pseudocode for a nested if else statement If student s grade is greater than or equal to 90 Print A else If student s grade is greater than or equal to 80 Print B else If student s grade is greater than or equal to 70 Print C else If student s grade is greater than or equal to 60 Print D else Print F

93 3.6 The if else selection statement Compound statement: Set of statements within a pair of braces Example: if ( grade >= 60 ) printf( "Passed.\n" ); else { printf( "Failed.\n" ); printf( "You must take this course again.\n" ); } Without the braces, the statement printf( "You must take this course again.\n" ); would be executed automatically 93

94 94 Software Engineering Observation A compound statement can be placed anywhere in a program that a single statement can be placed. It is also possible to have no statement at all, i.e., the empty statement. The empty statement is represented by placing a semicolon (;) where a statement would normally be.

95 95 Common Programming Error Forgetting one or both of the braces that delimit a compound statement. This usually leads the compiler to issue error messages that make little sense initially they may occur much later in the program.

96 96 Common Programming Error Placing a semicolon after the condition in an if statement as in if ( grade >= 60 ); leads to a logic error in single-selection if statements and a syntax error in doubleselection if statements.

97 97 Error-Prevention Tip Typing the beginning and ending braces of compound statements before typing the individual statements within the braces helps avoid omitting one or both of the braces, preventing syntax errors and logic errors (where both braces are indeed required).

98 The while repetition statement Repetition structure Programmer specifies an action to be repeated while some condition remains true Pseudocode: While there are more items on my shopping list Purchase next item and cross it off my list while loop repeated until condition becomes false Example: int product = 2; while ( product <= 1000 ) product = 2 * product;

99 99 Common Programming Errors Not providing the body of a while statement with an action that eventually causes the condition in the while to become false. Normally, such a repetition structure will never terminate an error called an infinite loop. Spelling the keyword while with an uppercase W as in While (remember that C is a casesensitive language). All of C s reserved keywords such as while, if and else contain only lowercase letters.

100 100 product <= 1000 true product = 2 * product false Fig. 3.4 Flowcharting the while repetition statement.

101 Counter-Controlled Repetition Counter-controlled repetition Loop repeated until counter reaches a certain value Definite repetition: number of repetitions is known Example: A class of ten students took a quiz. The grades (integers in the range 0 to 100) for this quiz are available to you. Determine the class average on the quiz.

102 102 1 Set total to zero 2 Set grade counter to one 3 4 While grade counter is less than or equal to ten 5 Input the next grade 6 Add the grade into the total 7 Add one to the grade counter 8 9 Set the class average to the total divided by ten 10 Print the class average Fig. 3.5 Pseudocode algorithm that uses counter-controlled repetition to solve the class average problem.

103 1 /* Fig. 3.6: fig03_06.c 2 Class average program with counter-controlled repetition */ 3 #include <stdio.h> 4 5 /* function main begins program execution */ 6 int main( void ) 7 { 8 int counter; /* number of grade */ 9 int grade; /* grade value */ 10 int total; /* sum of grades input by user */ 11 int average; /* average of grades */ /* initialization phase */ 14 total = 0; /* initialize total */ 15 counter = 1; /* initialize loop counter */ /* processing phase */ 18 while ( counter <= 10 ) { /* loop 10 times */ 19 printf( "Enter grade: " ); /* ask for input */ 20 scanf( "%d", &grade ); /* read grade */ 21 total = total + grade; /* add grade to total */ 22 counter = counter + 1; /* increment */ 23 } /* end while */ Counter to control while loop Initialize counter to 1 while loop iterates as long as counter <= 10 Increment the counter Continued on next slide Pearson Education, Inc. All rights reserved.

104 25 /* termination phase */ 26 average = total / 10; /* integer division */ Calculate the average printf( "Class average is %d\n", average ); /* result */ return 0; } /* end function main */ 104 Enter grade: 98 Enter grade: 76 Enter grade: 71 Enter grade: 87 Enter grade: 83 Enter grade: 90 Enter grade: 57 Enter grade: 79 Enter grade: 82 Enter grade: 94 Class average is Pearson Education, Inc. All rights reserved.

105 105 Common Programming Error If a counter or total is not initialized, the results of your program will probably be incorrect. This is an example of a logic error. You must initialize all counters and totals.

106 3.9 Formulating Algorithms with Top- Down, Stepwise Refinement 106 Problem becomes: Develop a class-averaging program that will process an arbitrary number of grades each time the program is run. Unknown number of students How will the program know to end? Use sentinel value Also called signal value, dummy value, or flag value Indicates end of data entry. Loop ends when user inputs the sentinel value Sentinel value chosen so it cannot be confused with a regular input (such as -1 in this case)

107 107 Common Programming Error Choosing a sentinel value that is also a legitimate data value.

108 3.9 Formulating Algorithms with Top- Down, Stepwise Refinement 108 Top-down, stepwise refinement Begin with a pseudocode representation of the top: Determine the class average for the quiz Divide top into smaller tasks and list them in order: Initialize variables Input, sum and count the quiz grades Calculate and print the class average Many programs have three phases: Initialization: initializes the program variables Processing: inputs data values and adjusts program variables accordingly Termination: calculates and prints the final results

109 3.9 Formulating Algorithms with Top- Down, Stepwise Refinement 109 Refine the initialization phase from Initialize variables to: Initialize total to zero Initialize counter to zero Refine Input, sum and count the quiz grades to Input the first grade (possibly the sentinel) While the user has not as yet entered the sentinel Add this grade into the running total Add one to the grade counter Input the next grade (possibly the sentinel)

110 3.9 Formulating Algorithms with Top- Down, Stepwise Refinement 110 Refine Calculate and print the class average to If the counter is not equal to zero Set the average to the total divided by the counter Print the average else Print No grades were entered

111 111 1 Initialize total to zero 2 Initialize counter to zero 3 4 Input the first grade 5 While the user has not as yet entered the sentinel 6 Add this grade into the running total 7 Add one to the grade counter 8 Input the next grade (possibly the sentinel) 9 10 If the counter is not equal to zero 11 Set the average to the total divided by the counter 12 Print the average 13 else 14 Print No grades were entered Fig. 3.7 Pseudocode algorithm that uses sentinel-controlled repetition to solve the class average problem.

112 112 Good Programming Practice When performing division by an expression whose value could be zero, explicitly test for this case and handle it appropriately in your program (such as printing an error message) rather than allowing the fatal error to occur.

113 113 Software Engineering Observation Many programs can be divided logically into three phases: an initialization phase that initializes the program variables; a processing phase that inputs data values and adjusts program variables accordingly; and a termination phase that calculates and prints the final results.

114 114 Software Engineering Observation You terminate the top-down, stepwise refinement process when the pseudocode algorithm is specified in sufficient detail for you to be able to convert the pseudocode to C. Implementing the C program is then normally straightforward.

115 115 Floating point numbers Integer numbers have obvious limitations No fractions needed in most scientific and engineering applications Integers are relatively small Numbers with fractions (i.e. decimal point) are called floating point numbers, and are declared as float or double Double allows larger numbers Printed with %f Examples: etc.

116 1 /* Fig. 3.8: fig03_08.c 2 Class average program with sentinel-controlled repetition */ 3 #include <stdio.h> 4 5 /* function main begins program execution */ 6 int main( void ) 7 { 8 int counter; /* number of grades entered */ 9 int grade; /* grade value */ 10 int total; /* sum of grades */ float average; /* number with decimal point*/ /* initialization phase */ 15 total = 0; /* initialize total */ 16 counter = 0; /* initialize loop counter */ /* processing phase */ 19 /* get first grade from user */ float type indicates variable can be a noninteger 20 printf( "Enter grade, -1 to end: " ); /* prompt for input */ 21 scanf( "%d", &grade ); /* read grade from user */ Continued on next slide Pearson Education, Inc. All rights reserved.

117 23 /* loop while sentinel value not yet read from user */ 24 while ( grade!= -1 ) { while loop repeats until user enters a value of total = total + grade; /* add grade to total */ 26 counter = counter + 1; /* increment counter */ /* get next grade from user */ 29 printf( "Enter grade, -1 to end: " ); /* prompt for input */ 30 scanf("%d", &grade); /* read next grade */ 31 } /* end while */ /* termination phase */ 34 /* if user entered at least one grade */ 35 if ( counter!= 0 ) { 36 Ensures the user entered at least one grade 37 /* calculate average of all grades entered */ 38 average = ( float ) total / counter; /* avoid truncation */ Converts total to float type /* display average with two digits of precision */ 41 printf( "Class average is %.2f\n", average ); 42 } /* end if */ Prints result with 2 digits after decimal point... Continued on next slide Pearson Education, Inc. All rights reserved.

118 43 else { /* if no grades were entered, output message */ 44 printf( "No grades were entered\n" ); 45 } /* end else */ return 0; } /* end function main */ 118 Enter grade, -1 to end: 75 Enter grade, -1 to end: 94 Enter grade, -1 to end: 97 Enter grade, -1 to end: 88 Enter grade, -1 to end: 70 Enter grade, -1 to end: 64 Enter grade, -1 to end: 83 Enter grade, -1 to end: 89 Enter grade, -1 to end: -1 Class average is Enter grade, -1 to end: -1 No grades were entered 2007 Pearson Education, Inc. All rights reserved.

119 119 Good Programming Practice In a sentinel-controlled loop, the prompts requesting data entry should explicitly remind the user what the sentinel value is.

120 120 Print width specification Integers are printed with %d Prints from current position Not helpful if you want align numbers in vertical direction A print width specification (also called padding ) can be inserted between the % and the d For example: %6d says print at least 6 characters, and print spaces first if necessary Example on next slide

121 1 /* Example of print width specification */ 2 #include <stdio.h> 3 4 int main( void ) 5 { 6 int i = 3; 7 int j = 850; 8 int k = ; 9 10 printf( "%d\n%d\n\n", i, j ); 11 printf( "%6d\n%6d\n\n", i, j ); 12 printf( "%6d\n", k ); 13 return 0; /* program ended successfully */ } /* end function main */ Pearson Education, Inc. All rights reserved.

122 122 Print width specification Examples of printing of floating point numbers: %f print from current position %20f print at least 20 characters %.2f print two digits after decimal point %20.2f print at least 20 characters, with two after the decimal point If you use %f, you often get many digits after the decimal point, which is not necessarily what you want

123 1 /* Example of float print width specification */ 2 #include <stdio.h> 3 4 int main( void ) 5 { 6 7 float f = 10.0 / 7.0; 8 9 printf( "%f\n", f ); 10 printf( "%20f\n", f ); 11 printf( "%.2f\n", f ); 12 printf( "%20.2f\n", f ); return 0; /* program ended successfully */ } /* end function main */ Pearson Education, Inc. All rights reserved.

124 124 Common Programming Errors Using precision in a conversion specification in the format control string of a scanf statement is wrong. Precisions are used only in printf conversion specifications. Using floating-point numbers in a manner that assumes they are represented precisely can lead to incorrect results. Floating-point numbers are represented only approximately by most computers. Do not compare floating-point values for equality.

125 Nested Control Structures Problem A college has a list of test results (1 = pass, 2 = fail) for 10 students Write a program that analyzes the results If more than 8 students pass, print "Raise Tuition" Notice that The program must process 10 test results Counter-controlled loop will be used Two counters can be used One for number of passes, one for number of fails Each test result is a number either a 1 or a 2 If the number is not a 1, we assume that it is a 2

126 Nested Control Structures Top level outline Analyze exam results and decide if tuition should be raised First Refinement Initialize variables Input the ten quiz grades and count passes and failures Print a summary of the exam results and decide if tuition should be raised Refine Initialize variables to Initialize passes to zero Initialize failures to zero Initialize student counter to one

127 Nested Control Structures Refine Input the ten quiz grades and count passes and failures to While student counter is less than or equal to ten Input the next exam result If the student passed Add one to passes else Add one to failures Add one to student counter Refine Print a summary of the exam results and decide if tuition should be raised to Print the number of passes Print the number of failures If more than eight students passed Print Raise tuition

128 1 Initialize passes to zero 2 Initialize failures to zero 3 Initialize student to one 4 5 While student counter is less than or equal to ten 6 Input the next exam result 7 8 If the student passed 9 Add one to passes 10 else 11 Add one to failures Add one to student counter Print the number of passes 16 Print the number of failures 17 If more than eight students passed 18 Print Raise tuition 128 Fig. 3.9 Pseudocode for examination results problem.

129 129 1 /* Fig. 3.10: fig03_10.c 2 Analysis of examination results */ 3 #include <stdio.h> 4 6 int main( void ) 7 { 8 /* initialize variables in definitions */ 9 int passes = 0; /* number of passes */ 10 int failures = 0; /* number of failures */ 11 int student = 1; /* student counter */ 12 int result; /* one exam result */ /* process 10 students using counter-controlled loop */ 15 while ( student <= 10 ) { 16 while loop continues until 10 students processed 17 /* prompt user for input and obtain value from user */ 18 printf( "Enter result ( 1=pass,2=fail ): " ); 19 scanf( "%d", &result ); 2007 Pearson Education, Inc. All rights reserved.

130 21 /* if result 1, increment passes */ 22 if ( result == 1 ) { 23 passes = passes + 1; 24 } /* end if */ 25 else { /* otherwise, increment failures */ 26 failures = failures + 1; 27 } /* end else */ 28 if and else statements are nested inside while loop 29 student = student + 1; /* increment student counter */ 30 } /* end while */ /* termination phase; display number of passes and failures */ 33 printf( "Passed %d\n", passes ); 34 printf( "Failed %d\n", failures ); /* if more than eight students passed, print "raise tuition" */ 37 if ( passes > 8 ) { 38 printf( "Raise tuition\n" ); 39 } /* end if */ return 0; } Pearson Education, Inc. All rights reserved.

131 Enter Result (1=pass,2=fail): 1 Enter Result (1=pass,2=fail): 1 Enter Result (1=pass,2=fail): 1 Enter Result (1=pass,2=fail): 2 Enter Result (1=pass,2=fail): 1 Enter Result (1=pass,2=fail): 1 Enter Result (1=pass,2=fail): 1 Enter Result (1=pass,2=fail): 1 Enter Result (1=pass,2=fail): 1 Enter Result (1=pass,2=fail): 1 Passed 9 Failed 1 Raise tuition Pearson Education, Inc. All rights reserved.

132 132 Performance Tip Initializing variables when they are defined can help reduce a program s execution time. Many of the performance tips we mention result in nominal improvements, so the reader may be tempted to ignore them. Note that the cumulative effect of all these performance enhancements can make a program perform significantly faster. Also, significant improvement is realized when a supposedly nominal improvement is placed in a loop that may repeat a large number of times.

133 Assignment Operators Assignment operators abbreviate assignment expressions c = c + 3; can be abbreviated as c += 3; using the addition assignment operator Statements of the form variable = variable operator expression; can be rewritten as variable operator= expression; Examples of other assignment operators: d -= 4 (d = d - 4) e *= 5 (e = e * 5) f /= 3 (f = f / 3) g %= 9 (g = g % 9)

134 134 Assignment operator Sample expression Explanation Assigns Assume: int c = 3, d = 5, e = 4, f = 6, g = 12; += c += 7 c = c to c -= d -= 4 d = d to d *= e *= 5 e = e * 5 20 to e /= f /= 3 f = f / 3 2 to f %= g %= 9 g = g % 9 3 to g Fig Arithmetic assignment operators.

135 3.12 Increment and Decrement Operators 135 Increment operator (++) Can be used instead of c+=1 Decrement operator (--) Can be used instead of c-=1 Preincrement Operator is used before the variable (++c or --c) Variable is changed before the expression it is in is evaluated Postincrement Operator is used after the variable (c++ or c--) Expression executes before the variable is changed

136 3.12 Increment and Decrement Operators 136 If c equals 5, then printf( "%d", ++c ); Prints 6 printf( "%d", c++ ); Prints 5 In either case, c now has the value of 6 When variable not in an expression Preincrementing and postincrementing have the same effect ++c; printf( %d, c ); Has the same effect as c++; printf( %d, c );

137 137 Operator Sample expression Explanation ++ ++a Increment a by 1, then use the new value of a in the expression in which a resides. ++ a++ Use the current value of a in the expression in which a resides, then increment a by b Decrement b by 1, then use the new value of b in the expression in which b resides. -- b-- Use the current value of b in the expression in which b resides, then decrement b by 1. Fig Increment and decrement operators.

138 1 /* Fig. 3.13: fig03_13.c 2 Preincrementing and postincrementing */ 3 #include <stdio.h> 4 5 /* function main begins program execution */ 6 int main( void ) 7 { 8 int c; /* define variable */ 9 10 /* demonstrate postincrement */ 11 c = 5; /* assign 5 to c */ 12 printf( "%d\n", c ); /* print 5 */ 13 printf( "%d\n", c++ ); /* print 5 then postincrement */ 14 printf( "%d\n\n", c ); /* print 6 */ /* demonstrate preincrement */ 17 c = 5; /* assign 5 to c */ 18 printf( "%d\n", c ); /* print 5 */ 19 printf( "%d\n", ++c ); /* preincrement then print 6 */ 20 printf( "%d\n", c ); /* print 6 */ return 0; } /* end function main */ c is printed, then incremented c is incremented, then printed Pearson Education, Inc. All rights reserved.

139 Pearson Education, Inc. All rights reserved.

140 140 Good Programming Practice Unary operators should be placed directly next to their operands with no intervening spaces.

141 141 Common Programming Error Attempting to use the increment or decrement operator on an expression other than a simple variable name is a syntax error, e.g., writing ++(x + 1).

142 142 Operators Associativity Type ++(post) -- (post) right to left postfix + - (type) ++ (pre) -- (pre) right to left unary * / % left to right multiplicative + - left to right additive < <= > >= left to right relational ==!= left to right equality?: right to left conditional = += -= *= /= %= right to left assignment Fig Precedence of the operators encountered so far in the text.

143 143 Debugging Your program compiles, but it does not run correctly! What to do now? Ask your more knowledgeable colleagues? Read the lecture notes Read a C textbook Read the code statement by statement Walk-through Check the effect of each statement on the state of the program

144 144 Debugging Read the code statement by statement Walk-through: Check the effect of each statement on the state of the program State = Values of attributes of each object Value of each simple variable Value of individual attributes of other program elements Make a table

Chapter 3 Structured Program Development

Chapter 3 Structured Program Development 1 Chapter 3 Structured Program Development Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 3 - Structured Program Development Outline 3.1 Introduction

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

Structured Program Development in C

Structured Program Development in C 1 3 Structured Program Development in C 3.2 Algorithms 2 Computing problems All can be solved by executing a series of actions in a specific order Algorithm: procedure in terms of Actions to be executed

More information

Chapter 1 & 2 Introduction to C Language

Chapter 1 & 2 Introduction to C Language 1 Chapter 1 & 2 Introduction to C Language Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 1 & 2 - Introduction to C Language 2 Outline 1.1 The History

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,

More information

Structured Program Development

Structured Program Development Structured Program Development Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Introduction The selection statement if if.else switch The

More information

Introduction to C Programming

Introduction to C Programming 1 2 Introduction to C Programming 2.6 Decision Making: Equality and Relational Operators 2 Executable statements Perform actions (calculations, input/output of data) Perform decisions - May want to print

More information

CSE123 LECTURE 3-1. Program Design and Control Structures Repetitions (Loops) 1-1

CSE123 LECTURE 3-1. Program Design and Control Structures Repetitions (Loops) 1-1 CSE123 LECTURE 3-1 Program Design and Control Structures Repetitions (Loops) 1-1 The Essentials of Repetition Loop Group of instructions computer executes repeatedly while some condition remains true Counter-controlled

More information

Chapter 1 Introduction to Computers and C++ Programming

Chapter 1 Introduction to Computers and C++ Programming Chapter 1 Introduction to Computers and C++ Programming 1 Outline 1.1 Introduction 1.2 What is a Computer? 1.3 Computer Organization 1.7 History of C and C++ 1.14 Basics of a Typical C++ Environment 1.20

More information

Introduction to Programming

Introduction to Programming Introduction to Programming session 6 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Spring 2011 These slides are created using Deitel s slides Sharif University of Technology Outlines

More information

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 6/e Before writing a program to solve a particular problem, it s essential to have a thorough understanding of the problem and a carefully planned approach to solving the problem. The

More information

IS 0020 Program Design and Software Tools

IS 0020 Program Design and Software Tools 1 IS 0020 Program Design and Software Tools Introduction to C++ Programming Spring 2005 Lecture 1 Jan 6, 2005 Course Information 2 Lecture: James B D Joshi Tuesdays/Thursdays: 1:00-2:15 PM Office Hours:

More information

Programming for Engineers Introduction to C

Programming for Engineers Introduction to C Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

More information

Introduction to C++ Programming Pearson Education, Inc. All rights reserved.

Introduction to C++ Programming Pearson Education, Inc. All rights reserved. 1 2 Introduction to C++ Programming 2 What s in a name? that which we call a rose By any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would be the

More information

Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

More information

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a

More information

Chapter 2 - Control Structures

Chapter 2 - Control Structures Chapter 2 - Control Structures 1 Outline 2.1 Introduction 2.2 Algorithms 2.3 Pseudocode 2.4 Control Structures 2.5 if Selection Structure 2.6 if/else Selection Structure 2.7 while Repetition Structure

More information

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

Introduction to C++ Programming. Adhi Harmoko S, M.Komp Introduction to C++ Programming Adhi Harmoko S, M.Komp Machine Languages, Assembly Languages, and High-level Languages Three types of programming languages Machine languages Strings of numbers giving machine

More information

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Fundamentals of Programming. Lecture 3: Introduction to C Programming Fundamentals of Programming Lecture 3: Introduction to C Programming Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department Outline A Simple C

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

Data types, variables, constants

Data types, variables, constants Data types, variables, constants Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic in C 2.6 Decision

More information

Chapter 1 Introduction to Computers and C++ Programming

Chapter 1 Introduction to Computers and C++ Programming Chapter 1 Introduction to Computers and C++ Programming 1 Outline 1.1 Introduction 1.2 What Is a Computer? 1.3 Computer Organization 1.4 Evolution of Operating Systems 1.5 Personal Computing, Distributed

More information

Fundamentals of Programming. Lecture 6: Structured Development (part one)

Fundamentals of Programming. Lecture 6: Structured Development (part one) Fundamentals of Programming Lecture 6: Structured Development (part one) Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu edu Sharif University of Technology Computer Engineering Department Outline Algorithms

More information

JavaScript: Control Statements I Pearson Education, Inc. All rights reserved.

JavaScript: Control Statements I Pearson Education, Inc. All rights reserved. 1 7 JavaScript: Control Statements I 2 Let s all move one place on. Lewis Carroll The wheel is come full circle. William Shakespeare How many apples fell on Newton s head before he took the hint! Robert

More information

Chapter 2 - Control Structures

Chapter 2 - Control Structures Chapter 2 - Control Structures 1 2.1 Introduction 2.2 Algorithms 2.3 Pseudocode 2.4 Control Structures 2.5 if Selection Structure 2.6 if/else Selection Structure 2.7 while Repetition Structure 2.8 Formulating

More information

In Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability. programs into their various phases.

In Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability. programs into their various phases. Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 2: Sentinel-Controlled Repetition In Fig. 3.5 and Fig. 3.7, we include some completely blank lines in the pseudocode for readability.

More information

Chapter 2 - Control Structures

Chapter 2 - Control Structures Chapter 2 - Control Structures 1 Outline 2.1 Introduction 2.2 Algorithms 2.3 Pseudocode 2.4 Control Structures 2.5 if Selection Structure 2.6 if/else Selection Structure 2.7 while Repetition Structure

More information

0 Introduction: Computer systems and program development

0 Introduction: Computer systems and program development 0 Introduction: Computer systems and program development Outline 1 Introduction 2 What Is a Computer? 3 Computer Organization 4 Evolution of Operating Systems 5 Personal Computing, Distributed Computing

More information

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M Control Structures Intro. Sequential execution Statements are normally executed one

More information

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Copyright 1992-2012 by Pearson Copyright 1992-2012 by Pearson Before writing a program to solve a problem, have

More information

Full file at C How to Program, 6/e Multiple Choice Test Bank

Full file at   C How to Program, 6/e Multiple Choice Test Bank 2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

More information

Chapter 3 Structured Program Development in C Part II

Chapter 3 Structured Program Development in C Part II Chapter 3 Structured Program Development in C Part II C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 3.7 The while Iteration Statement An iteration statement (also called

More information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. 2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

More information

SEQUENTIAL STRUCTURE. Erkut ERDEM Hacettepe University October 2010

SEQUENTIAL STRUCTURE. Erkut ERDEM Hacettepe University October 2010 SEQUENTIAL STRUCTURE Erkut ERDEM Hacettepe University October 2010 History of C C Developed by by Denis M. Ritchie at AT&T Bell Labs from two previous programming languages, BCPL and B Used to develop

More information

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

More information

IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

Introduction to Programming

Introduction to Programming Introduction to Programming session 5 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel s slides Sahrif University of Technology Outlines

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

Introduction to Computers, the Internet and the Web Pearson Education, Inc. All rights reserved.

Introduction to Computers, the Internet and the Web Pearson Education, Inc. All rights reserved. 1 1 Introduction to Computers, the Internet and the Web 2 The chief merit of language is clearness. Galen Our life is frittered away by detail. Simplify, simplify. Henry David Thoreau He had a wonderful

More information

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU CSE101-lec#12 Designing Structured Programs Introduction to Functions Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Designing structured programs in C: Counter-controlled repetition

More information

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3 Programming - 1 Computer Science Department 011COMP-3 لغة البرمجة 1 011 عال- 3 لطالب كلية الحاسب اآللي ونظم المعلومات 1 1.1 Machine Language A computer programming language which has binary instructions

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah Lecturer Department of Computer Science & IT University of Balochistan 1 Outline p Introduction p Program development p C language and beginning with

More information

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator 1 A Closer Look at the / Operator Used for performing numeric calculations C++ has unary, binary, and ternary s: unary (1 operand) - binary ( operands) 13-7 ternary (3 operands) exp1? exp : exp3 / (division)

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba Before writing a program to solve a problem, have a thorough understanding of the problem and a carefully planned approach to solving it. Understand the types of building

More information

Fundamentals of Programming Session 7

Fundamentals of Programming Session 7 Fundamentals of Programming Session 7 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2014 These slides have been created using Deitel s slides Sharif University of Technology Outlines

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine

More information

Chapter 2, Part I Introduction to C Programming

Chapter 2, Part I Introduction to C Programming Chapter 2, Part I Introduction to C Programming C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 2016 Pearson Education, Ltd. All rights reserved. 2 2016 Pearson Education,

More information

BIL101E: Introduction to Computers and Information systems Lecture 8

BIL101E: Introduction to Computers and Information systems Lecture 8 BIL101E: Introduction to Computers and Information systems Lecture 8 8.1 Algorithms 8.2 Pseudocode 8.3 Control Structures 8.4 Decision Making: Equality and Relational Operators 8.5 The if Selection Structure

More information

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq CS 241 Computer Programming Introduction Teacher Assistant Hadeel Al-Ateeq 1 2 Course URL: http://241cs.wordpress.com/ Hadeel Al-Ateeq 3 Textbook HOW TO PROGRAM BY C++ DEITEL AND DEITEL, Seventh edition.

More information

ANSI C Programming Simple Programs

ANSI C Programming Simple Programs ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1 BIL 104E Introduction to Scientific and Engineering Computing Lecture 1 Introduction As engineers and scientists why do we need computers? We use computers to solve a variety of problems ranging from evaluation

More information

Chapter 2 Author Notes

Chapter 2 Author Notes Chapter 2 Author Notes Good Programming Practice 2.1 Every program should begin with a comment that explains the purpose of the program, the author and the date and time the program was last modified.

More information

JavaScript: Control Statements I

JavaScript: Control Statements I 7 JavaScript: Control Statements I OBJECTIVES In this chapter you will learn: Basic problem-solving techniques. To develop algorithms through the process of top-down, stepwise refinement. To use the if

More information

Instructor. Mehmet Zeki COSKUN Assistant Professor at the Geodesy & Photogrammetry, Civil Eng. (212)

Instructor. Mehmet Zeki COSKUN Assistant Professor at the Geodesy & Photogrammetry, Civil Eng. (212) Instructor Mehmet Zeki COSKUN Assistant Professor at the Geodesy & Photogrammetry, Civil Eng. (212) 285-6573 coskunmeh@itu.edu.tr http://atlas.cc.itu.edu.tr/~coskun Address Consultation of Students: Monday

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

Introduction to C Final Review Chapters 1-6 & 13

Introduction to C Final Review Chapters 1-6 & 13 Introduction to C Final Review Chapters 1-6 & 13 Variables (Lecture Notes 2) Identifiers You must always define an identifier for a variable Declare and define variables before they are called in an expression

More information

Introduction to Python Programming

Introduction to Python Programming 2 Introduction to Python Programming Objectives To understand a typical Python program-development environment. To write simple computer programs in Python. To use simple input and output statements. To

More information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify

More information

Introduction to C# Applications Pearson Education, Inc. All rights reserved.

Introduction to C# Applications Pearson Education, Inc. All rights reserved. 1 3 Introduction to C# Applications 2 What s in a name? That which we call a rose by any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would be the

More information

CS110D: PROGRAMMING LANGUAGE I

CS110D: PROGRAMMING LANGUAGE I CS110D: PROGRAMMING LANGUAGE I Computer Science department Lecture 5&6: Loops Lecture Contents Why loops?? While loops for loops do while loops Nested control structures Motivation Suppose that you need

More information

Unit 3. Operators. School of Science and Technology INTRODUCTION

Unit 3. Operators. School of Science and Technology INTRODUCTION INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

More information

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break

More information

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

More information

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

More information

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M tutor Isam M. Al Jawarneh, PhD student isam.aljawarneh3@unibo.it Mobile Middleware

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Introduction to Java Applications; Input/Output and Operators

Introduction to Java Applications; Input/Output and Operators www.thestudycampus.com Introduction to Java Applications; Input/Output and Operators 2.1 Introduction 2.2 Your First Program in Java: Printing a Line of Text 2.3 Modifying Your First Java Program 2.4 Displaying

More information

Course Outline. Introduction to java

Course Outline. Introduction to java Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.

More information

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out REGZ9280: Global Education Short Course - Engineering 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. REGZ9280 14s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write

More information

INTRODUCTION 1 AND REVIEW

INTRODUCTION 1 AND REVIEW INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Chapter 2 Basic Elements of C++

Chapter 2 Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion

More information

Control Statements. Musa M. Ameen Computer Engineering Dept.

Control Statements. Musa M. Ameen Computer Engineering Dept. 2 Control Statements Musa M. Ameen Computer Engineering Dept. 1 OBJECTIVES In this chapter you will learn: To use basic problem-solving techniques. To develop algorithms through the process of topdown,

More information

BITG 1233: Introduction to C++

BITG 1233: Introduction to C++ BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

2.8. Decision Making: Equality and Relational Operators

2.8. Decision Making: Equality and Relational Operators Page 1 of 6 [Page 56] 2.8. Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. This section introduces a simple version of Java's if statement

More information

Lecture 3 Tao Wang 1

Lecture 3 Tao Wang 1 Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers

More information

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode STUDENT OUTLINE Lesson 8: Structured Programming, Control Structures, if- Statements, Pseudocode INTRODUCTION: This lesson is the first of four covering the standard control structures of a high-level

More information

Chapter 4 C Program Control

Chapter 4 C Program Control 1 Chapter 4 C Program Control Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Chapter 4 C Program Control Outline 4.1 Introduction 4.2 The Essentials of Repetition

More information

Information Science 1

Information Science 1 Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting

More information

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

C++ Programming Language Lecture 1 Introduction

C++ Programming Language Lecture 1 Introduction C++ Programming Language Lecture 1 Introduction By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department Introduction In this course you will learn C++ and the legacy C code. It is

More information

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages

More information

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

More information

Chapter 2: Overview of C. Problem Solving & Program Design in C

Chapter 2: Overview of C. Problem Solving & Program Design in C Chapter 2: Overview of C Problem Solving & Program Design in C Addison Wesley is an imprint of Why Learn C? Compact, fast, and powerful High-level Language Standard for program development (wide acceptance)

More information

DEPARTMENT OF MATHS, MJ COLLEGE

DEPARTMENT OF MATHS, MJ COLLEGE T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

2.5 Another Application: Adding Integers

2.5 Another Application: Adding Integers 2.5 Another Application: Adding Integers 47 Lines 9 10 represent only one statement. Java allows large statements to be split over many lines. We indent line 10 to indicate that it s a continuation of

More information

UEE1302 (1102) F10: Introduction to Computers and Programming

UEE1302 (1102) F10: Introduction to Computers and Programming Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1302 (1102) F10: Introduction to Computers and Programming Programming Lecture 00 Programming by Example Introduction to C++ Origins,

More information

Lab 2: Structured Program Development in C

Lab 2: Structured Program Development in C Lab 2: Structured Program Development in C (Part A: Your first C programs - integers, arithmetic, decision making, Part B: basic problem-solving techniques, formulating algorithms) Learning Objectives

More information