Department of Computer and Mathematical Sciences

Size: px
Start display at page:

Download "Department of Computer and Mathematical Sciences"

Transcription

1 _ Unit 2: Programming in C++, pages 1 of 8 Department of Computer and Mathematical Sciences CS 1410 Intro to Computer Science with C++ 8 Lab 8: While Loops Objectives: The objective of this lab is to help understand the various categories of WHILE-LOOPS available in C++. One aspect of programming that quickly becom es apparent to the beginner is the need to repeatedly execute the same set of instructions in a program, for a fixed number of times or even an indefinite num ber of tim es. For exam ple, we may wish to allow the user of a program to repeat the sam e task as m any times as he or sh e desires. Recall the operating system program FORMAT that we us ed in the f irst lab to f ormat a d isk. After formatting a disk, ea ch time the program asks the user if he or she wants to form at another disk. If the user answers "yes", th en the program executes the sam e set of instructions to form at the next disk. Or suppose we are faced with the problem of writing a program to process large quantities of information. Consider, for instance, a program that m ust generate th e payroll ch ecks for all em ployees in a larg e company. This program must repeatedly process th e same type of infor mation in the sam e way, namely, the pay rate, hours worked, etc. for each employee. To solve this problem efficiently, the same set of instructions m ust be ex ecuted fo r each em ployee RECORD (a record is a sm all collection of related data values). A mechanism in a programming language that allows the same set of instructions to execute multiple times is called a LOOP. C++ has many types of statements that im plement loop s, b ut the m ost basic and powerf ul of these sta tements is th e WHILE- LOOP. The syntax for a WHILE-LOOP is as follows: while (boolean expression) one statement; The reserved word in this sta tement is "whi le". When a WHILE-LOOP executes, the Boolean expression within the parentheses is evalua ted. This expression is called the LOOP CONDITION. If it is TRUE, the statem ent w ithin th e lo op executes. Otherwise, execution proceeds to the nex t statem ent in the program. Note that this is qu ite sim ilar to a n IF-ELSE statement. The big dif ference is this: After th e statem ent within the loop executes, then the Boolean expression is evaluated again. If it is TRUE, the stat ement within the loop executes another time, then the Boolean expression is evaluated again, and so forth. Therefore this looping process continues until the Boolean expression finally evalua tes as FALSE. Usually, it is necessary to include more than one statement in the body of a loop. This can be done by using a compound statement, called the LOOP BODY, as shown below: while ( loop condition ) list of statements } Therefore, the entire lis t of statem ents within the body of th is loop will execute over and over again, until the loop condition becomes FALSE.

2 Unit 2: Programming in C++, pages 2 of 8 Task 1: WHILE-LOOP statements The purpose of this task is to illust rate SENTINEL-CONTRO LLED, FLAG-CONTROLLED, and COUNT-CONTROLLED while-loops. In practice, when loops are used in program s, the following genera l pattern of st atements often appears: Statements to initialize loop process Statements to initialize loop condition while ( loop condition ) Statements to perform loop process Statements to update loop condition } The LOOP PROCESS is the key set of steps or instructions that the WHILE-LOOP is designed to repeat. Of course, the statements necessary to carry out th is process will be contained within the body of the loop. Many tim es, it is necessary to place certain statem ents before the loop to prepare or initialize this proces s. Likewise, s tatements are usua lly needed before the loop to initialize the loop condition to TR UE. If the loop condition is not initialized to TRUE before the WHILE-LOOP is encountered, the statem ents within the body of the loop m ay never execute even one time. At the same time, statements must be placed within the body of the loop to update the loop co ndition. If the loop con dition is in itially TRUE and is nev er updated, then it will remain TRUE and the loop will continue executing i ndefinitely - it will never term inate. This is called an ENDLESS or INFINITE LOOP. The sty le of the loop condition can be us ed to categorize WHILE-LOOPs. There are sev eral categories of loops, including F LAG-CONTROLLED, SENTINEL- CONTROLLED, and COUNT-CONTROLLED loops. A SENTINEL-C ONTROLLED loop continues executing u ntil a special data value is input that signals all inform ation ha s been processed and it' s tim e to terminate ( this spec ial data va lue is ca lled a SENTINEL). On the other hand, a FLAG- CONTROLLED loop is controlled by a special Boolean variable called a FLAG, which i s initialized to TRUE before the loop begins executing. This type of loop continues executing until something happens within the loop body that causes the flag variable to become FALSE. A very common type of loop is a COUNT- COUNTROLLED loop. For this type of loop, the loop body executes a fixed number of times. Usually in a count-controlled loop, an integer variable called a COUNTER is used to keep track of how many times the loop body has executed. When the value stored in the counter reaches the fixed number of times the loop is supposed to execute, then the loop terminates. Statement of the Problem: Create a C++ program called HiLo that will create a guessing game. The program will generate a rando m number between 1 and 100 for the user to gu ess. Then ask the use r f or a num ber as a guess ing num ber. The program will de termine the us er s guessing number as follows: If the guessing num ber is equal to the ra ndom number, output th e m essage tha t th e guessing number is correct and quit the game. If the guessing number is less than the random number, output a message Too low., and ask if the user want to continue. If yes, ask the user for another guess. If the guessing num ber is greater than the random number, output a m essage Too high., and ask if the user want to continue. If yes, ask the user for another guess. Output a goodbye message.

