Data Types and the while Statement

Size: px
Start display at page:

Download "Data Types and the while Statement"

Transcription

1 Session 2 Student Name Other Identification Data Types and the while Statement The goals of this laboratory session are to: 1. Introduce three of the primitive data types in C Discuss some of the elementary operations that can be performed on these types. 3. Introduce the while control statement. Your instructor will tell you which of the proposed experiments you are to perform. In preparation for this laboratory session, you should read Chapter One of Computer Science: An Overview.

2 14 Session 2 Primitive Data Types Intuitively, something is different between data consisting of numeric values (such as food prices at McDonald's or the number of tacos you can get for a buck at Taco Bell) and data consisting of strings of characters (such as the names of your best friends or the lyrics to your favorite song). In one case we can meaningfully apply the mathematical operations of multiplication and division, while in the other we cannot. In programming terminology we say that the two groups of data are of different type. The C++ programming language accounts for several elementary types of data. All other types of data are constructed as conglomerates of these primitive types. Our goal for now is to learn the fundamentals of three basic types: integer, real, and character. The integer data type encompasses the counting numbers and their negatives:... -4, -3, -2, -1, 0, 1, 2, 3, 4,... In contrast, the data type real includes numeric values with fractional components such as 1.5, , and As explained in Computer Science: An Overview, objects of type integer are normally stored within a machine's memory using two's complement notation, whereas objects of type real are normally stored using floating-point notation. The data type character accounts for data consisting of a single symbol such as a letter of the alphabet, a punctuation mark, or any special symbol, such as $, %, Data items of type character are normally stored using ASCII code. In future laboratory sessions you will learn how words and sentences can be constructed as collections of data of type character. Variables A variable is a name used in a program to refer to an item of data. Such names, also called identifiers, consist of any combination of letters, digits, and underscores, as long as they don't begin with a digit. Thus, Ritz_bits, X25, and Didi_7 would be valid variable names, whereas 7eleven, num miles, and 409 would not be. Good programming practice promotes the use of identifiers that reflect their role within the program. For example, a variable referring to temperature values might be called temperature or degrees. Before a variable name can be used in a program it must be declared; that is, the particular name along with its data type must be described. This is done via a variable declaration statement having the form data_type variable_list; where data_type indicates the type associated with the variables being declared and variable_list is a list of variable names separated by commas. Keywords are used to represent the data types. These words have strict, preassigned meanings and cannot be used for other purposes (such as names of variables) elsewhere in a program. The keywords that represent the data types of integer, real, and character are int, float, and char, respectively. Thus, the declarative statements int servings, fat, calories; float sodium; char ingredients; establish servings, fat, and calories as variables of type int; sodium as a variable of type float; and ingredients as a variable of type char. From the machine's point of view, this

3 Session 2 15 program segment states that the program requires areas of memory for the storage of three values of type int, one value of type float, and one value of type char. Moreover, it informs the translator that these memory locations will be referenced in the remaining part of the program by the names servings, fat, calories, sodium, and ingredients, respectively. The language C++ allows a value to be assigned to a variable at the time the variable is declared. Such initialization of variables is done by following the variable name by an equal sign (=) and the value to be assigned. Thus, the statements int x = 1, y = 2; float z = 3.75; char sym = 'a'; not only establish x, y, z, and sym as variables of type int, int, float, and char, respectively, but assign the variables the starting values 1, 2, 3.75, and a. (Note that data of type character is enclosed with single quotation marks when it appears within a program.) Reading and Writing Data of Primitive Types When you communicate with the world outside of your C++ program you use something called an I/O stream (I/O is a commonly used abbreviation for Input/Output). An I/O stream is a sequence of characters that can be either directed into or out of your program. As you learned in the previous laboratory session, the object cout can be used to display messages on the monitor screen. cout is the stream that is associated with the screen output device. Recall that the operator << was used to display information on the screen. You can also use the << operator to have cout display values that are stored in variables in your program. For example, cout << "One gallon of ice cream = " << scps_gal << " scoops.\n"; If the variable scps_gal is assigned the value 103, then the statement causes the message One gallon of ice cream = 103 scoops. to appear on the monitor screen. We can use the << operator multiple times in the same command to display the value of more than one variable. For example, if the variable v (of type char) is assigned the value A and the variable p (of type int) is assigned the value 75, the statement cout << "U.S.RDA: vitamin " << v << " = " << p << " percent.\n"; produces the line U.S.RDA: vitamin A = 75 percent. Finally, note that the combination \n represents the "new line" marker so that cout << "Over the river\nand through the woods\n"; produces the output

4 16 Session 2 Over the river And through the woods One way of assigning a value to a variable is to use the predefined object cin, which can be thought of as the complement of the cout object. Whereas the latter object can be used to display data on the screen, cin can be used to receive data from the keyboard. cin is the stream that is associated with the keyboard input device. Recall that the << operator directs information from your program onto the screen output stream cout. Similarly, the >> operator directs information from the keyboard input stream cin. Following the >> operator are parameters indicating where the data retrieved should be stored. For example, consider the statements cout << "How many scoops per gallon?\n"; cin >> scps_gal; The first line prompts the user for a response by printing a message on the monitor screen. The second line retrieves the response from the keyboard and stores it in the variable scps_gal. We can use the >> operator more than one time in the same statement to retrieve several data items, which may be of different type For example, if sym is a variable of type char and num is a variable of type int, then the statement cin >> sym >> num; would tell cin to read two pieces of information from the keyboard and assign the first to the variables sym and the second to num. How does cin determine which information should be stored in sym and which in num? Users must use whitespace (such as a space or an end-of-line) to separate the values as they are entered. You will be experiementing with this later in this session. Observe that cin changes the value of the variables scps_gal, sym, and num in the preceding examples. Then cin copies new values into the locations that are represented by these variable names. The output stream cout does not change the value of the variables is displays on the screen. The object cin can be a little tricky to work with, so let us take a moment to consider a few subtle details about its actions. When cin is used, characters representing the keys typed at the keyboard are collected in the input stream until a new line marker (generated by typing the ENTER key 1 ) appears in the input stream. At this time, cin processes the contents of the stream by putting values into variables as dictated by the use of the >> operator. If all of the >> operators used can be satisfied by the data in the input stream, cin makes the appropriate variable assignments and terminates its activities; otherwise, cin must wait for more data to be entered at the keyboard, followed by another new line marker. If cin is able to satisfy its >> operators without consuming the entire input stream, the unused portion of the stream remains and will be found in the input stream when cin is called again. This unused portion of the stream will include the new line marker that terminated the previous input. Thus, when cin is executed again, the input stream will already contain a new line marker, and cin will immediately process the input stream left from the previous call rather than wait for new input from the keyboard. Experiment On some systems this is labeled the RETURN key. If this is the case on your system, simply make the appropriate translation when this manual refers to the ENTER key.

5 Session 2 17 investigates the consequences of this process. For now, suppose that age is a variable of type int and sym is a variable of type char. If the keys 1, 2, 5, and ETNER are typed in response to the command cin >> age >> sym; then cin will assign the value 125 to the variable age and your program will seem to be stuck as cin waits for a character to be entered. cin uses whitespace characters such as space and ENTER to separate inputs, so it is tricky to use cin to receive whitespace characters. Because of such technicalities, many C++ programmers prefer to write their own routines for reading data from the keyboard when robustness is important. We will see how this can be done in later laboratory sessions. Experiment 2.1 Step 1. Execute the following program (CP02E01), and record the results below. int num = 2; char sym_1 = 'c', sym_2 = 'i', sym_3 = 'n'; cout<<"give me "<< num << " scoops of \n"; cout<<sym_1<<"ho"<<sym_1<<"olate "; cout<<sym_1<<"ho<<sym_1<<"olate "<<sym_1<<"hip "; cout<<sym_2<<sym_3<<" a waffle cone please!\n"; Step 2. Change the line

6 18 Session 2 cout<<"give me "<< num << " scoops of \n"; in the program above to cout<<"give me "<< num << " scoops of" << endl; Execute the modified program and record the results. Step 3. Based on your results, what does endl do? Experiment 2.2 Step 1. Execute the following program (CP02E02). In response to the first request, type an a followed by W. In response to the second request, type bcd, followed by W. Record the results. char a, b, c; cout << "Enter a character.\n"; cin >> a; cout << "\nthe character entered was " < a << ".\n"; cout << "Enter three more characters." << endl; cin >> a >> b >> c; cout << "\nthe characters entered were " << a << b << c ".\n";

7 Session 2 19 Step 2. Explain the results obtained in Step 1. In particular, what was left in the input stream after executing cin the first time? Step 3. Execute the program again. This time answer the first request by typing efgh followed by W. Record and explain the results. Experiment 2.3 Step 1. Execute the following program (CP02E03). In response to the first request, type two integers followed by the ENTER key. In response to the second request, type two integers followed by the ENTER key. Record and explain the results.

8 20 Session 2 int a, b, c; cout << "Enter an integer.\n"; cin >> a; cout << "\nthe value entered was " << a << endl; cout << "Enter two integers.\n"; cin >> b >> c; cout << "\nthe values entered were "<<b<<" and "<<c << endl; Step 2. Execute the program in Step 1 again. In response to the first request, type a single integer followed by the ENTER key. In response to the second request, type a single integer, followed by the ENTER key, followed by a single integer, followed by the ENTER key. Record and explain the results. Elementary Operations and the Assignment Statement Another means of assigning values to variables is through the use of an assignment statement. The statement

9 Session 2 21 pizza = 14.50; requests that the value be assigned to the variable pizza using floating-point notation. In general, the assignment statement is used to assign the value found on the right of the = symbol to the variable found on the left of the = symbol. The right side of an assignment statement can be any expression whose value is compatible with the variable on the left side. Thus, assuming that calories and fat are variables of type integer, the following assignment statements are valid. calories = 270; fat = calories; In the case of numeric data, the traditional arithmetic operations can be used in an expression on the right side of the assignment statement to direct the computation of the value to be assigned. Here the symbols +, -, *, and / are used to represent addition, subtraction, multiplication, and division, respectively. Thus, the statement pounds = calories * fat; assigns the product of calories and fat to pounds. Parentheses can be used to clarify the order in which the expression on the right side of an assignment statement is to be evaluated. Thus, cal_serving = (fat_calories + sugar_calories) / servings; would correctly assign the true value to calories per serving (cal_serving), whereas cal_serving = fat_calories + sugar_calories / servings; would not. A common operation is that of incrementing a value as accomplished by the statement x = x + 1; where x is an integer variable. C++ provides a shorthand notation for this assignment statement. It has the form x++; which consists of the name of the variable to be incremented followed by two plus signs. A similar expression x--; is a shorthand notation for the statement x = x - 1; that decrements the value of x by one. Expressions such as x++ and x-- can be used in more complex expressions such as in the assignment statement y = 5 + x++; Here, y is assigned the result of adding 5 to x and then x is incremented by 1. In particular, the combination x = 2; y = 5 + x++; would result in y being assigned the value 7 and x being assigned 3. Note that the value

10 22 Session 2 of x is not incremented until its original value has already been used in the computation. If we had wanted the incremented value to be used in the computation, we would have used the expression ++x rather than x++. In short, ++x means to increment the value of x and then use this new value in the remaining computation, whereas x++ means to increment the value of x after its original value has been used. Thus, the sequence x = 2; y = x; would result in y being assigned 8 and x being assigned 3. The expression x-- has a similar variation. The C++ language recognizes a close relationship between data of type integer and character. Indeed, it is often convenient to think of the bit pattern representing a symbol (type character) as an integer value. (The printable characters in ASCII are represented by the integer values 32 through 126.) In particular, if sym is of type char and num is of type int, then statements such as sym = 99; num = 'a'; and sym++; are permitted (although not always considered good programming practice). Assuming that characters are represented in ASCII, the first of these statements assigns the character c to the variable sym since c is represented by 99 in ASCII. The second statement assigns the value 97 to the variable num since the character a is represented by 97 in ASCII. The third statement is often used to convert a letter in the alphabet to the next sequential letter (except for the letter z). Experiment 2.4 Step 1. Execute the following program (CP02E04) and record the results. int x, y; cout << "x = " << x << endl; cout << "y = " << y << endl; y = 25; cout << "x = " << x << endl; cout << "y = " << y << endl;

11 Session 2 23 Step 2. Explain the results in Step 1. (What can be said about the value of a variable that has not been assigned a value?) Experiment 2.5 Step 1. Execute the following program (CP02E05), and record the results. int x, y, z; x = y = z = 5 + 3; cout << "x = " << x << endl; cout << "y = " << y << endl; cout << "z = " << z << endl; Step 2. Change the assignment statement in Step 1 to read as follows: x = 1 + y = 5 + z = 7;

12 24 Session 2 Execute the modified program, and record the results. Step 3. Explain the results in the preceding steps. Experiment 2.6 Step 1. Execute the following program (CP02E06), and record the results. int integer_result; float float_result; integer_result = 7/3; float_result = 7/3; cout << integer_result << endl; cout << float_result << endl; integer_result = 12.6/3; float_result = 12.6/3; cout << integer_result << endl; cout << float_result << endl;

13 Session 2 25 Step 2. Explain the results and the usage of the division operator (/). Experiment 2.7 Step 1. Execute the following program (CP02E07), and record the results. int a, b, c; a = 7 % 3; b = 8 % 3; c = 8 % 4; cout << a << " " << b << " " << c << endl; Step 2. The operator % is called the modulus operator. What does it do? Step 3. Change the statement a = 7 % 3;

14 26 Session 2 to a = 7.0 % 3.0; and try to execute the modified program. What can you conclude? Experiment 2.8 Step 1. Assuming that x and y are variables of type integer, what ambiguity exists in the following two statements? (Hint: If x starts with the value 3, will y in the first statement be assigned 9 or 11?) y = x + x + x++; y = x++ + x + x; Step 2. Write a short program to discover what actually happens when these statements are executed. Record your program and your findings below.

15 Session 2 27 Step 3. Change the program you wrote in Step 2 to investigate the expressions x + x + ++x ++x + x + x x-- + x + x and x + x + x-- Record your findings and explain them.

16 28 Session 2 The while Control Statement Normally, instructions within a function in a C++ program are executed in the order in which they appear. While this may be sufficient for simple programs, it is not flexible enough for more complex tasks. Thus, C++ provides a variety of control statements for redirecting the flow of execution. One of these is the while control statement. The while control statement is used to execute a certain block of code repetitively. The general form of the while statement is while (condition) body where body is a statement or a sequence of statements. If body consists of only one statement, then the opening and closing braces of the while statement can be omitted. Execution of the while statement begins with testing the condition. If true, the statement or statements within the body will be executed, and the condition will be tested once again. This cyclic process continues until the condition is found to be false, at which time control skips to the statements following the closing brace of the while statement. Thus, the following program int i; i = 5; while (i > 0) cout << "Recycle!\n"; i--; produces Recycle! Recycle! Recycle! Recycle! Recycle! We will discuss the details of the condition part of a while statement in Session 5. For now we need merely note that the symbols <, >, ==, and!= are used to represent less than, greater than, equal to, and not equal to, respectively, and combined as in <= and >=

17 Session 2 29 to represent less than or equal to and greater than or equal to. Experiment 2.9 Step 1. The following program (CP02E09) is designed to print the integers 1 through 10. Execute the program and record the results. int i; i = 1; while (i < 10) i++; cout << i << endl; Step 2. Explain the changes required to make the program perform as initially intended. Confirm your answer by making these changes and executing the corrected program. Experiment 2.10 Step 1. Execute the following program(cp02e10), and record the results.

18 30 Session 2 char x = 'a'; while (x < 'z') x++; cout << x << endl; Step 2. Explain the results obtained in Step 1.

19 Session 2 31 Post-Laboratory Problems 2.1. Write a program that neatly prints a table of powers squares, cubes, and quartics. Print these powers for the integers from 0 to 100. The first few lines of the table might appear as follows: integer square cube quartic Write a program that calculates the area of a right triangle whose dimensions are supplied by the user Write a program with the declarations int x, y, w, z; x = 2; y = -3; w = 7; z = -10; that computes and reports the results of each of the following arithmetic problems. According to your results, summarize the precedence rules for the mathematical operators /, %, -, +, *. a. x / y b. w / y / x c. z / y % x d. x % - y * w e. x % y f. - z % w - y / x * g. 9 - x % ( 2 + y ) 2.4. Write a program that computes the sum of the integers from 1 up to an integer provided by the program s user. For example, if the user types 10, the program should reply 55 because = Write a "Guess what number I'm thinking of..." game. Allow the player a maximum of five guesses, and if he or she hasn't guessed the number by then, print a losing message. If the player guesses the target number, print a winning message Write a program that calculates the mean of a set of positive integers that are supplied by the user. Write the program so that a negative number terminates the input string of integers. Thus, the user can supply a different number of integers each time the program is executed Write a program that asks the user for an integer and then displays all of the positive prime numbers that are equal to or less than that supplied integer. For example, if the user's number is 12, the program should print 11, 7, 5, 3, 2, In this laboratory session you learned a shorthand notation for incrementing and decrementing variables. A similar shorthand consists of an operation followed by an assignment symbol such as *= or +=. Execute the program below and, based on the results, state what += appears to represent. Then, experiment with other

20 32 Session 2 arithmetic operations to confirm your hypothesis. Present your findings in an organized manner. To extend your investigation, experiment with such expressions as x *= y + z. int x; x = 5; cout << x << endl; x += 3; cout << x << endl; x += 3; cout << x << endl;

Data Types and the while Statement

Data Types and the while Statement Session 2 Student Name Other Identification Data Types and the while Statement In this laboratory you will: 1. Learn about three of the primitive data types in Java, int, double, char. 2. Learn about the

More information

Chapter 2 Basic Elements of C++

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

More information

Lecture 3 Tao Wang 1

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

More information

3 The L oop Control Structure

3 The L oop Control Structure 3 The L oop Control Structure Loops The while Loop Tips and Traps More Operators The for Loop Nesting of Loops Multiple Initialisations in the for Loop The Odd Loop The break Statement The continue Statement

More information

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

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

More information

Chapter 2: Basic Elements of C++

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

More information

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

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

More information

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

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

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

More information

The C++ Language. Arizona State University 1

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

More information

Objectives. In this chapter, you will:

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

More information

UNIT- 3 Introduction to C++

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

More information

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

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

More information

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma. REVIEW cout Statement The cout statement invokes an output stream, which is a sequence of characters to be displayed to the screen. cout

More information

Fundamentals of Programming CS-110. Lecture 2

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

More information

Full file at

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

More information

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh C++ PROGRAMMING For Industrial And Electrical Engineering Instructor: Ruba A. Salamh CHAPTER TWO: Fundamental Data Types Chapter Goals In this chapter, you will learn how to work with numbers and text,

More information

Add Subtract Multiply Divide

Add Subtract Multiply Divide ARITHMETIC OPERATORS if AND if/else AND while LOOP Order of Operation (Precedence Part 1) Copyright 2014 Dan McElroy Add Subtract Multiply Divide + Add - Subtract * Multiply / Divide = gives the quotient

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

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

More information

Expressions, Input, Output and Data Type Conversions

Expressions, Input, Output and Data Type Conversions L E S S O N S E T 3 Expressions, Input, Output and Data Type Conversions PURPOSE 1. To learn input and formatted output statements 2. To learn data type conversions (coercion and casting) 3. To work with

More information

Reserved Words and Identifiers

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

More information

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

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

More information

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1 NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.

More information

Introduction to Programming EC-105. Lecture 2

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

More information

Chapter 2: Overview of C++

Chapter 2: Overview of C++ Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using C++ 6e by Frank L. Friedman and Elliot B. Koffman C++ Background Introduced by Bjarne Stroustrup of AT&T s Bell Laboratories in

More 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

BITG 1233: Introduction to C++

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

More information

Topic 2: C++ Programming fundamentals

Topic 2: C++ Programming fundamentals Topic 2: C++ Programming fundamentals Learning Outcomes Upon successful completion of this topic you will be able to: describe basic elements of C++ programming language compile a program identify and

More information

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

More information

download instant at Introduction to C++

download instant at  Introduction to C++ Introduction to C++ 2 Programming: Solutions What s in a name? that which we call a rose By any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would

More information

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #2

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

Ex: If you use a program to record sales, you will want to remember data:

Ex: If you use a program to record sales, you will want to remember data: Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:

More information

Introduction to C++ Lecture Set 2. Introduction to C++ Week 2 Dr Alex Martin 2013 Slide 1

Introduction to C++ Lecture Set 2. Introduction to C++ Week 2 Dr Alex Martin 2013 Slide 1 Introduction to C++ Lecture Set 2 Introduction to C++ Week 2 Dr Alex Martin 2013 Slide 1 More Arithmetic Operators More Arithmetic Operators In the first session the basic arithmetic operators were introduced.

More information

Pseudo-code vs. Assembly. Introduction to High-Level Language Programming. Disadvantages of Assembly. Pseudo-code vs. High-level Programs

Pseudo-code vs. Assembly. Introduction to High-Level Language Programming. Disadvantages of Assembly. Pseudo-code vs. High-level Programs Pseudo-code vs. Assembly Introduction to High-Level Language Programming Chapter 7 Set sum to 0 While i 5 do Get value for N Add N to sum Increase value of i by 1 Print the value of sum.begin -- Sum 5

More information

Introduction to Programming

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

More information

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

PART I.   Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++. Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

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

More information

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

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

More information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

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

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

More information

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 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

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

Programming with C++ as a Second Language

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

More information

Introductionto C++ Programming

Introductionto C++ Programming What s in a name? that which we call a rose By any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would be the most fun? Peggy Walker Take some more

More information

(Refer Slide Time: 00:23)

(Refer Slide Time: 00:23) In this session, we will learn about one more fundamental data type in C. So, far we have seen ints and floats. Ints are supposed to represent integers and floats are supposed to represent real numbers.

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 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics 1 Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-3 2.1 Variables and Assignments 2

More 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

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm. CHAPTER 1&2 OBJECTIVES After completing this chapter, you will be able to: Understand the basics and Advantages of an algorithm. Analysis various algorithms. Understand a flowchart. Steps involved in designing

More information

Maciej Sobieraj. Lecture 1

Maciej Sobieraj. Lecture 1 Maciej Sobieraj Lecture 1 Outline 1. Introduction to computer programming 2. Advanced flow control and data aggregates Your first program First we need to define our expectations for the program. They

More information

CS242 COMPUTER PROGRAMMING

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

More information

Chapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved

Chapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved Chapter 1 C++ Basics Copyright 2010 Pearson Addison-Wesley. All rights reserved Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment

More information

Chapter-8 DATA TYPES. Introduction. Variable:

Chapter-8 DATA TYPES. Introduction. Variable: Chapter-8 DATA TYPES Introduction To understand any programming languages we need to first understand the elementary concepts which form the building block of that program. The basic building blocks include

More information

Problem Solving With C++ Ninth Edition

Problem Solving With C++ Ninth Edition CISC 1600/1610 Computer Science I Programming in C++ Professor Daniel Leeds dleeds@fordham.edu JMH 328A Introduction to programming with C++ Learn Fundamental programming concepts Key techniques Basic

More information

Chapter 1 Introduction to Computers and C++ Programming

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

More information

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Copyright 2011 Pearson Addison-Wesley. All rights

More information

Full file at

Full file at Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

More information

This watermark does not appear in the registered version - Slide 1

This watermark does not appear in the registered version -   Slide 1 Slide 1 Chapter 1 C++ Basics Slide 2 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output Program Style

More information

2 nd Week Lecture Notes

2 nd Week Lecture Notes 2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

More information

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style 3 2.1 Variables and Assignments Variables and

More information

Chapter 2. C++ Basics

Chapter 2. C++ Basics Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-2 2.1 Variables and Assignments Variables

More information

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing 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

More information

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

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

More information

Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:

Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents: Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language Dr. Amal Khalifa Lecture Contents: Introduction to C++ Origins Object-Oriented Programming, Terms Libraries and Namespaces

More 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

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

More information

Homework #3 CS2255 Fall 2012

Homework #3 CS2255 Fall 2012 Homework #3 CS2255 Fall 2012 MULTIPLE CHOICE 1. The, also known as the address operator, returns the memory address of a variable. a. asterisk ( * ) b. ampersand ( & ) c. percent sign (%) d. exclamation

More information

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

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

More information

A First Program - Greeting.cpp

A First Program - Greeting.cpp C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout

More information

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

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

More information

Introduction to Programming

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

More information

COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP Primitive and Class Types. Yi Hong May 14, 2015 COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

More information

LAB: INTRODUCTION TO FUNCTIONS IN C++

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

More information

Fundamentals of Programming Session 4

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

More information

Engineering Problem Solving with C++, Etter/Ingber

Engineering Problem Solving with C++, Etter/Ingber Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input

More information

CS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++

CS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++ CS101: Fundamentals of Computer Programming Dr. Tejada stejada@usc.edu www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++ 10 Stacks of Coins You have 10 stacks with 10 coins each that look and feel

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual: Java Programming, Eighth Edition 2-1 Chapter 2 Using Data A Guide to this Instructor s Manual: We have designed this Instructor s Manual to supplement and enhance your teaching experience through classroom

More information

BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC ELEMENTS OF A COMPUTER PROGRAM BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators

More information

CSI33 Data Structures

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

More information

Variables. Data Types.

Variables. Data Types. Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

More information

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions Mr. Dave Clausen La Cañada High School Vocabulary Variable- A variable holds data that can change while the program

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

Pseudocode is an abbreviated version of the actual statement t t (or code ) in the program.

Pseudocode is an abbreviated version of the actual statement t t (or code ) in the program. Pseudocode Pseudocode is an abbreviated version of the actual statement t t (or code ) in the program. It is a type of algorithm in that all steps needed to solve the problem must be listed. 1 While algorithms

More information

Data Types & Variables

Data Types & Variables Fundamentals of Programming Data Types & Variables Budditha Hettige Exercise 3.1 Write a C++ program to display the following output. Exercise 3.2 Write a C++ program to calculate and display total amount

More information

Unit 3. Operators. School of Science and Technology INTRODUCTION

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

More information

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

More information

IT 1033: Fundamentals of Programming Data types & variables

IT 1033: Fundamentals of Programming Data types & variables IT 1033: Fundamentals of Programming Data types & variables Budditha Hettige Department of Computer Science Exercise 3.1 Write a C++ program to display the following output. Exercise 3.2 Write a C++ program

More information

Introduction to the C++ Programming Language

Introduction to the C++ Programming Language LESSON SET 2 Introduction to the C++ Programming Language OBJECTIVES FOR STUDENT Lesson 2A: 1. To learn the basic components of a C++ program 2. To gain a basic knowledge of how memory is used in programming

More information

Chapter 7. Additional Control Structures

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

More information

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid: 1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,

More information

CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started

CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started Handout written by Julie Zelenski, Mehran Sahami, Robert Plummer, and Jerry Cain. After today s lecture, you should run home and read

More information

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ 0.1 Introduction This is a session to familiarize working with the Visual Studio development environment. It

More information

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University Overview of C, Part 2 CSE 130: Introduction to Programming in C Stony Brook University Integer Arithmetic in C Addition, subtraction, and multiplication work as you would expect Division (/) returns the

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

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132)

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132) BoredGames Language Reference Manual A Language for Board Games Brandon Kessler (bpk2107) and Kristen Wise (kew2132) 1 Table of Contents 1. Introduction... 4 2. Lexical Conventions... 4 2.A Comments...

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 3 BASIC INSTRUCTION OF C++

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

More information

Fundamental of Programming (C)

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

More information