Chapter 3, Part 2 s Input: cin s Example programs.

Slides:



Advertisements
Similar presentations
This Time Whitespace and Input/Output revisited The Programming cycle Boolean Operators The “if” control structure LAB –Write a program that takes an integer.
Advertisements

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
1 9/13/06CS150 Introduction to Computer Science 1 Type Casting.
1 Objectives Understand streamed input and output.
Chapter 3 Assignment and Interactive Input. 2 Objectives You should be able to describe: Assignment Operators Mathematical Library Functions Interactive.
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
Input/Output Main Memory istream ostream Disk Drive Keyboard Scanner Disk Drive Monitor Printer stream = sequence of bytes.
1 10/29/07CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
1 Lecture 5: Input/Output (I) Introduction to Computer Science Spring 2006.
Chapter 3 Assignment and Interactive Input
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
Chapter 3: Input/Output
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
19/5/2015CS150 Introduction to Computer Science 1 Announcements  1st Assignment due next Monday, Sep 15, 2003  1st Exam next Friday, Sep 19, 2003  1st.
Variables, Data Types and Constants Yared Semu Addis Ababa Institute of Technology Mar 31, 2012.
1 Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 2 Primitive Data Types and Operations.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 2 Elementary Programming.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
1 Last of the basics Controlling output Overflow and underflow Standard function libraries Potential pitfalls of getting information with cin Type casting.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
CSE 100 s s Input: cin s type casting Math Library Functions math.h sqrt(n) fabs(n) cos(n) log10(n) log(n) pow(b, n) etc. * * *
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ Programming: Basic Elements of C++.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Chapter 05 (Part III) Control Statements: Part II.
A FIRST BOOK OF C++ CHAPTER 3 ASSIGNMENT AND INTERACTIVE INPUT.
Chapter 2: Introduction to C++. Language Elements Keywords Programmer-defined symbols (identifiers) Operators Punctuation Syntax Lines and Statements.
E-1 University of Washington Computer Programming I Lecture 5: Input and Output (I/O) © 2000 UW CSE.
Operating System Using setw and setprecision functions Using setiosflags function Using cin function Programming 1 DCT
Programming Fundamentals with C++1 Chapter 3 COMPLETING THE BASICS.
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
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.
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Chapter 3 – Variables and Arithmetic Operations. First Program – volume of a box /************************************************************/ /* Program.
Program Input and the Software Design Process ROBERT REAVES.
Input/Output. Objectives In this chapter you will: Learn what a stream is and examine input and output streams Explore how to use the input stream functions.
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
CS201 Introduction to Sabancı University 1 Chapter 2 Writing and Understanding C++ l Writing programs in any language requires understanding.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
LESSON 2 Basic of C++.
arithmetic operator & cin I.Mona Alshehri The output formatting functions setw(width) setw(n) - output the value of the next expression in n columns.
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.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
Bill Tucker Austin Community College COSC 1315
Chapter 3 Assignment and Interactive Input.
Computing Fundamentals
Chapter 2 Assignment and Interactive Input
BASIC ELEMENTS OF A COMPUTER PROGRAM
Data Streams.
Chapter 2 Elementary Programming
Chapter 3: Input/Output
Wednesday 09/23/13.
Chapter 3 Input output.
CSE 100 Input: cin type casting.
Common Programming Errors Assignment Statements
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
What Actions Do We Have Part 1
Reading from and Writing to Files
Reading from and Writing to Files
Presentation transcript:

Chapter 3, Part 2 s Input: cin s Example programs

Cin Object – Reading in Data cin >> my_num; The keyboard entry is stored into a local variable called my_num. Read as: “get from my_num”.

Examples of cin cin >> var1; Syntax: cin >> var1; Examples: cin >> last_name;// string cin >> ch;// character cin >> my_id#;// number * Can only determine data types by declaration statement

Multiple cin on One Line cin >> var1 >> var2 >>... Syntax: cin >> var1 >> var2 >>... cin >> First >> Last >> MyNum; * cin >> qz1 >> qz2 >> qz3 >> qz4; cin >> First; cin >> Last; cin >> MyNum; cin >> qz1 >> qz2 >> qz3 >> qz4;

cin & cout standard device standard device (keyboard) (screen) main() { cout << cin >> }

cin & cout cout cin > insertion extraction “put to” “get from” For input: whitespace characters used as a separator, otherwise ignored

cin Example 1 int num1, num2, num3; double average; cout << "Enter three integer numbers: "; cin >> num1 >> num2 >> num3; average = (num1 + num2 + num3) / 3.0; cout << "The average is " << average; cout << '\n';

cin Example 1 Output: The average is

cin Example 2 double radius, circumference; double pi = ; cout << "Enter the radius of a circle: "; cin >> radius; circumference = 2 * pi * radius; cout << "The circumference of a circle of radius " << radius << " is " << circumference <<‘\n’;

cin Example 2 Output: Enter the radius of a circle: 14 The circum... circle of radius 14 is

cin Example 3 double celsius, faren; cout <<"Enter the temperature in degrees Fahrenheit: "; cin >> faren; celsius = 5.0/9.0 * (faren ); cout << faren <<" degrees Fahrenheit equals "<< celsius << " degrees celsius.\n";

cin Example 3 Output: Enter the temperature in degrees Farenheit: degrees Farenheit equals degrees celsius.

const Qualifier Revisited const DataType Name = Literal Value; Syntax: const DataType Name = Literal Value; Examples const double PI = ; const double OT_RATE = 1.5; * Protected from change within the program Don’t believe me… try it! PI = ;cin >> OT_RATE;

const Qualifier double radius, area; const double PI = cout > radius; cout << “The area of your circle is “ << PI * radius * radius; * How can that last statement be rewritten using pow?

Common Programming Errors 3 not initializing variables before use >> 3 forgetting >> to separate variables in cin applying ++ or -- to an expression (x-y)++

Why isn’t phonetic spelled as it sounds? Why do they put Braille dots on the keypad of a drive-up ATM? How many Microsoft technicians does it take to change a light bulb? How many Microsoft technicians does it take to change a light bulb? Three: two holding the ladder and one to screw the bulb into a faucet. “Lack of brains hinders research” The Columbus Dispatch, 16 April 1996