3 Lab 8: While Loops, page 3 of 8 After analyzing the above given problem designed as follows: 1. Generate a random number. 2. Prompt the user for a guess number. 3. Determine if the guessing number is a. Equal t o t he random number: I f it is, output a m essage that says the guessing i s correct and quit the game. b. Less than the random number: If it is, i. Output a m essage T oo low, ii. Ask i f the user wa nts to continue t he game. If y es, ask f or an other g uess number; ot herwise q uit t he game. c. Greater tha n t he random number: If it is, i. Output a m essage T oo high, ii. Ask i f the user wa nts to continue t he game. If y es, ask f or an other g uess number; ot herwise q uit t he game. 4. Output a goodbye message., the steps and the chart of the algorithm can be Declare necessary variables: Taget, Guess, Response, NotDone Generate a random number call Target Begin Start Setup a while loop to determine if user want to continue Prompt the user for a guessing number Determine if Guess = Target Determine if Guess < Target the Loop Output message -- the guess is correct Set value to indicate it is done Output message -- the guess is too low Output message -- the guess is too high Determine if the game is done Prompt the user whether to continue Output message goodbye Activity 1.1: Each step of the above algorithm and the programming flowchart can be converted to C++ code as follows. 1. Generate a random number. /*****These statements generate a random integer from 0 to 100*****/ srand ( time(null) ); Target = rand()%100+1; Don t forget to declare the variables that being used. /******************************************************************/ 2. Prompt the user for an input as a guessing number. cout<<"i am thinking of an integer from 1 to 100."<<endl; cout<<"can you guess it?"<<endl; Response = 'y'; notdone = true; This variable is used to terminate the game when the guess is correct. End

4 Unit 2: Programming in C++, pages 4 of 8 while ( Response == 'y' ) cout<<"make a guess-->"; cin>>guess; 3. Determine if the guessing number is a. Equal to the random number: If it is, out put a m essage that says the guessing is correct and quit the game. if (Guess == Number) cout<<"lucky guess! Did you cheat?"<<endl; notdone = false; } b. Less than the random number: If it is, i. Output a message Too low, ii. Ask if the user wants to continue the gam e. If yes, ask for another guessing number; otherwise quit the game. c. Greater than the random number: If it is, i. Output a message Too high, ii. Ask if the user wants to continue the gam e. If yes, ask for another guessing number; otherwise quit the game. else if (Guess > Number) cout<<"too high!"<<endl; else cout<<"too low!"<<endl; if (notdone) //notdone == true cout<<"do you want to guess again?(y/n)-->"; cin>>response; This code is to ask if the user wants to continue the game. } else Response = 'n'; } // while Response Output a goodbye message. cout<<"******good BYE******"; Activity 1.2: Start MS Visual Stud io and create a ne w C++ project or use the previous project and add a new cpp file called HiLo to the project. Then add the code in Activity 1.1 to complete the program. Then run the program. Activity 1.3: The while-loop contained in the program HiLo f alls in to two of the dif ferent categories o f while-loo ps. One is easy to see and the other is m ore subtle. Sta te the two categories and explain why these two cat egories app ly. Then use the constan t MaxTries initialize it to be 4 and the variab le Tries to modify the program so the user is lim ited to at most four guesses. ( HINT: Modify the while-loop condition. ) Run the program to check for correctness. After this modification, the while-l oop in the program will also fall into what category?

