Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3
|
|
- Nelson McBride
- 5 years ago
- Views:
Transcription
1 Programming - 1 Computer Science Department 011COMP-3 لغة البرمجة عال- 3 لطالب كلية الحاسب اآللي ونظم المعلومات 1
2 1.1 Machine Language A computer programming language which has binary instructions those are executed directly by a computer. Machine Language programming was very slow and difficult to understand for most of the programmers. 2
3 1.2 Assembly Language Assembly language is a low level programming language which implements a symbolic representation of the machine codes. Assembly language is converted into executable machine code by a utility program called assembler. 3
4 1.3 High level Language A machine independent programming language which contains English words and commonly used mathematical notations. Programs written in a high-level language must be translated into machine language by a compiler. Compiler is a software that translates a program written in a high-level programming language (C/C++, COBOL, etc.) into machine language. Examples: C++, Java and FORTRAN etc 4
5 1.4 History of C and C++ C++ was developed by Bjarne Stroustrup in the early 1980s at Bell Labs. C++ is an extension of C programming language and provides capabilities for Object-Oriented Programming (OOP). 5
6 1.5 Introduction to Programming Preprocessor directives : #include<iostream> main() Function 1. Body of the function 2. Other statements 3. Return statement Comments: //, /*. */ 6
7 1.5.1 Preprocessor Directives Preprocessor directives Processed by preprocessor before compiling Begin with #(hash) Example: #include <iostream> /*Tells preprocessor to include the input/output stream header file <iostream> */ White spaces Blank lines, space characters and tabs Delimiter, used to make programs easier to read Extra spaces are ignored by the compiler 7
8 1.5.2 main() Function A part of every C++ program Only one function in a program must be main() Keyword : A word in code that is reserved by C++ for a specific use. Ex: int, char, if, else, for, while, break, return, namespace etc Header of main() function : int/void main( ) Body of main() is delimited by braces { } 8
9 1.5.3 Comments Explain programs to other programmers. Improve program readability Ignored by compiler Types of comment: Single-line comment Begin with // Example: int main() Multi-line comment Start with /* //this is main() function End with */ 9
10 1.5.4 Statements Instruct the program to perform an action. Every statement must end with a semicolon (;) Examples : int x; cin>>x; cout << Welcome to C++ ; return 0; 10
11 1.5.5 Variable & Data types Variable: Location in memory where value can be stored ex. int x, float y etc Fundamental data types: int integer numbers : 1, 2, 4,. char characters : a, c, float, double floating point numbers: 2.5, 4.96 The value of a variable could be changed while the program is running. 11
12 1.5.6 Input statement cin >> x; cin /std::cin // x is a variable Standard input stream object. Defined in input/output stream header file <iostream> We are using a name (cin/cout) that belongs to namespace std. Stream extraction operator >> Value from left (operand) inserted into right operand (variable). 12
13 1.5.7 Output statement cout << Welcome to C++ ; cout /std::cout Standard output stream object. Defined in input/output stream header file <iostream> We are using a name (cout/cin) that belongs to namespace std. Stream insertion operator << Value to right (right operand) inserted into left operand. The string of characters contained between after the operator << shows on computer screen. 13
14 1.5.8 return Statement Terminates the execution of a function and returns control to the calling function. used at the end of function The value 0 indicates the program terminated successfully. Example return 0; / return(0); 14
15 2.1 First program in C++ #include<iostream> #include<conio.h> using namespace std; int main( ) { cout<< Welcome to C++\n ; getch (); } return 0; 15
16 2.2 Escape Sequence Escape character: backslash : "\" Escape sequence: A character preceded by backslash (\) Examples : "\n : Newline. Cursor moves to beginning of next line on the screen \t : Horizontal tab. Move the screen cursor to the next tab stop. \b : Backspace. Move the screen cursor one space back etc 16
17 2.2.1 Modifying First C++ Program Print text on one line using multiple statements. Each stream insertion (<<) resumes printing where the previous one stopped. Example statements: cout << Welcome ; cout << to C++\n ; 17
18 2.2.2 Modifying First C++ Program Print text on several lines using a single statement. Each newline escape sequence positions the cursor to the beginning of the next line. Two newline characters back to back outputs a blank line. Example statement : cout << Welcome\n to\n\nc++\n ; 18
19 2.3 Adding Integers #include<iostream> #include<conio.h> void main( ) { } int a, b, sum; cout<< Enter value of a : ; cin>>a; cout>> Enter value of b : ; cin>>b; sum = a + b; cout<< Value of a and b : <<sum; getch (); 19
20 3.1 Memory Concepts A variable is a memory location in C++ Programming language Every variable has name, type, size and value. A name like number1, number2 and sum that refer to a value is called variable. Example: sum = number1 + number2; Value of sum is overwritten Values of number1 and number2 remain intact 20
21 3.1.1 Example Memory locations after storing values for number1 and number2. 21
22 3.1.2 Continued Memory locations after calculating and storing the sum of number1 and number2. 22
23 3.2 Arithmetic Arithmetic operators are the binary operators that takes two input to perform calculation. Examples: Addition (+) Subtraction (-) Multiplication (*) Division (/) Modulus(%) 23
24 3.2.1 Arithmetic operators C++ operation C++ arithmetic operator Algebraic expression Addition + f + 7 f + 7 Subtraction - p c p - c Multiplication * bm or b m b * m Division / x / y or x y or x y x / y C++ expression Modulus % r mod s r % s 24
25 Example Division (/) / : Integer division truncates remainder 7 / 5 evaluates to 1 Modulus(%) % : Modulus operator returns remainder 7 % 5 evaluates to 2 25
26 3.3 Rules of operator precedence 1) Operators in parentheses evaluated first 2) Multiplication, division, modulus applied next 3) Addition, subtraction applied last 26
27 3.3.1 Precedence of Arithmetic Operators 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 Modulus 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. 27
28 3.4 Decision making : Relational and Equality Operators Relational Operator C++ operator Sample C++ condition Meaning of C++ condition Relational Operator ( 4 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 Equality Operator ( 2 operators) == X == y X is equal to y!= X!= y X is not equal to y 28
29 Example: comparing integer using if statement, relational operator and equality operator void main() { int x,y; cout<< enter two numbers ; cin>>x>>y; if(x==y) cout<<x<< is equal to <<y; if(x!=y) cout<<x<< is not equal to <<y; if(x<y) if(x>y) cout<<x<< is smaller than <<y; cout<<x<< is greater than <<y; } 29
30 4.1 Control Statement: Introduction Program control specify the order in which statements execute in a program. C++ provides many building blocks to specify the order of execution. Some of them are : 1. If Statement 2. if else Statement 3. while Statement 30
31 4.2 Algorithm A procedure for solving a problem in terms of 1. The action to execute 2. The order in which the actions execute is called an algorithm. 31
32 4.3 Pseudo code Pseudo code is an artificial and informal language that helps us to implement algorithms without having to worry about the strict details of C++ language syntax. Pseudo code does not execute on computer. 32
33 4.3.1 Pseudo code example Example: Sum of two numbers. 1 Prompt the user to enter the first integer 2 Input the first integer 3 Prompt the user to enter the second integer 4 Input the second integer 5 Add first integer and second integer, store result 6 Display result 33
34 5.1 Control Structure Statements used to control the flow of execution in a program. There are three control structures: 1. Sequence Structure 2. Selection Structure 3. Repetition Structure 34
35 5.1.1 Sequence Structure In Sequence Structure, the execution of C++ statements is done one after another in an order in which they are written. 35
36 5.1.2 Selection Structure Selection Structure selects which statement will execute on the basis of given conditions. C++ provides three types of selection structures: 1. if( ) 2. if else( ) 3. switch( ) 36
37 Selection Structure a) if() : if() selection statement either performs an action if a condition is true or skips the action if the condition is false. Example: if(grade>=60) cout << passed ; 37
38 Selection Structure b) if else() : If else() selection statement performs an action if a condition is true or performs a different action if the condition is false. Example: if(grade>=60) cout << passed ; else cout << fail ; 38
39 Nested if...else Statements Nested if else statement test for multiple cases by placing if...else selection statements inside other if...else selection statements. 39
40 Nested if...else example Example: if ( studentgrade >= 90 ) cout << "A"; else if ( studentgrade >= 80 ) cout << "B"; else if ( studentgrade >= 70 ) cout << "C"; else if ( studentgrade >= 60 ) cout << "D"; else cout << "F"; 40
41 Selection Structure c) switch() : switch() selection statement performs one of the many different actions, depending on the value of an integer expression. 41
42 Conditional Operator? : The conditional operator is ternary operator it takes three operands. The operands, together with the conditional operator, form a conditional expression. 1. The first operand is a condition, 2. The second operand is the value for the entire conditional expression if the condition is true 3. The third operand is the value if the condition is false. Example: cout << ( grade >= 60? "Passed" : "Failed" ); 42
43 Block A group of statements enclosed within a pair of braces { } is called a Block. for example: { } statement1; statement2; statement3; 43
44 5.1.3 Repetition Structure Looping statements that enable programs to perform statements repeatedly as long as a condition remains true. C++ provides three types of repetition statements : 1. while() 2. for() 3. do while() 44
45 6.1 while () Repetition Statement A repetition statement allows the programmer to specify that a program should repeat an action while some condition remains true. 45
46 6.1.1 Example void main() { int product = 3; while ( product <= 100) product = 3 * product; } 46
47 6.2 Formulating Algorithms: Counter-Controlled Repetition Counter-controlled repetition is often called definite repetition because the number of repetitions is known before the loop begins executing. 47
48 6.2.1 Example #include <iostream> #include <conio.h> using namespace std; int main() { int counter = 1; while ( counter <= 10 ) { cout << counter << endl; counter++; } } getch(); return 0; 48
49 6.3 Formulating Algorithms: Sentinel-Controlled Repetition Sentinel-controlled repetition is often called indefinite repetition because the number of repetitions is not known before the loop begins executing. 49
50 6.3.1 Example #include <iostream> using namespace std; void main() { int score, sum; sum = 0; cout << "Enter score (-1 to quit): "; cin >> score; while (score!= -1) { sum += score; cout << "Enter score (-1 to quit): "; cin >> score; } cout << "Sum = " << sum << endl; } 50
51 7.1 Nested Control Statement The only other structured way control statements can be connected, namely, by nesting one control statement within another. A control command placed inside another control command is said to be nested. 51
52 7.1.1 Example #include<iostream> using namespace std; void main() { int passes = 0, failures=0, studentcounter = 1, ; int result; // one exam result (1 = pass, 2 = fail) while ( studentcounter <= 10 ) { cout << "Enter result (1 = pass, 2 = fail): "; cin >> result; if ( result == 1 ) //if else nested in while passes = passes + 1; else failures = failures + 1; studentcounter = studentcounter + 1; } } 52
53 7.2 Assignment Operators C++ provides several assignment operators for abbreviating assignment expressions. = is an assignment operator, which assigns the value of its right operand to its left operand. Example: c=c+3; c+=3; [Variable = variable operator expression] [Variable operator= expression] 53
54 7.2.1 Assignment Operators Assignment operator Sample expression Explanation += c += 7 c = c + 7 -= d -= 4 d = d -4 *= e *=5 e = e * 5 /= f /= 3 f = f / 3 %= g %= 9 g = g % 9 54
55 7.3 Increment and decrement operators C++ provides two unary operators for adding 1 to or subtracting 1 from the value of a numeric variable. Example: Unary increment operator Unary decrement operator 55
56 7.3.1 Increment and decrement operators Operator Called Sample expression Explanation ++ Preincrement ++a Increment a by 1, then use new value of a in the expression in which a resides. ++ Postincrement a++ Use the current value of a in the expression in which a resides, then increment a by Predecrement --b Decrement b by 1, then use new value of b in the expression in which b resides. -- Postdecrement b-- Use the current value of b in the expression in which b resides, then decrement b by 1. 56
57 8.1 Essentials of Counter- Controlled Repetition Counter-controlled repetition requires: 1. The name of a control variable (or loop counter) 2. The initial value of the control variable 3. The loop-continuation condition that tests for the final value of the control variable. 4. The increment (or decrement) by which the control variable is modified each time through the loop. 57
58 8.1 Example #include <iostream> void main() { int counter=1; while ( counter<=10) { cout << counter << " "; counter ++; } } Output of the above Example:
59 8.2 for() Repetition Statement for( ; ; ) repetition statement specifies the counter-controlled repetition details in a single line of code: for statement header components 59
60 8.2.1 Example #include <iostream> using namespace std; int main( ) { for (int counter=1; counter<=10; counter++) cout<<counter<<" "; return 0; } Output of the above Example:
61 8.3 Examples using the for statement Vary the control variable from 1 to 10 in increments of 1. for ( int i = 1; i <= 10; i++ ) Vary the control variable from 10 down to 1 in increments of -1 (that is, decrements of 1). for ( int i = 10; i >= 1; i-- ) Vary the control variable from 7 to 77 in steps of 7. for ( int i = 7; i <= 77; i += 7 ) Vary the control variable from 20 down to 2 in steps of -2. for ( int i = 20; i >= 2; i -= 2 ) 61
62 9.1 do...while() Repetition Statement The do...while() repetition statement is similar to the while statement. The do...while() statement tests the loopcontinuation condition after the loop body executes; therefore, the loop body always executes at least once. 62
63 9.2 Example #include <iostream> using namespace std; int main() { int counter=1; do { cout<<counter<< ; counter++; } while (counter<=10); return 0; } 63
64 9.3 Switch Multiple- Selection Statement C++ provides the switch multiple-selection statement to perform many different actions based on the possible values of a variable or expression. Example: switch(day) { } case 1: cout<< Saturday ; break; 64
65 9.3.1 Example #include <iostream> void main() { int day; cout<< enter the day ; cin>>day; switch(day) { case 1: cout<< Sunday ; break; 65
66 9.3.1 Example continued case 2: cout<< Monday ; break; case 3: cout<< Tuesday ; break; case 4: cout<< Wednesday ; break; default: cout<< incorrect entry ; break; } } 66
67 10.1 Break statement The break statement, when executed in a while, for, do while, or switch control statement, causes immediate exit from that control statement. 67
68 Example for (count=1; count<=10; count++) { if(count == 5) break; //break loop if x is 5 cout<<count<< ; } cout<< \n Broke out of the loop of count = <<count; 68
69 10.2 Continue statement The continue statement, when executed in a while, for or do while statement, skips the remaining statements in the body of that statement and proceeds with the next iteration of the loop. 69
70 Example for (count=1; count<=10; count++) { if(count == 5) continue; //Skips remaining code on loop cout<<count<< ; } 70
71 10.3 Logical operators C++ provides logical operators that are used to form more complex condition by combining simple conditions. The logical operators are: 1. && Logical AND 2. Logical OR 3.! Logical NOT 71
72 Logical AND(&&) operator Logical AND(&&) operator is used when we wish to ensure that two conditions are both true before we choose a certain path of execution. Example: if(gender== F && age>=65) seniorfemales++; 72
73 Logical AND(&&) operator Expression 1 Expression 2 Expression 1 && Expression 2 False False False False True False True False False True True True 73
74 Logical OR ( ) operator Logical OR ( ) operator is used when we wish to ensure at some point in a program that either or both of two conditions are true before we choose a certain path of execution. Example: if((semesteraverage>=90) (finalexam>=90)) cout<< Student grade is A ; 74
75 Logical OR ( ) operator Expression 1 Expression 2 Expression 1 && Expression 2 False False False False True True True False True True True True 75
76 logical negation (!) operator C++ provides the! (logical NOT) operator to enable a programmer to reverse the meaning of a condition. Unlike the && and binary operators, which combine two conditions, the unary logical negation operator has only a single condition as an operand. Ex. if(!(grade<= 59)) cout<< You have passed the examination ; Expression False True! Expression True Fasle 76
77 10.4 Confusing the Equality (==) and Assignment (=) operators Example: if( paycode == 4) cout<< You get a bonus ; but accidentally wrote if(paycode = 4) count<< You get a bonus ; 77
78 11.1 Derived Data Types Data types that are derived from fundamental data types are known as derived data types. Derived data types don't create a new data type; instead, they add some functionality to the basic data types. Ex. Two derived data type are - Array & Pointer. 78
79 11.2 Array An array is a sequenced collection of elements of the same data type, placed in contiguous memory locations that are referred to by the same name. Each element of an array can be accessed by a subscript value which indicates the position of an element in an array. 79
80 Array declaration An array can be declared as: int num[ ] = {2,8,7,6,0}; Array size(length) = UB LB + 1 We need an array to store large number of variables of same type under a single variable. Ex. To store Marks of 50 students 80
81 Example #include<iostream> #include<conio.h> using namespace std; int A [ ] = {16, 2, 77, 40, 120}; int n, result=0; void main () { for ( n=0 ; n<5 ; n++ ) { result += A[n]; } cout << result; getch(); } 81
82 12.1 Function A function is a collection of statements which contains data definitions and code that performs a specific task - a single, well-defined task. Advantage using function: This makes programs easier to read and maintain. Statements in function bodies are written only once Reused from perhaps several locations in a program Hidden from other functions Avoid repeating code 82
83 12.2 Function Prototype Function prototype also called function declaration The general form of a function prototype is: data-type function_name (type 1 arg 1, type 2 arg 2); Where, data-type represents the data-type of the item that is returned by the function, function_name represents the function name, and type 1, type 2,, type n represents the data-type of the arguments arg 1, arg 2,, arg n. Example: int addtwonumbers(int, float); 83
84 12.3 Function definition Definition of a function: Header : Return type, Function Name, Parameter(s) [type and name pair ]. Body : a collection of statements. Example: int addtwonumbers (int numberone, float numbertwo ) { int sum; sum = numberone + numbertwo; return sum; } 84
85 12.4 Return Type The return type is the data type of the result returned to the caller function. Example: int addtwonumbers (int numberone, float numbertwo ) { int sum; sum = numberone + numbertwo; return sum; } 85
86 12.5 Function Call There are two main ways for calling a function: 1. Call by value 2. Call by reference 86
87 Example #include<iostream> int square(int y) { int p; p=y*y; return p; } void main() { int i; i=10; cout<<square(i); } 87
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 informationIntroduction 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 informationChapter 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 informationIntroduction 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 informationIntroduction 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 informationC: 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 informationChapter 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 informationIn this chapter you will learn:
1 In this chapter you will learn: Essentials of counter-controlled repetition. Use for, while and do while to execute statements in program repeatedly. Use nested control statements in your program. 2
More informationExamination for the Second Term - Academic Year H Mid-Term. Name of student: ID: Sr. No.
Kingdom of Saudi Arabia Ministry of Higher Education Course Code: ` 011-COMP Course Name: Programming language-1 Deanship of Preparatory Year Jazan University Total Marks: 20 Duration: 60 min Group: Examination
More informationArithmetic 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 informationLecture 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 informationObjectives. 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 informationChapter 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 informationChapter 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 informationCHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++
CHAPTER 9 C++ 1. WRITE ABOUT THE BINARY OPERATORS USED IN C++? ARITHMETIC OPERATORS: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,
More informationBITG 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 informationIntroduction 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 informationBy the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program
1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize
More informationIntroduction 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 informationChapter 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 informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1
NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.
More informationChapter 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 informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationChapter 2 - Control Structures
Chapter 2 - Control Structures 1 2.11 Assignment Operators 2.12 Increment and Decrement Operators 2.13 Essentials of Counter-Controlled Repetition 2.1 for Repetition Structure 2.15 Examples Using the for
More informationCS 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 information6.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 informationControl 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 informationProgramming 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 informationCSc 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 informationCHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING. Dr. Shady Yehia Elmashad
CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING Dr. Shady Yehia Elmashad Outline 1. Introduction to C++ Programming 2. Comment 3. Variables and Constants 4. Basic C++ Data Types 5. Simple Program: Printing
More informationObjectives. 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 informationChapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.
Chapter 2 C++ Basics 1 Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-3 2.1 Variables and Assignments 2
More informationo Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement
Last Time Let s all Repeat Together 10/3/05 CS150 Introduction to Computer Science 1 1 We covered o Counter and sentinel controlled loops o Formatting output Today we will o Type casting o Top-down, stepwise
More informationComputer Programming : C++
The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program
More informationUnit 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 informationc) 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 informationAdd Subtract Multiply Divide
ARITHMETIC OPERATORS if AND if/else AND while LOOP Order of Operation (Precedence Part 1) Copyright 2014 Dan McElroy Add Subtract Multiply Divide + Add - Subtract * Multiply / Divide = gives the quotient
More informationChapter 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 informationCreating a C++ Program
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an
More information2.11 Assignment Operators. Assignment expression abbreviations c = c + 3; can be abbreviated as c += 3; using the addition assignment operator
2.11 Assignment Operators 1 Assignment expression abbreviations c = c + 3; can be abbreviated as c += 3; using the addition assignment operator Statements of the form variable = variable operator expression;
More informationFull 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 informationIntroduction 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 informationdownload instant at Introduction to C++
Introduction to C++ 2 Programming, Input/Output and Operators What s in a name? that which we call a rose By any other name would smell as sweet. William Shakespeare High thoughts must have high language.
More informationChapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.
Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style 3 2.1 Variables and Assignments Variables and
More informationChapter 2. C++ Basics
Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-2 2.1 Variables and Assignments Variables
More informationC++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay
C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming
More informationC++ PROGRAMMING SKILLS Part 2 Programming Structures
C++ PROGRAMMING SKILLS Part 2 Programming Structures If structure While structure Do While structure Comments, Increment & Decrement operators For statement Break & Continue statements Switch structure
More informationChapter 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 information2.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 informationFundamentals of Programming Session 9
Fundamentals of Programming Session 9 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection) Control Structures A computer can proceed: In sequence Selectively (branch) - making
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationIntroduction 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 informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationJava 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 informationREPETITION CONTROL STRUCTURE LOGO
CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of
More informationPART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.
Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name
More informationUniversità 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 informationChapter 2: Overview of C++
Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using C++ 6e by Frank L. Friedman and Elliot B. Koffman C++ Background Introduced by Bjarne Stroustrup of AT&T s Bell Laboratories in
More informationFundamentals 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 informationIntroduction to Programming using C++
Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know
More informationObjectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators
Objectives Chapter 4: Control Structures I (Selection) In this chapter, you will: Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)
More informationInformation Science 1
Topics covered Information Science 1 Terms and concepts from Week 8 Simple calculations Documenting programs Simple Calcula,ons Expressions Arithmetic operators and arithmetic operator precedence Mixed-type
More informationScientific Computing
Scientific Computing Martin Lotz School of Mathematics The University of Manchester Lecture 1, September 22, 2014 Outline Course Overview Programming Basics The C++ Programming Language Outline Course
More informationChapter 2: Introduction to C++
Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++
More informationChapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley
More informationMultiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationChapter 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 informationA First Program - Greeting.cpp
C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout
More informationIT 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 informationIn 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 informationChapter 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 informationChapter 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 informationChapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.
Chapter 4: Control Structures I (Selection) In this chapter, you will: Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)
More informationProgramming. C++ Basics
Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++
More information2/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 informationCourse 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 informationInformation 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 informationChapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments
Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Copyright 2011 Pearson Addison-Wesley. All rights
More informationIntroduction of C++ OOP forces us to think in terms of object and the interaction between objects.
Introduction of C++ Object Oriented Programming :- An Object Oriented Programming (OOP) is a modular approach which allows the data to be applied within the stipulated area. It also provides reusability
More informationC++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.
EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic
More informationJavaScript: 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 informationStructured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:
Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language Dr. Amal Khalifa Lecture Contents: Introduction to C++ Origins Object-Oriented Programming, Terms Libraries and Namespaces
More information2 nd Week Lecture Notes
2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous
More informationStructured 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 informationChapter 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 informationChapter 4 C Program Control
Chapter C Program Control 1 Introduction 2 he Essentials of Repetition 3 Counter-Controlled Repetition he for Repetition Statement 5 he for Statement: Notes and Observations 6 Examples Using the for Statement
More information12/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 informationLab # 02. Basic Elements of C++ _ Part1
Lab # 02 Basic Elements of C++ _ Part1 Lab Objectives: After performing this lab, the students should be able to: Become familiar with the basic components of a C++ program, including functions, special
More informationAnother Simple Program: Adding Two Integers
Another Simple Program: Adding Two Integers Another Simple Program: Adding Two Integers This program uses the input stream object std::cin and the stream extrac>, to obtain two integers
More informationStructured 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 informationEngineering Problem Solving with C++, Etter/Ingber
Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input
More informationInternet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e Sequential execution Execute statements in the order they appear in the code Transfer of control Changing the order in which statements execute All scripts
More informationFundamental 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 informationIS 0020 Program Design and Software Tools
1 Course Information 2 IS 0020 Program Design and Software Tools Introduction to C++ Programming Lecture 1 May 10, 2004 Lecture: James B D Joshi Mondays: 6:00-8.50 PM One (two) 15 (10) minutes break(s)
More informationCHAPTER 3 BASIC INSTRUCTION OF C++
CHAPTER 3 BASIC INSTRUCTION OF C++ MOHD HATTA BIN HJ MOHAMED ALI Computer programming (BFC 20802) Subtopics 2 Parts of a C++ Program Classes and Objects The #include Directive Variables and Literals Identifiers
More informationJava provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:
JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
More informationC++ Programming Lecture 7 Control Structure I (Repetition) Part I
C++ Programming Lecture 7 Control Structure I (Repetition) Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department while Repetition Structure I Repetition structure Programmer
More informationUNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING
( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types
More information