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

Size: px
Start display at page:

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

Transcription

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

2 C++ for Engineers and Scientists Third Edition Chapter 3 Assignment, Formatting, and Interactive Input

3 Objectives In this chapter, you will learn about: Assignment operations Formatting numbers for program output Using mathematical library functions Program input using the cin object Symbolic constants A case study involving acid rain Common programming errors C++ for Engineers and Scientists, Third Edition 3

4 Assignment Operations Assignment Statement: Assigns the value of the expression on the right side of the = to the variable on the left side of the = Another assignment statement using the same variable will overwrite the previous value with the new value Examples: slope = 3.7; slope = 6.28; C++ for Engineers and Scientists, Third Edition 4

5 Assignment Operations (continued) Right side of an assignment statement may contain any expression that can be evaluated to a value Examples: newtotal = total; taxes =.06*amount; average = sum / items; Only one variable can be on the left side of an assignment statement C++ for Engineers and Scientists, Third Edition 5

6 Assignment Operations (continued) C++ for Engineers and Scientists, Third Edition 6

7 Assignment Operations (continued) Assignment operator: The = sign C++ statement: Any expression terminated by a semicolon Multiple assignments in the same expression are possible Example: a = b = c = 25; C++ for Engineers and Scientists, Third Edition 7

8 Assignment Operations (continued) Coercion: Forcing a data value to another data type Value of the expression on the right side of an assignment statement will be coerced (converted) to the data type of the variable on the left side during evaluation Variable on the left side may also be used on the right side of an assignment statement C++ for Engineers and Scientists, Third Edition 8

9 Assignment Operations (continued) C++ for Engineers and Scientists, Third Edition 9

10 Assignment Operations (continued) Accumulation statement: Has the effect of accumulating, or totaling Syntax: variable = variable + newvalue; C++ for Engineers and Scientists, Third Edition 10

11 Assignment Operations (continued) Additional assignment operators provide short cuts: +=, -=, *=, /=, %= Example: sum = sum + 10; is equivalent to: sum += 10; price *= rate +1; is equivalent to: price = price * (rate + 1); C++ for Engineers and Scientists, Third Edition 11

12 Assignment Operations (continued) C++ for Engineers and Scientists, Third Edition 12

13 Assignment Operations (continued) Counting statement: Adds a fixed value to the variable s current value Syntax: variable = variable + fixednumber; Example: i = i + 1; count = count + 1; C++ for Engineers and Scientists, Third Edition 13

14 Assignment Operations (continued) Increment operator ++: Unary operator for the special case when a variable is increased by 1 Prefix increment operator appears before the variable Example: ++i Postfix increment operator appears after the variable Example: i++ C++ for Engineers and Scientists, Third Edition 14

15 Assignment Operations (continued) Example: k = ++n; //prefix increment is equivalent to: n = n + 1; //increment n first k = n; //assign n s value to k Example: k = n++; //postfix increment is equivalent to k = n; //assign n s value to k n = n + 1; //and then increment n C++ for Engineers and Scientists, Third Edition 15

16 Assignment Operations (continued) Decrement operator --: Unary operator for the special case when a variable is decreased by 1 Prefix decrement operator appears before the variable Example: --i; Postfix decrement operator appears after the variable Example: i--; C++ for Engineers and Scientists, Third Edition 16

17 Formatting Numbers for Program Output Proper output formatting contributes to ease of use and user satisfaction cout with stream manipulators can control output formatting C++ for Engineers and Scientists, Third Edition 17

18 Formatting Numbers for Program Output (continued) Table 3.1 Commonly Used Stream Manipulators C++ for Engineers and Scientists, Third Edition 18

19 Formatting Numbers for Program Output (continued) Table 3.1 Commonly Used Stream Manipulators (continued) C++ for Engineers and Scientists, Third Edition 19

20 Formatting Numbers for Program Output (continued) C++ for Engineers and Scientists, Third Edition 20

21 Formatting Numbers for Program Output (continued) The field width manipulator must be included for each value in the data stream sent to cout Other manipulators remain in effect until they are changed iomanip header file must be included to use manipulators requiring arguments C++ for Engineers and Scientists, Third Edition 21