5 Lab 8: While Loops, page 5 of 8 Original categories: Additional category: Activity 1.4: Modify the program in Activity 1.3 so that the user is limited to at most 7 guesses. Run and test the modified program. Task 2: While-Loop The purpose of this task is to illustrate a possible problem with while-loops. As mentioned in the previous task, it is possible to design a loop that is INFINITE, that is to say, it will never term inate and continues endlessly executing the loop body. This happens when the loop condition is written in such a way that it ne ver evaluates as FALSE. Believe it or not, creating an infinite loop is a surprisingly easy m istake to m ake. W hat type of error is this - syntax or semantics? Activity 2.1: Study the following program carefully. #include <iostream> #include <iomanip> using namespace std; //Program name: TaskTwo int main(void) int I=5; while ((I < 10) && (I > -10)) if (I == -3) cout<<"p\n"; I = I + 8; if (I == -2) cout<<'?'; I = I + 7; if (I == -1) cout<<'x'; I = I - 3; if (I == 0) cout<<'o'; I = I + 2; if (I == 1) cout<<'d'; I = I * 2; if (I == 2) cout<<'o'; I = I - 5; if (I == 3) cout<<'!'; I = I / 3; if (I == 4) cout<<'*'; I++; if (I == 5) cout<<'l'; I = I % 5; if (I == 6) cout<<'t'; I--; } // while I cin.get(); cin.get(); return 0; } // main Activity 2.2: Predict the output from the program TaskTwo in Activity 2.1.

6 Unit 2: Programming in C++, pages 6 of 8 Activity 2.3: Delete the file HiLo.cpp from the Lab8 project under Source folder in Task 1 in the Solution Explorer window. Then press Delete key. This will remove the file HiLo.cpp Next add a file called Lab8tsk2.cpp to the project by choosing the Add New Items... command from the Project menu. Then copy the source code from Activity 2.1 to Lab8tsk2.cpp file. Run the program and observe the output. Y ou may terminate execution of the program by clicking the Close Window " " button on the upper right-hand corner of the program output window. Explain any discrepancies with your predicted output and note any errors observed in the program. Predicted Output: Observed Output: Activity 2.4: Modify the program TaskTwo to correct the error observed in Activity 2.3. The program should give one line of output: LOOP. After testing your program for correctness, print and turn in the modified program. Task 3: While-Loops The purpose of this task is to demonstrate an application of while-loops. As mentioned earlier, one important application of while-loops is proce ssing large quantities of data values, each of which m ust be process ed in the sam e way. The program in this tas k demonstrates this concept, by using a while-loop to process a collection of floating-point dat a values that are stored in a file. W hile working through this task, ask yourself: W hat category of loop is used in this pro gram? W hat statem ents initialize th e loop cond ition? W hat statem ents update the loop condition? Statement of the Problem: Create a C++ program called Extrema that will find a minimum and maximum numbers from a given list of data in a text file. The first data in the text f ile indicates the number of data in the list. After analyzing the above given problem, the steps of the algorithm can be designed as follows:

7 Lab 8: While Loops, page 7 of 8 5. Open the given text file. 6. Read the first data and set it as the size of the list. 7. Read the next data and set it as minimum and maximum. 8. Read the next data. 9. Compare to the minimum: if it is less than the minimum, set the current data as minimum. Otherwise, do nothing. 10. Compare to th e m aximum: if it is g reater th an th e maximum, set the current data as maximum. Otherwise, do nothing. 11. Repeat steps 4-6 if there some more data to be read. 12. Output the minimum to be the minimum number and the maximum to be the maximum number and close the file. Start Open the given text file Read first data set it as Size Read the next data and set it as minimum and maximum. Setup a counter Begin Setup a while loop to determine if counter < Size the Loop Read next data Determine if Next data > Maximum Maximum = Next data Determine if Next data < Minimum Maximum = Next data Maximum = Next data Increment counter Uotput maximum and Minimum Activity 3.1: Each step of the above algorithm and the programming flowchart in Activity 1.1 can be converted to C++ code as follows. 1. Open the given text file. InLab83.open("f:\\inlab83.txt", ios::in); 2. Read the first data and set it as the size of the list. InLab83>>Size; 3. Read the next data and set it as minimum and maximum. InLab83>>Number; Extremum1 = Number; Extremum2 = Number; 4. Read the next data I = 1; while (I <= Size-1) InLab63>>Number; Set the initial minimum and initial maximum to the first number on the list. Set the while loop to repeat steps 4-6. End Open and associate the variable InLab83 to the input file.

