# Chapter 7. Additional Control Structures

Size: px
Start display at page:

Transcription

1 Chapter 7 Additional Control Structures 1

2 Chapter 7 Topics Switch Statement for Multi-Way Branching Do-While Statement for Looping For Statement for Looping Using break and continue Statements 2

3 Chapter 7 Topics Additional C++ Operators Operator Precedence Type Coercion in Arithmetic and Relational Precedence 3

4 Switch Statement The Switch statement is a selection control structure for multi-way branching switch (IntegralExpression) { case Constant1 : Statement(s); case Constant2 : }... Statement(s); default : Statement(s); // optional // optional // optional // optional 4

5 Example of Switch Statement float weightinpounds = 165.8; char weightunit;... // User enters letter for desired weightunit switch (weightunit) { case P : case p : << endl; break; case O : case o : cout << weightinpounds << pounds cout << 16.0 * weightinpounds << 5 ounces << endl;

6 Example of Switch Statement, continued break; case G : case g : cout << * weightinpounds << grams << endl; break; default : cout << That unit is not handled! << endl; break; } 6

7 Switch Statement The value of IntegralExpression (of char, short, int, long or enum type) determines which branch is executed Case labels are constant (possibly named) integral expressions Several case labels can precede a statement 7

8 Control in Switch Statement Control branches to the statement following the case label that matches the value of IntegralExpression Control proceeds through all remaining statements, including the default, unless redirected with break 8

9 Control in Switch Statement If no case label matches the value of IntegralExpression, control branches to the default label, if present Otherwise control passes to the statement following the entire switch statement Forgetting to use break can cause logical errors because after a branch is taken, control proceeds sequentially until either break or the end of the switch statement occurs 9

10 Do-While Statement Do-While is a looping control structure in which the loop condition is tested after each iteration of the loop SYNTAX do { Statement } while (Expression); Loop body statement can be a single statement or a block 10

11 Example of Do-While void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response has been input // && response == y or n { do { cin >> response; // Skips leading whitespace if ((response!= y ) && (response!= n )) 11

12 Do-While Loop vs. While Loop POST-TEST loop (exit-condition) The looping condition is tested after executing the loop body Loop body is always executed at least once PRE-TEST loop (entry-condition) The looping condition is tested before executing the loop body Loop body may not be executed at all 12

13 Do-While Loop DO Statement WHILE Expression FALSE TRUE When the expression is tested and found to be false, the loop is exited and control passes to the statement that follows the Do-while statement 13

14 For Loop SYNTAX for (initialization; test expression; update) { Zero or more statements to repeat } 14

15 For Loop For loop contains An initialization An expression to test for continuing An update to execute after each iteration of the body 15

16 Example of For Loop int num; for (num = 1; num <= 3; num++) { cout << num << Potato << endl; } 16

17 num? Example of Repetition int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl; OUTPUT 17

18 num 1 Example of Repetition int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl; OUTPUT 18

19 num 1 int num; Example of Repetition true for(num = 1; num <= 3; num++) cout << num << Potato << endl; OUTPUT 19

20 num 1 Example of Repetition int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl; 1Potato OUTPUT 20

21 num 2 Example of Repetition int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl; 1Potato OUTPUT 21

22 num 2 Example of Repetition int num; true for(num = 1; num <= 3; num++) cout << num << Potato << endl; 1Potato OUTPUT 22

23 2 Example of Repetition num int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl; OUTPUT 1Potato 2Potato 23

24 num 3 Example of Repetition int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl; 1Potato 2Potato OUTPUT 24

25 num 3 int num; Example of Repetition true for(num = 1; num <= 3; num++) cout << num << Potato << endl; 1Potato 2Potato OUTPUT 25

26 num 3 Example of Repetition int num; for(num = 1; num <= 3; num++) cout << num << Potato << endl; 1Potato 2Potato OUTPUT 3Potato 26

27 num 4 Example of Repetition int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl; 1Potato 2Potato OUTPUT 3Potato 27

28 num 4 int num; Example of Repetition false for(num = 1; num <= 3; num++) cout << num << Potato << endl; 1Potato 2Potato OUTPUT 3Potato 28

29 num 4 Example of Repetition int num; false for(num = 1; num <= 3; num++) cout << num << Potato << endl; When the loop control condition is evaluated and has value false, the loop is said to be satisfied and control passes to the statement following the For statement 29

30 Output The output was 1Potato 2Potato 3Potato 30

31 int count; Count-controlled Loop for (count = 4; count > 0; count--) { cout << count << endl; } cout << Done << endl; OUTPUT: Done 31

32 What is output? int count; for (count = 0; count < 10; count++) { cout << * ; } 32