22 Formatting Numbers for Program Output (continued) Formatting floating-point numbers requires three field-width manipulators to: Set the total width of the display Force a decimal place Set the number of significant digits after the decimal point Example: cout << " " << setw(10) << fixed << setprecision(3) << << " "; produces this output: C++ for Engineers and Scientists, Third Edition 22

23 Formatting Numbers for Program Output (continued) setprecision: Sets number of digits after decimal point if a decimal point has been explicitly forced; otherwise, it sets the total number of displayed digits If the field width is too small, cout ignores the setw manipulator setting and allocates enough space for printing If setprecision setting is too small, the fractional part of the value is rounded to the specified number of decimal places C++ for Engineers and Scientists, Third Edition 23

24 Formatting Numbers for Program Output (continued) If setprecision value is too large, the fractional value is displayed with its current size C++ for Engineers and Scientists, Third Edition 24

25 Formatting Numbers for Program Output (continued) Table 3.2 Effect of Format Manipulators C++ for Engineers and Scientists, Third Edition 25

26 Formatting Numbers for Program Output (continued) Table 3.2 Effect of Format Manipulators (continued) C++ for Engineers and Scientists, Third Edition 26

27 Formatting Numbers for Program Output (continued) setiosflags manipulator: Allows additional formatting: Right or left justification Fixed display with 6 decimal places Scientific notation with exponential display Display of a leading + sign Parameterized manipulator: One which requires arguments, or parameters C++ for Engineers and Scientists, Third Edition 27

28 Formatting Numbers for Program Output (continued) Table 3.3 Format Flags for Use with setiosflags() C++ for Engineers and Scientists, Third Edition 28

29 Formatting Numbers for Program Output (continued) C++ for Engineers and Scientists, Third Edition 29

30 Formatting Numbers for Program Output (continued) To designate an octal integer constant, use a leading zero To designate a hexadecimal integer constant, use a leading 0x Manipulators affect only output; the value stored internally does not change C++ for Engineers and Scientists, Third Edition 30

31 Formatting Numbers for Program Output (continued) C++ for Engineers and Scientists, Third Edition 31

32 Formatting Numbers for Program Output (continued) Manipulators can also be set using the ostream class methods Separate the cout object name from the method name with a period Example: cout.precision(2) C++ for Engineers and Scientists, Third Edition 32

33 Formatting Numbers for Program Output (continued) Table 3.4 ostream Class Functions C++ for Engineers and Scientists, Third Edition 33

34 Using Mathematical Library Functions C++ has preprogrammed mathematical functions that can be included in a program You must include the cmath header file: #include <cmath> Math functions require one or more arguments as input, but will return only one value All functions are overloaded, and can be used with integer and real arguments C++ for Engineers and Scientists, Third Edition 34

35 Using Mathematical Library Functions (continued) Table 3.5 Common C++ Functions C++ for Engineers and Scientists, Third Edition 35

36 Using Mathematical Library Functions (continued) To use a math function, give its name and pass the input arguments within parentheses Expressions that can be evaluated to a value can be passed as arguments Figure 3.10 Using and passing data to a function C++ for Engineers and Scientists, Third Edition 36

37 Using Mathematical Library Functions (continued) C++ for Engineers and Scientists, Third Edition 37

38 Using Mathematical Library Functions (continued) Function calls can be nested Example: sqrt(sin(abs(theta))) Cast operator: A unary operator that forces the data to the desired data type Compile-time cast Syntax: datatype (expression) Example: int(a+b) C++ for Engineers and Scientists, Third Edition 38

39 Using Mathematical Library Functions (continued) Run-time cast: The requested conversion is checked at run time and applied if valid Syntax: staticcast<data-type> (expression) Example: staticcast<int>(a*b) C++ for Engineers and Scientists, Third Edition 39

40 Program Input Using cin cin Object: Allows data entry to a running program Use of the cin object causes the program to wait for input from the keyboard When keyboard entry is complete, the program resumes execution, using the entered data An output statement preceding the cin object statement provides a prompt to the user C++ for Engineers and Scientists, Third Edition 40

41 Program Input Using cin (continued) C++ for Engineers and Scientists, Third Edition 41

42 Program Input Using cin (continued) cin can accept multiple input values to be stored in different variables Multiple numeric input values must be separated by spaces Example: cin >> num1 >> num2 with keyboard entry: C++ for Engineers and Scientists, Third Edition 42