8 Unit 2: Programming in C++, pages 8 of 8 5. Compare to the m inimum: if it is less than the m inimum, set the curren t data as minimum. Otherwise, do nothing. if (Number < Extremum1) Extremum1 = Number; 6. Compare to the m aximum: if it is greater th an the m aximum, set the curren t data as maximum. Otherwise, do nothing. if (Number > Extremum2) Extremum2 = Number; 7. Repeat steps 4-6 if there some more data to be read. I++; } // while I 8. Output th e Extrem um1 to be th e m inimum num ber and the Extremum 2 to be the maximum number. cout<<"the extrema are " <<fixed<<showpoint<<setprecision(2) <<Extremum1<<" and "<<Extremum2; InLab63.close() Activity 3.2: Predict the output from the program Extrema if the InL ab83.txt file contains the data shown in the Input: box. Create an input file called InLab83.txt file from Notepad with the data shown below. Then run the program and observe the output. Explain any discrepancies with your predicted output. Input: Predicted Output: Observed Output: Activity 3.3: Delete the file Lab8tsk2.cpp from the Lab8 project under Source folder in Task 1 in the Solution Explorer window. Then p ress Delete key. This will rem ove the f ile Lab8tsk2.cpp Next ad d a file called Lab8tsk3.cpp to the project by choosing the Add New Items... command from the Project m enu. Then add source code from Activity 3.1 to Lab8tsk3.cpp file. Create an input file called InLab83.txt file from Notepad with the data shown below. Then run the program and observe th e output. E xplain any discrepancies with your predicted output. Input: Predicted Output: Observed Output: This statement will increment the value of by 1. This statement will switch the current number to the smaller number. This statement will switch the current number to the larger number. Activity 3.4: How would you describe the purpose of this program?

Lab 10: Alternate Controls

Lab 10: Alternate Controls _ Unit 2: Programming in C++, pages 1 of 8 Department of Computer and Mathematical Sciences CS 1410 Intro to Computer Science with C++ 9 Objectives: Lab 10: Alternate Controls The objective of this lab

More information

Why Is Repetition Needed?

Why Is Repetition Needed? Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable

More information

REPETITION CONTROL STRUCTURE LOGO

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

More information

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed?

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed? Chapter 5: Control Structures II (Repetition) Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct and use countercontrolled, sentinel-controlled,

More information

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite

More information

Programming Language. Control Structures: Repetition (while) Eng. Anis Nazer Second Semester

Programming Language. Control Structures: Repetition (while) Eng. Anis Nazer Second Semester Programming Language Control Structures: Repetition (while) Eng. Anis Nazer Second Semester 2017-2018 Repetition statements Control statements change the order which statements are executed Selection :

More information

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple 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 information

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

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 5: Control Structures II (Repetition) Why Is Repetition Needed? Repetition allows you to efficiently use variables Can input,

More information

Repetition Structures

Repetition Structures Repetition Structures Chapter 5 Fall 2016, CSUS Introduction to Repetition Structures Chapter 5.1 1 Introduction to Repetition Structures A repetition structure causes a statement or set of statements

More information

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition) C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition) Objectives In this chapter, you will: Learn about repetition (looping) control structures

More information

Chapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved

Chapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved Chapter Four: Loops Slides by Evan Gallagher The Three Loops in C++ C++ has these three looping statements: while for do The while Loop while (condition) { statements } The condition is some kind of test

More information

Unit 7. 'while' Loops

Unit 7. 'while' Loops 1 Unit 7 'while' Loops 2 Control Structures We need ways of making decisions in our program To repeat code until we want it to stop To only execute certain code if a condition is true To execute one segment

More information

Department of Computer and Mathematical Sciences. Lab 10: Functions. CS 1410 Intro to Computer Science with C++

Department of Computer and Mathematical Sciences. Lab 10: Functions. CS 1410 Intro to Computer Science with C++ _ Unit 2: Programming in C++, pages 1 of 8 Department of Computer and Mathematical Sciences CS 1410 Intro to Computer Science with C++ 10 Lab 10: Functions Objectives: The objective of this lab is to understand

More information

To become familiar with array manipulation, searching, and sorting.

To become familiar with array manipulation, searching, and sorting. ELECTRICAL AND COMPUTER ENGINEERING 06-88-211: COMPUTER AIDED ANALYSIS LABORATORY EXPERIMENT #2: INTRODUCTION TO ARRAYS SID: OBJECTIVE: SECTIONS: Total Mark (out of 20): To become familiar with array manipulation,

More information

LAB: WHILE LOOPS IN C++