33 Answer ********** The 10 asterisks are all on one line. Why? 33

34 What output from this loop? int count; for (count = 0; count < 10; count+ +); { } cout << * ; 34

35 Answer No output from the for loop! Why? The semicolon after the () means that the body statement is a null statement 35

36 Answer In general, the body of the For loop is whatever statement immediately follows the () That statement can be a single statement, a block, or a null statement Actually, the code outputs one * after the loop completes counting to 10 36

37 Several Statements in Body Block const int MONTHS = 12; int float count; bill; float sum = 0.0; for (count = 1; count <= MONTHS; count++) { } cout << Enter bill: ; cin >> bill; sum = sum + bill; cout << Your total bill is : << sum << endl; 37

38 Break Statement The Break statement can be used with Switch or any of the 3 looping structures It causes an immediate exit from the Switch, While, Do-While, or For statement in which it appears If the Break statement is inside nested structures, control exits only the innermost structure containing it 38

39 Guidelines for Choosing Looping Statement For a simple count-controlled loop, use the For statement For an event-controlled loop whose body always executes once, use of Do-While statement For an event-controlled loop about which nothing is known, use a While statement When in doubt, use a While statement 39

40 Continue Statement The Continue statement is valid only within loops It terminates the current loop iteration, but not the entire loop In a For or While, Continue causes the rest of the body of the statement to be skipped; in a For statement, the update is done In a Do-While, the exit condition is tested, and if true, the next loop iteration is begun 40

41 Problem Given a character, a length, and a width, draw a box For example, given the values &, 4, and 6, you would display &&&&&& &&&&&& &&&&&& &&&&&& 41

42 Additional C++ Operators Previously discussed C++ Operators include: the assignment operator (=) the arithmetic operators (+, -, *, /, %) relational operators (==,!=,,<=, >, >=) logical operators (!, &&, ) C++ has many specialized other operators seldom found in other programming languages 42

43 Additional C++ Operators See Table in 7.6 in Text for Additional C++ Operators for a full list of: Combined Assignment Operators Increment and Decrement Operators Bitwise Operators More Combined Assignment Operators Other Operators 43

44 Assignment Operators and Assignment Expressions (=) is the basic assignment operator Every assignment expression has a value and a side effect, the value that is stored into the object denoted by the left-hand side For example, delta = 2 * 12 has the value 24 and side effect of storing 24 into delta 44

45 Assignment Expressions In C ++, any expression become an expression statement when terminated by a semicolon The following are all valid C++ statements, first 2 have no effect at run time: 23; 2 * (alpha + beta); delta = 2 * 12; 45

46 Increment and Decrement Operators The increment and decrement operators (+ + and --) operate only on variables, not on constants or arbitrary expressions 1) Example of pre-incrementation int1 = 14; int2 = ++int1; // int1 == 15 && int2 == 15 2) Example of post-incrementation int1 = 14; int2 = int1++; // int1 == 15 && int2 == 14 46

47 Bitwise Operators Bitwise operators (e.g., <<, >>, and ) are used for manipulating individual bits within a memory cell << and >> are left and right shift operators, respectively that take bits within a memory cell and shift them to the left or the right Do not confuse relational && and operators used in logical expressions with & and bitwise operators 47

48 The Cast Operation Explicit type cast used to show that the type conversion is intentional In C++, the cast operation comes in three forms: intvar = int(floatvar); // Functional notation intvar = (int)floatvar; // Prefix notation intvar = static_cast<int>(floatvar); // Keyword notation 48

49 The Cast Operation Restriction on use of functional notation: Data type name must be a single identifier If type name consists of more than one identifier, prefix notation or keyword notation must be used Most software engineers now recommend use of keyword cast because it is easier to find these keywords in a large program 49

50 The sizeof Operator The sizeof operator --a unary operator that yields the size, in bytes, of its operand The operand can be a variable name, as in sizeof someint Alternatively, the operand can be the name of a data type enclosed in parentheses: (sizeof float) 50

51 The? Operator? : operator, also called the conditional operator is a three-operand operator Example of its use: set a variable m ax equal to the larger of two variables a and b. With the?:operator, you can use the following assignment statement: m ax = (a>b)? a :b; 51

52 Operator Precedence Following Table on slide 53 and slide 54 groups discussed operators by precedence levels for C++ Horizontal line separates each precedence level from the next-lower level Column level Associativity describes grouping order. Within a precedence level, operators group Left to right or, Right to left 52

53 Operator Associativity Remarks Function call and functionstyle cast () ++ Left to right -- Right to left ++and - as postfix operators ++ --! Unary +Unary (cast) sizeof Right to left Right to left * / % Left to right + - Left to right ++and - as prefix operators 53