43 Program Input Using cin (continued) C++ for Engineers and Scientists, Third Edition 43

44 Program Input Using cin (continued) User-input validation: The process of ensuring that data entered by the user matches the expected data type Robust program: One that detects and handles incorrect user entry C++ for Engineers and Scientists, Third Edition 44

45 Symbolic Constants Symbolic constant: Constant value that is declared with an identifier using the const keyword A constant s value may not be changed Example: const int MAXNUM = 100; Good programming places statements in appropriate order C++ for Engineers and Scientists, Third Edition 45

46 Symbolic Constants (continued) Proper placement of statements: preprocessor directives int main() { symbolic constants main function declarations } other executable statements return value C++ for Engineers and Scientists, Third Edition 46

47 A Case Study: Acid Rain Acid Rain: Develop a program to calculate the ph level of a substance based on user input of the concentration of hydronium ions Step 1: Analyze the Problem Step 2: Develop a Solution Step 3: Code the Solution Step 4: est and Correct the Program C++ for Engineers and Scientists, Third Edition 47

48 A Closer Look: Programming Errors Program errors may be detected in four ways: Before a program is compiled (desk checking) While it is being compiled (compile-time errors) While it is being run (run-time errors) While examining the output after completion Errors may be: Typos in the source code Logic errors C++ for Engineers and Scientists, Third Edition 48

49 A Closer Look: Programming Errors (continued) Logic errors: Often difficult to detect and difficult to find the source Program tracing: Stepping through the program by hand or with a trace tool Debugger: Program that allows the interruption of a running program to determine values of its variables at any point C++ for Engineers and Scientists, Third Edition 49

50 Common Programming Errors Failure to declare or initialize variables before use Failure to include the preprocessor statement when using a C++ preprogrammed library Passing the incorrect number or type of arguments to a function Applying increment or decrement operator to an expression instead of an individual variable C++ for Engineers and Scientists, Third Edition 50

51 Common Programming Errors (continued) Failure to separate all variables passed to cin with the extraction symbol >> Failure to test thoroughly Compiler-dependent evaluation when increment or decrement operators are used with variables that appear more than once in the same expression C++ for Engineers and Scientists, Third Edition 51

52 Summary Expression: A sequence of one or more operands separated by operators Expressions are evaluated based on precedence and associativity Assignment operator: = Increment operator: ++ Decrement operator: -- C++ for Engineers and Scientists, Third Edition 52

53 Summary (continued) Use #include <cmath> for math functions Arguments to a function must be passed in the proper number, type, and order Functions may be included within larger expressions cin object provides data input from a keyboard; program is suspended until the input arrives C++ for Engineers and Scientists, Third Edition 53

54 Summary (continued) Use a prompt to alert the user to provide input Constants are named values that do not change C++ for Engineers and Scientists, Third Edition 54

### Lecture 4 Tao Wang 1

Lecture 4 Tao Wang 1 Objectives In this chapter, you will learn about: Assignment operations Formatting numbers for program output Using mathematical library functions Symbolic constants Common programming

### Lecture 3 Tao Wang 1

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

### C Programming

204216 -- C Programming Chapter 3 Processing and Interactive Input Adapted/Assembled for 204216 by Areerat Trongratsameethong A First Book of ANSI C, Fourth Edition Objectives Assignment Mathematical Library

### CHAPTER 3 Expressions, Functions, Output

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

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

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

### Chapter 3 : Assignment and Interactive Input (pp )

Page 1 of 50 Printer Friendly Version User Name: Stephen Castleberry email Id: scastleberry@rivercityscience.org Book: A First Book of C++ 2007 Cengage Learning Inc. All rights reserved. No part of this

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

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

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

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

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

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

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

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

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

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

### Introduction to C++ (Extensions to C)

Introduction to C++ (Extensions to C) C is purely procedural, with no objects, classes or inheritance. C++ is a hybrid of C with OOP! The most significant extensions to C are: much stronger type checking.

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

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

### Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1

300580 Programming Fundamentals 3 With C++ Variable Declaration, Evaluation and Assignment 1 Today s Topics Variable declaration Assignment to variables Typecasting Counting Mathematical functions Keyboard

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