LAB: WHILE LOOPS IN C++ LAB: WHILE LOOPS IN C++ MODULE 2 JEFFREY A. STONE and TRICIA K. CLARK COPYRIGHT 2014 VERSION 4.0 PALMS MODULE 2 LAB: WHILE LOOPS IN C++ 2 Introduction This lab will provide students with an introduction

More information

Today in CS161. Week #3. Learn about. Writing our First Program. See example demo programs. Data types (char, int, float) Input and Output (cin, cout)

Today in CS161. Week #3. Learn about. Writing our First Program. See example demo programs. Data types (char, int, float) Input and Output (cin, cout) Today in CS161 Week #3 Learn about Data types (char, int, float) Input and Output (cin, cout) Writing our First Program Write the Inches to MM Program See example demo programs CS161 Week #3 1 Data Types

More information

Islamic University of Gaza Computer Engineering Dept. C++ Programming. For Industrial And Electrical Engineering By Instructor: Ruba A.

Islamic University of Gaza Computer Engineering Dept. C++ Programming. For Industrial And Electrical Engineering By Instructor: Ruba A. Islamic University of Gaza Computer Engineering Dept. C++ Programming For Industrial And Electrical Engineering By Instructor: Ruba A. Salamh Chapter Four: Loops 2 Chapter Goals To implement while, for

More information

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

More information

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution. Repetition Structures Introduction to Repetition Structures Chapter 5 Spring 2016, CSUS Chapter 5.1 Introduction to Repetition Structures The Problems with Duplicate Code A repetition structure causes

More information

Lab 4: Introduction to Programming

Lab 4: Introduction to Programming _ Unit 2: Programming in C++, pages 1 of 9 Department of Computer and Mathematical Sciences CS 1410 Intro to Computer Science with C++ 4 Lab 4: Introduction to Programming Objectives: The main objective

More information

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points) Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow

More information

Programming Language. Functions. Eng. Anis Nazer First Semester

Programming Language. Functions. Eng. Anis Nazer First Semester Programming Language Functions Eng. Anis Nazer First Semester 2016-2017 Definitions Function : a set of statements that are written once, and can be executed upon request Functions are separate entities

More information

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple 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 information

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++ Repetition Contents 1 Repetition 1.1 Introduction 1.2 Three Types of Program Control Chapter 5 Introduction 1.3 Two Types of Repetition 1.4 Three Structures for Looping in C++ 1.5 The while Control Structure

More information

2.11 Assignment Operators. Assignment expression abbreviations c = c + 3; can be abbreviated as c += 3; using the addition assignment operator

2.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 information

CS112 Lecture: Repetition Statements

CS112 Lecture: Repetition Statements CS112 Lecture: Repetition Statements Objectives: Last revised 2/18/05 1. To explain the general form of the java while loop 2. To introduce and motivate the java do.. while loop 3. To explain the general

More information

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering Lecture 3 Winter 2011/12 Oct 25 Visual C++: Problems and Solutions New section on web page (scroll down)

More information

Chapter 5: Control Structures II (Repetition)

Chapter 5: Control Structures II (Repetition) Chapter 5: Control Structures II (Repetition) 1 Objectives Learn about repetition (looping) control structures Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and

More information

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is

More information

Security Coding Module - Buffer Overflow Data Gone Wild CS1

Security Coding Module - Buffer Overflow Data Gone Wild CS1 Security Coding Module - Buffer Overflow Data Gone Wild CS1 Background Summary: Buffer overflow occurs when data is input or written beyond the allocated bounds of an buffer, array, or other object causing

More information

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Multiple 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 information

Chapter Four: Loops II

Chapter Four: Loops II Chapter Four: Loops II Slides by Evan Gallagher & Nikolay Kirov Chapter Goals To understand nested loops To implement programs that read and process data sets To use a computer for simulations Processing

More information

Building on the foundation. Now that we know a little about cout cin math operators boolean operators making decisions using if statements

Building on the foundation. Now that we know a little about cout cin math operators boolean operators making decisions using if statements Chapter 5 Looping Building on the foundation Now that we know a little about cout cin math operators boolean operators making decisions using if statements Advantages of Computers Computers are really

More information

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements Today in CS161 Lecture #7 Learn about If and else statements Rewrite our First Program Using if and else statements Create new Graphics Demos Using if and else statements CS161 Lecture #7 1 Selective Execution

More information

More About WHILE Loops

More About WHILE Loops More About WHILE Loops http://people.sc.fsu.edu/ jburkardt/isc/week04 lecture 07.pdf... ISC3313: Introduction to Scientific Computing with C++ Summer Semester 2011... John Burkardt Department of Scientific