54 Operator Associativity Remarks < <= > >= ==!= &&?: = += -= *= /= Left to right Left to right Left to right Left to right Right to left Right to left 54

55 Type Coercion in Arithmetic and Relational Expressions If two operands are of different types, one of them is temporarily promoted (or widened) to match the data type of the other Rule of type coercion in an arithmetic coercion: Step 1: Each char, short, bool, or enumeration value is promoted (widened) to int. If both operands are now int, the result is an int expression. 55

56 Type Coercion in Arithmetic and Relational Expressions Step 2: If Step 1 still leaves a mixed type expression, the following precedence of types is used: int, unsigned int, long, float, double,long double 56

57 Type Coercion in Arithmetic and Relational Expressions Example: expression som efloat+2 Step 1 leaves a mixed type expression In Step 2, int is a lower type than the float value---for example, 2.0 Then the addition takes place, and the type of the entire expression is float 57

58 Type Coercion in Arithmetic and Relational Expressions This description also holds for relational expressions such as som eint <= som efloat Value of som eint temporarily coerced to floatingpoint representation before the comparison occurs Only difference between arithmetic and relational expressions: Resulting type of relational expression is always bool---the value true or false 58

### Test Results Schedule Miscellanea Control Structs. Add l Oper s Break Hands on Q & A Conclusion References Files

CSC-201 - Computer Science I Lecture #5: Chapter 7 Dr. Chuck Cartledge September 21, 2016 at 9:10am 1/37 Table of contents I 1 Test Results 2 Schedule 3 Miscellanea 4 Control Structs. 5 Add l Oper s 6

### CHAPTER 3 Expressions, Functions, Output

CHAPTER 3 Expressions, Functions, Output More Data Types: Integral Number Types short, long, int (all represent integer values with no fractional part). Computer Representation of integer numbers - Number

### 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

### 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

### 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

### UNIT- 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

### Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

### 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

### 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

### C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

### Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

### c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object

### 1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. B. Outputs to the console a floating point number f1 in scientific format

### Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values.

Data Types 1 Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values. Base Data Types All the values of the type are ordered and atomic.

### C Programming Language (Chapter 2 of K&R) Variables and Constants

C Programming Language (Chapter 2 of K&R) Types, Operators and Expressions Variables and Constants Basic objects manipulated by programs Declare before use: type var1, var2, int x, y, _X, x11, buffer;

### Data Types and Variables in C language

Data Types and Variables in C language Disclaimer The slides are prepared from various sources. The purpose of the slides is for academic use only Operators in C C supports a rich set of operators. Operators

### Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships

### The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y

### The Arithmetic Operators

The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x

### 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

### 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

### C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

### Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

### 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

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

### 3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

Chapter 2: Problem Solving Using C++ TRUE/FALSE 1. Modular programs are easier to develop, correct, and modify than programs constructed in some other manner. ANS: T PTS: 1 REF: 45 2. One important requirement

### Chapter 3. Numeric Types, Expressions, and Output

Chapter 3 Numeric Types, Expressions, and Output 1 Chapter 3 Topics Constants of Type int and float Evaluating Arithmetic Expressions Implicit Type Coercion and Explicit Type Conversion Calling a Value-Returning

### 3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

3. EXPRESSIONS It is a sequence of operands and operators that reduce to a single value. Operator : It is a symbolic token that represents an action to be taken. Ex: * is an multiplication operator. Operand:

### Review of the C Programming Language

Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

### Assignment: 1. (Unit-1 Flowchart and Algorithm)

Assignment: 1 (Unit-1 Flowchart and Algorithm) 1. Explain: Flowchart with its symbols. 2. Explain: Types of flowchart with example. 3. Explain: Algorithm with example. 4. Draw a flowchart to find the area

### Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits

### Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions

### Reserved Words and Identifiers

1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

### Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

### 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

### 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

### 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

### 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

### Control Structures. Control Structures Conditional Statements COMPUTER PROGRAMMING. Electrical-Electronics Engineering Dept.

EEE-117 COMPUTER PROGRAMMING Control Structures Conditional Statements Today s s Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical

### Operators and Expressions:

Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

### CS2141 Software Development using C/C++ C++ Basics

CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

### Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

### Operators in java Operator operands.

Operators in java Operator in java is a symbol that is used to perform operations and the objects of operation are referred as operands. There are many types of operators in java such as unary operator,

### A flow chart is a graphical or symbolic representation of a process.

Q1. Define Algorithm with example? Answer:- A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of

### Internet & 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

CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

### CSCI 1061U Programming Workshop 2. C++ Basics

CSCI 1061U Programming Workshop 2 C++ Basics 1 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output