### C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing

### The cin Object. cout << "Enter the length and the width of the rectangle? "; cin >> length >> width;

The cin Object Short for console input. It is used to read data typed at the keyboard. Must include the iostream library. When this instruction is executed, it waits for the user to type, it reads the

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

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

### Chapter 2: Basic Elements of C++

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

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

### Window s Visual Studio Output

1. Explain the output of the program below. Program char str1[11]; char str2[11]; cout > str1; Window s Visual Studio Output Enter a string: 123456789012345678901234567890 Enter

### C++ for Engineers and Scientists. Third Edition. Chapter 12 Pointers

C++ for Engineers and Scientists Third Edition Chapter 12 Pointers CSc 10200! Introduction to Computing Lecture 24 Edgardo Molina Fall 2013 City College of New York 2 Objectives In this chapter you will

### I/O Streams and Standard I/O Devices (cont d.)

Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore how to read data from the standard input device Learn how to use predefined

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

Last Time Let s all Repeat Together 10/3/05 CS150 Introduction to Computer Science 1 1 We covered o Counter and sentinel controlled loops o Formatting output Today we will o Type casting o Top-down, stepwise

### 3.1. Chapter 3: The cin Object in Program 3-1. Displaying a Prompt 8/23/2014. The cin Object

Chapter 3: Expressions and Interactivity 3.1 The cin Object The cin Object The cin Object in Program 3-1 Standard input object Like cout, requires iostream file Used to read input from keyboard Information

### Chapter 3: Expressions and Interactivity

Chapter 3: Expressions and Interactivity 3.1 The cin Object The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Information retrieved from cin with >>

### 3.1. Chapter 3: Displaying a Prompt. Expressions and Interactivity

Chapter 3: Expressions and Interactivity 3.1 The cin Object Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

### CSc Introduction to Computing

CSc 10200 Introduction to Computing Lecture 2 Edgardo Molina Fall 2011 - City College of New York Thursday, September 1, 2011 Introduction to C++ Modular program: A program consisting of interrelated segments

### Chapter 2. Outline. Simple C++ Programs

Chapter 2 Simple C++ Programs Outline Objectives 1. Building C++ Solutions with IDEs: Dev-cpp, Xcode 2. C++ Program Structure 3. Constant and Variables 4. C++ Operators 5. Standard Input and Output 6.

### Chapter 3: Expressions and Interactivity. Copyright 2012 Pearson Education, Inc. Thursday, October 9, 14

Chapter 3: Expressions and Interactivity 3.1 The cin Object The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Information retrieved from cin with >>

Slide 7-1 Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Type Conversation / Casting Name Constant - const, #define X When You Mix Apples and Oranges: Type Conversion Operations

### Chapter 10 Introduction to Classes

C++ for Engineers and Scientists Third Edition Chapter 10 Introduction to Classes CSc 10200! Introduction to Computing Lecture 20-21 Edgardo Molina Fall 2013 City College of New York 2 Objectives In this

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

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

### 3.1. Chapter 3: The cin Object. Expressions and Interactivity

Chapter 3: Expressions and Interactivity 3.1 The cin Object Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3-1 The cin Object Standard input stream object, normally the keyboard,

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

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

### For Teacher's Use Only Q No Total Q No Q No

Student Info Student ID: Center: Exam Date: FINALTERM EXAMINATION Spring 2010 CS201- Introduction to Programming Time: 90 min Marks: 58 For Teacher's Use Only Q No. 1 2 3 4 5 6 7 8 Total Marks Q No. 9

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

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

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

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

### C++ As A "Better C" Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

C++ As A "Better C" Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2013 Fall Outline 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.5

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

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

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

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

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

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

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

### Fundamentals of Programming Session 7

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

### Getting started with C++ (Part 2)

Getting started with C++ (Part 2) CS427: Elements of Software Engineering Lecture 2.2 11am, 16 Jan 2012 CS427 Getting started with C++ (Part 2) 1/22 Outline 1 Recall from last week... 2 Recall: Output

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

### JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

Estd: 1994 JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli - 621014 (An approved by AICTE and Affiliated to Anna University) ISO 9001:2000 Certified Subject Code & Name : CS 1202

### C++ Input/Output: Streams

C++ Input/Output: Streams Basic I/O 1 The basic data type for I/O in C++ is the stream. C++ incorporates a complex hierarchy of stream types. The most basic stream types are the standard input/output streams:

### Collected By Anonymous

CS201- Introduction to Programming Mega Collection for Final Term Only Solved Paper Year Session Paper # 01 2012 Unknown Paper # 02 2011 (session_02) Paper # 03 2011 (session_03) Paper # 04 2010 Unknown

### Chapter 3 - Notes Input/Output

Chapter 3 - Notes Input/Output I. I/O Streams and Standard I/O Devices A. I/O Background 1. Stream of Bytes: A sequence of bytes from the source to the destination. 2. 2 Types of Streams: i. Input Stream:

### Lecture 3. Input and Output. Review from last week. Variable - place to store data in memory. identified by a name should be meaningful Has a type-

Lecture 3 Input and Output Review from last week Variable - place to store data in memory identified by a name should be meaningful Has a type- int double char bool Has a value may be garbage change value

C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

Come and join us at WebLyceum For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc Go to http://www.weblyceum.com and click Register In Case of any Problem Contact Administrators Rana Muhammad

### Work relative to other classes

Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language

### CS201 Some Important Definitions

CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data

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

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

### ! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

Week 1 Operators, Data Types & I/O Gaddis: Chapters 1, 2, 3 CS 5301 Fall 2016 Jill Seaman Programming A program is a set of instructions that the computer follows to perform a task It must be translated

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

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

### C++ Programming: From Problem Analysis to Program. Design, Fifth Edition. Chapter 1: An Overview of Computers and Programming Languages

C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages Updated by: Malak Abdullah The Evolution of Programming Languages (cont'd.)

### Differentiate Between Keywords and Identifiers

History of C? Why we use C programming language Martin Richards developed a high-level computer language called BCPL in the year 1967. The intention was to develop a language for writing an operating system(os)

### Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

Computer Systems Computer System Computer Structure C++ Environment Imperative vs. object-oriented programming in C++ Input / Output Primitive data types Software Banking System Compiler Music Player Text

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

### LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

LESSON 5 ARITHMETIC DATA PROCESSING The arithmetic data types are the fundamental data types of the C language. They are called "arithmetic" because operations such as addition and multiplication can be

### Chapter 2 - I know what I want to do NOW WHAT? Student Learning Outcomes (SLOs)

Chapter 2 - I know what I want to do NOW WHAT? Student Learning Outcomes (SLOs) a. You should be able to list two significant characteristics for each of the basic data types (bool, int, double, and char).

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

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

### Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

### Chapter 15 - C++ As A "Better C"

Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

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

### Introduction to C++ Dr M.S. Colclough, research fellows, pgtas

Introduction to C++ Dr M.S. Colclough, research fellows, pgtas 5 weeks, 2 afternoons / week. Primarily a lab project. Approx. first 5 sessions start with lecture, followed by non assessed exercises in

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

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

### Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. 9 Self-Test Exercises p. 11 History Note p. 12 Programming and

### Chapter 2. Lexical Elements & Operators

Chapter 2. Lexical Elements & Operators Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr The C System

### CS2141 Software Development using C/C++ Stream I/O

CS2141 Software Development using C/C++ Stream I/O iostream Two libraries can be used for input and output: stdio and iostream The iostream library is newer and better: It is object oriented It can make

### Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Question No: 1 ( Marks: 2 ) Write a declaration statement for an array of 10

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

### 7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

KEY CONCEPTS COMP 10 EXPLORING COMPUTER SCIENCE Lecture 2 Variables, Types, and Programs Problem Definition of task to be performed (by a computer) Algorithm A particular sequence of steps that will solve

### Data Conversion & Scanner Class

Data Conversion & Scanner Class Quick review of last lecture August 29, 2007 ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor: Alexander Stoytchev Numeric Primitive Data Storing

### Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT Two Mark Questions UNIT - I 1. DEFINE ENCAPSULATION. Encapsulation is the process of combining data and functions

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

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

### UNIT-2 Introduction to C++

UNIT-2 Introduction to C++ C++ CHARACTER SET Character set is asset of valid characters that a language can recognize. A character can represents any letter, digit, or any other sign. Following are some

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

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