More information

CSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York

CSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York CSc 10200 Introduc/on to Compu/ng Lecture 8 Edgardo Molina Fall 2011 City College of New York 18 The Null Statement Null statement Semicolon with nothing preceding it ; Do-nothing statement required for

More information

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Multiple 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 information

while for do while ! set a counter variable to 0 ! increment it inside the loop (each iteration)

while for do while ! set a counter variable to 0 ! increment it inside the loop (each iteration) Week 7: Advanced Loops while Loops in C++ (review) while (expression) may be a compound (a block: {s) Gaddis: 5.7-12 CS 1428 Fall 2015 Jill Seaman 1 for if expression is true, is executed, repeat equivalent

More information

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

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

More information

Example 3. #include <iostream> using namespace std; int main()

Example 3. #include <iostream> using namespace std; int main() 1 Repetition Structure Examples Example 1 #include float number, sum=0; // number to be read cin >> number; // read first number cout

More information

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011 The American University in Cairo Department of Computer Science & Engineering CSCI 106-07&09 Dr. KHALIL Exam-I Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: EXAMINATION INSTRUCTIONS

More information

File Input / Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #9

File Input / Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #9 File Input / Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #9 Ziad Matni Dept. of Computer Science, UCSB Midterm Exam grades out! Announcements If you want to see your exams, visit

More information

PIC 10A Flow control. Ernest Ryu UCLA Mathematics

PIC 10A Flow control. Ernest Ryu UCLA Mathematics PIC 10A Flow control Ernest Ryu UCLA Mathematics If statement An if statement conditionally executes a block of code. # include < iostream > using namespace std ; int main () { double d1; cin >> d1; if

More information

Chapter Goals. Contents LOOPS

Chapter Goals. Contents LOOPS CHAPTER 4 LOOPS Slides by Donald W. Smith TechNeTrain.com Final Draft Oct 30, 2011 Chapter Goals To implement while, for, and do loops To hand-trace the execution of a program To become familiar with common

More information

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003 Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an

More information

Control Structures. Repetition (Loop) Structure. Repetition (Loop) Structure. Repetition (Loop) Structure. CS225: Slide Set 8: C++ Loop Structure

Control Structures. Repetition (Loop) Structure. Repetition (Loop) Structure. Repetition (Loop) Structure. CS225: Slide Set 8: C++ Loop Structure Control Structures Flow of control Execution sequence of program statements Repetition (Loop) Structure Control structure used to repeat a sequence of instructions in a loop The simplest loop structure

More information

Lab # 02. Basic Elements of C++ _ Part1

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

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++ CSCE 206: Structured Programming in C++ 2017 Spring Exam 2 Monday, March 20, 2017 Total - 100 Points B Instructions: Total of 13 pages, including this cover and the last page. Before starting the exam,

More information

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage: Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;

More information

WARM UP LESSONS BARE BASICS

WARM UP LESSONS BARE BASICS WARM UP LESSONS BARE BASICS CONTENTS Common primitive data types for variables... 2 About standard input / output... 2 More on standard output in C standard... 3 Practice Exercise... 6 About Math Expressions

More information

Chapter 4 - Notes Control Structures I (Selection)

Chapter 4 - Notes Control Structures I (Selection) Chapter 4 - Notes Control Structures I (Selection) I. Control Structures A. Three Ways to Process a Program 1. In Sequence: Starts at the beginning and follows the statements in order 2. Selectively (by

More information

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

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

More information

CS 007A Midterm 1 Practice Chapters 1 5

CS 007A Midterm 1 Practice Chapters 1 5 CS 007A Midterm 1 Practice Chapters 1 5 1. Consider the 4 bytes stored in contiguous memory, as shown to the right. a. Determine the decimal representation of these 4 one-byte integers: b. Determine the

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

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

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

More information

Chapter 3. Iteration

Chapter 3. Iteration Chapter 3 Iteration Iteration Iteration is the form of program control that allows us to repeat a section of code. For this reason this form of control is often also referred to as repetition. The programming

More information

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 4: Repetition Control Structure

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 4: Repetition Control Structure Learning Objectives At the end of this chapter, student should be able to: Understand the requirement of a loop Understand the Loop Control Variable () Use increment (++) and decrement ( ) operators Program

More information

More about Loops and Decisions

More about Loops and Decisions More about Loops and Decisions 5 In this chapter, we continue to explore the topic of repetition structures. We will discuss how loops are used in conjunction with the other control structures sequence

More information

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

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

More information

conditional statements

conditional statements L E S S O N S E T 4 Conditional Statements PU RPOSE PROCE DU RE 1. To work with relational operators 2. To work with conditional statements 3. To learn and use nested if statements 4. To learn and use

More information

LESSON 3 CONTROL STRUCTURES

LESSON 3 CONTROL STRUCTURES LESSON CONTROL STRUCTURES PROF. JOHN P. BAUGH PROFJPBAUGH@GMAIL.COM PROFJPBAUGH.COM CONTENTS INTRODUCTION... Assumptions.... Logic, Logical Operators, AND Relational Operators..... - Logical AND (&&) Truth

More information

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS Objectives By the end of this section you should be able to:

More information

The first tim e you use Visual Studio it is im portant to get the initial settings right. Load Visual Studio 2010 from the Start menu:

The first tim e you use Visual Studio it is im portant to get the initial settings right. Load Visual Studio 2010 from the Start menu: Visual Studio is an I nt egrated Developm ent Environm ent (I DE) for program m ing in Visual Basic (it can also do C# and C+ + but we will not be covering those). I t is perfectly possible to write Visual

More information

CHAPTER 4 CONTROL STRUCTURES

CHAPTER 4 CONTROL STRUCTURES CHAPTER 4 CONTROL STRUCTURES 1 Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may deviate, repeat code or take decisions. For that purpose,

More information

Increment and the While. Class 15

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

More information

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

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

More information

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions. Introduction In the programs that we have dealt with so far, all statements inside the main function were executed in sequence as they appeared, one after the other. This type of sequencing is adequate

More information

VARIABLES & ASSIGNMENTS

VARIABLES & ASSIGNMENTS Fall 2018 CS150 - Intro to CS I 1 VARIABLES & ASSIGNMENTS Sections 2.1, 2.2, 2.3, 2.4 Fall 2018 CS150 - Intro to CS I 2 Variables Named storage location for holding data named piece of memory You need

More information

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points) Name rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables retain their value

More information

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

Objectives. 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 information

REVIEW. The C++ Programming Language. CS 151 Review #2

REVIEW. The C++ Programming Language. CS 151 Review #2 REVIEW The C++ Programming Language Computer programming courses generally concentrate on program design that can be applied to any number of programming languages on the market. It is imperative, however,

More information

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank 1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A. integer B 1.427E3 B. double D "Oct" C. character B -63.29 D. string F #Hashtag

More information

CIS 130 Exam #2 Review Suggestions

CIS 130 Exam #2 Review Suggestions CIS 130 - Exam #2 Review Suggestions p. 1 * last modified: 11-11-05, 12:32 am CIS 130 Exam #2 Review Suggestions * remember: YOU ARE RESPONSIBLE for course reading, lectures/labs, and especially anything

More information

Lecture Transcript While and Do While Statements in C++

Lecture Transcript While and Do While Statements in C++ Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some

More information

Note: The buy help from the TA for points will apply on this exam as well, so please read that carefully.

Note: The buy help from the TA for points will apply on this exam as well, so please read that carefully. CS 215 Spring 2018 Lab Exam 1 Review Material: - All material for the course up through the Arrays I slides - Nothing from the slides on Functions, Array Arguments, or Implementing Functions Format: -

More information

ROUNDING ERRORS LAB 1. OBJECTIVE 2. INTRODUCTION

ROUNDING ERRORS LAB 1. OBJECTIVE 2. INTRODUCTION ROUNDING ERRORS LAB Imagine you are traveling in Italy, and you are trying to convert $27.00 into Euros. You go to the bank teller, who gives you 20.19. Your friend is with you, and she is converting $2,700.00.

More information

Review. Modules. CS 151 Review #6. Sample Program 6.1a:

Review. Modules. CS 151 Review #6. Sample Program 6.1a: Review Modules A key element of structured (well organized and documented) programs is their modularity: the breaking of code into small units. These units, or modules, that do not return a value are called

More information

Chapter 3 Problem Solving and the Computer

Chapter 3 Problem Solving and the Computer Chapter 3 Problem Solving and the Computer An algorithm is a step-by-step operations that the CPU must execute in order to solve a problem, or to perform that task. A program is the specification of an

More information

Review. Relational Operators. The if Statement. CS 151 Review #4

Review. Relational Operators. The if Statement. CS 151 Review #4 Review Relational Operators You have already seen that the statement total=5 is an assignment statement; that is, the integer 5 is placed in the variable called total. Nothing relevant to our everyday

More information

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays Outline 13.1 Test-Driving the Salary Survey Application 13.2 Introducing Arrays 13.3 Declaring and Initializing Arrays 13.4 Constructing

More information

Chapter 17 - Notes Recursion

Chapter 17 - Notes Recursion Chapter 17 - Notes Recursion I. Recursive Definitions A. Recursion: The process of solving a problem by reducing it to smaller versions of itself. B. Recursive Function: A function that calls itself. C.

More information

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

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

Name SECTION: 12:45 2:20. True or False (12 Points)

Name SECTION: 12:45 2:20. True or False (12 Points) Name SECION: 12:45 2:20 rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables

More information

Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3

Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3 Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3 Ziad Matni Dept. of Computer Science, UCSB Compiling Programs in C++ Input and Output Streams Simple Flow

More information

1. In C++, reserved words are the same as predefined identifiers. a. True

1. In C++, reserved words are the same as predefined identifiers. a. True C++ Programming From Problem Analysis to Program Design 8th Edition Malik TEST BANK Full clear download (no formatting errors) at: https://testbankreal.com/download/c-programming-problem-analysis-program-design-8thedition-malik-test-bank/

More information

Control Structures. A program can proceed: Sequentially Selectively (branch) - making a choice Repetitively (iteratively) - looping

Control Structures. A program can proceed: Sequentially Selectively (branch) - making a choice Repetitively (iteratively) - looping Control Structures A program can proceed: Sequentially Selectively (branch) - making a choice Repetitively (iteratively) - looping Conditional Execution if is a reserved word The most basic syntax for

More information

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++.

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++. Concepts Review 1. An algorithm is a sequence of steps to solve a problem. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++. 3. A flowchart is the graphical

More information

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received CSC 126 FINAL EXAMINATION FINAL Spring 2012 B Name (last, First) Instructor Question # Total Possible Total Received 1. 8 2. 8 3. 8 4. 14 5. 18 6. 10 7. 16 8. 18 TOTAL 100 Final Exam/ Page 2 1) (8 points)

More information

Controls Structure for Repetition

Controls Structure for Repetition Controls Structure for Repetition So far we have looked at the if statement, a control structure that allows us to execute different pieces of code based on certain conditions. However, the true power

More information

do { statements } while (condition);

do { statements } while (condition); Topic 4 1. The while loop 2. Problem solving: hand-tracing 3. The for loop 4. The do loop 5. Processing input 6. Problem solving: storyboards 7. Common loop algorithms 8. Nested loops 9. Problem solving:

More information

Structured Programming. Flowchart Symbols. Structured Programming. Selection. Sequence. Control Structures ELEC 330 1

Structured Programming. Flowchart Symbols. Structured Programming. Selection. Sequence. Control Structures ELEC 330 1 ELEC 330 1 Structured Programming Control Structures ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne Algorithm Development Conditional Expressions Selection Statements Loops 206_C3

More information

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay CS 101 Computer Programming and utilization Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building Bombay Lecture 4, Conditional execution of instructions Friday, August

More information

Due Date: See Blackboard

Due Date: See Blackboard Source File: ~/2315/45/lab45.(C CPP cpp c++ cc cxx cp) Input: under control of main function Output: under control of main function Value: 4 Integer data is usually represented in a single word on a computer.

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

CS 201 (Intro. to Computing) Fall 2015 Sabancı University Sample Questions for Midterm 1

CS 201 (Intro. to Computing) Fall 2015 Sabancı University Sample Questions for Midterm 1 CS 201 (Intro. to Computing) Fall 2015 Sabancı University Sample Questions for Midterm 1 Those questions do not imply any favorite subject or question type for the questions in the actual exam Please also

More information

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++ DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++ Objective: To Learn Basic input, output, and procedural part of C++. C++ Object-orientated programming language

More information

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

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

More information

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 18 Switch Statement (Contd.) And Introduction to

More information

C/C++ Programming Lecture 7 Name:

C/C++ Programming Lecture 7 Name: 1. The increment (++) and decrement (--) operators increase or decrease a variable s value by one, respectively. They are great if all you want to do is increment (or decrement) a variable: i++;. HOWEVER,

More information

assembler Machine Code Object Files linker Executable File

assembler Machine Code Object Files linker Executable File CSCE A211 Programming Intro What is a Programming Language Assemblers, Compilers, Interpreters A compiler translates programs in high level languages into machine language that can be executed by the computer.

More information