### Introduction to Programming EC-105. Lecture 2

Introduction to Programming EC-105 Lecture 2 Input and Output A data stream is a sequence of data - Typically in the form of characters or numbers An input stream is data for the program to use - Typically

### CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CprE 288 Introduction to Embedded Systems Exam 1 Review http://class.ece.iastate.edu/cpre288 1 Overview of Today s Lecture Announcements Exam 1 Review http://class.ece.iastate.edu/cpre288 2 Announcements

### 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

### Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

### C++ 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

### o 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

### 3. Java - Language Constructs I

Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

### CSI33 Data Structures

Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

### 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

### C++ Final Exam 2017/2018

1) All of the following are examples of integral data types EXCEPT. o A Double o B Char o C Short o D Int 2) After the execution of the following code, what will be the value of numb if the input value

### Increment and the While. Class 15

Increment and the While Class 15 Increment and Decrement Operators Increment and Decrement Increase or decrease a value by one, respectively. the most common operation in all of programming is to increment

### 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

### CSc 10200! Introduction to Computing. Lecture 4-5 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing Lecture 4-5 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 3 Assignment, Formatting, and Interactive Input

### .Net Technologies. Components of.net Framework

.Net Technologies Components of.net Framework There are many articles are available in the web on this topic; I just want to add one more article over the web by explaining Components of.net Framework.

### More Programming Constructs -- Introduction

More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and

### Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

### *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN

PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN

### Informatics Ingeniería en Electrónica y Automática Industrial

Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical

### Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the

### C++ 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

### Operators in C. Staff Incharge: S.Sasirekha

Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C

### Declaration and Memory

Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier

### The University of Alabama in Huntsville Electrical and Computer Engineering CPE Example of Objective Test Questions for Test 4

The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 02 Example of Objective Test Questions for Test 4 True or False Name: 1. The statement switch (n) case 8 : alpha++; case

### 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

### CHAPTER 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

### Chapter 3: Operators, Expressions and Type Conversion

101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

### Programming for Engineers Iteration

Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers

### LECTURE 3 C++ Basics Part 2

LECTURE 3 C++ Basics Part 2 OVERVIEW Operators Type Conversions OPERATORS Operators are special built-in symbols that have functionality, and work on operands. Operators are actually functions that use

### 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

### I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

I Internal Examination Sept. 2018 Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs. [I]Very short answer questions (Max 40 words). (5 * 2 = 10) 1. What is

### REPETITION 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

### Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

### Programming with C++ as a Second Language

Programming with C++ as a Second Language Week 2 Overview of C++ CSE/ICS 45C Patricia Lee, PhD Chapter 1 C++ Basics Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives Introduction to

### Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

Week 2: Console I/O and Operators Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.1) CS 1428 Fall 2014 Jill Seaman 1 2.14 Arithmetic Operators An operator is a symbol that tells the computer to perform specific

### Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires

### Java enum, casts, and others (Select portions of Chapters 4 & 5)

Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The

### Operators and Type Conversion. By Avani M. Sakhapara Assistant Professor, IT Dept, KJSCE

Operators and Type Conversion By Avani M. Sakhapara Assistant Professor, IT Dept, KJSCE Introduction An operator is a symbol which represents a particular operation that can be performed on some data.

### Fundamentals of Programming CS-110. Lecture 2

Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout

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

### Engineering Computing I

Engineering Computing I Types, Operators, and Expressions Types Operators Expressions 2 1 2.1 Variable Names Names are made up of letters and digits The first character must be a letter The underscore

### Chapter 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++

### A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object

### C++ 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

### Programming. 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++

### Chapter 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

### CSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow

CSE 452: Programming Languages Expressions and Control Flow Outline of Today s Lecture Expressions and Assignment Statements Arithmetic Expressions Overloaded Operators Type Conversions Relational and

### 5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.

Chapter 5: Looping 5.1 The Increment and Decrement Operators Copyright 2009 Pearson Education, Inc. Copyright Publishing as Pearson 2009 Addison-Wesley Pearson Education, Inc. Publishing as Pearson Addison-Wesley

### Type Conversion. and. Statements

and Statements Type conversion changing a value from one type to another Void Integral Floating Point Derived Boolean Character Integer Real Imaginary Complex no fractional part fractional part 2 tj Suppose

### Week 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.

Week 2 Branching & Looping Gaddis: Chapters 4 & 5 CS 5301 Spring 2018 Jill Seaman 1 Relational Operators l relational operators (result is bool): == Equal to (do not use =)!= Not equal to > Greater than

Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All for repetition statement do while repetition statement switch multiple-selection statement break statement continue statement Logical

### CS242 COMPUTER PROGRAMMING

CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing