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

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

1 MATH METHODS THAT RETURN VALUES. 2 JAVA'S MATH CLASS.
Computer Programming w/ Eng. Applications
Chapter 3: Expressions and Interactivity. Outline cin object Mathematical expressions Type Conversion and Some coding styles.
1 9/13/06CS150 Introduction to Computer Science 1 Type Casting.
Chapter 3 Assignment and Interactive Input. 2 Objectives You should be able to describe: Assignment Operators Mathematical Library Functions Interactive.
1 Lecture 6 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Copyright © 2012 Pearson Education, Inc. Chapter 3: Expressions and Interactivity.
C++ Typecasting. Math Library Functions.. Operator / Operands A = x + y.
1 Lecture 5: Input/Output (I) Introduction to Computer Science Spring 2006.
1 Chapter 3 Topics Constants of Type int and float l Evaluating Arithmetic Expressions l Implicit Type Coercion and Explicit Type Conversion l Calling.
Chapter 3 Assignment and Interactive Input
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 3: Expressions and Interactivity.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
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.
Data Types, Expressions and Functions (part I)
Expressions and Interactivity Chapter 3. 2 The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Often.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems.
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.
1 Chapter 8 Scope, Lifetime, and More on Functions Dale/Weems/Headington.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
計算機程式語言 Lecture 03-1 國立臺灣大學生物機電系 3 3 Assignment, Formatting, and Interactive Input.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
C++ Programming: Basic Elements of C++.
Chapter 3, Part 2 s Input: cin s Example programs.
A FIRST BOOK OF C++ CHAPTER 3 ASSIGNMENT AND INTERACTIVE INPUT.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Chapter 3: Assignment, Formatting, and Interactive Input.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
C++ for Engineers and Scientists Second Edition Chapter 3 Assignment, Formatting, and Interactive Input.
Chapter 3.1 & 3.2 s Programming s Assignment Statements s Incrementing & Decrementing s Math Library Functions.
C++ Programming, Namiq Sultan1 Chapter 3 Expressions and Interactivity Namiq Sultan University of Duhok Department of Electrical and Computer Engineerin.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Expressions and Interactivity. 3.1 The cin Object.
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.
Recap……Last Time [Variables, Data Types and Constants]
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
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.
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
C++ Data Types Check sample values of? ‘4’
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
Functions. Predefined Functions C++ comes with libraries of code that can be reused in your programs. The code comes in the form of predefined functions.
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
Introduction to Programming Lecture 6. Functions – Call by value – Call by reference Today's Lecture Includes.
Introduction to Computer Programming. MS Sadia Ejaz CIIT ATTOCK Identifiers The identifiers are the names used to represent variable, constants, types,
LESSON 2 Basic of C++.
1 Lecture Three I/O Formatting and Arithmetic Dr. Sherif Mohamed Tawfik.
Chapter 4: Introduction To C++ (Part 3). The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Information.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3: Expressions and Interactivity.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
arithmetic operator & cin I.Mona Alshehri The output formatting functions setw(width) setw(n) - output the value of the next expression in n columns.
SCP1103 Basic C Programming SEM1 2010/2011 Arithmetic Expressions Week 5.
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.
Arithmetic Expressions
Chapter 3 Assignment and Interactive Input.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Enum ,Char Functions& Math Library Functions I.Mona Alshehri
Chapter 2 Elementary Programming
A First Book of ANSI C Fourth Edition
Chapter 3: Input/Output
Wednesday 09/23/13.
CSE 100 Input: cin type casting.
Common Programming Errors Assignment Statements
C++ Programming Basics
Chapter 3 The New Math.
Presentation transcript:

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

Math Library Functions name of the function what it does data type of argument data type of returned value

Math Library Functions function_name (argument); Syntax: function_name (argument); Ex.sqrt(49) pow(2.1, 3) abs(-34.5) cos(30) abs(34.5) *

Math Library Functions nested functions sqrt( pow ( fabs (-4), 3) ) = sqrt( pow ( 4.0, 3) ) = sqrt( 64.0 ) = 8.0 * * *

Type Casting The explicit conversion of a value from one data type to another. data_type (expression) Syntax: data_type (expression) * int (5.34 * 1.68) int (8.9712) This returns a value of 8.

Type Casting someInt = someDouble - 8.2; someInt = int(someDouble - 8.2); These are identical statements. *

Type Coercion The implicit (automatic) conversion of a value from one data type to another. someDouble = 42; is stored as 42.0 someInt = 11.9; is stored as 11 *

Math Function Example #include // needed for the exp function int year; long int population; year = 1995; population = 5.5 * exp(0.02*(year-1990)); cout << "The estimated population for " << year << " is "<<population << "."; year = 2012; cout << "The estimated population for " << year << " is "<< population <<".";

Math Function Example e 5.5 e.02(year-1900) 5.5 * exp ( 0.02*(year-1990) )

Math Function Example Output: The estimated population for 1995 is 6. The estimated population for 2012 is 8.

cin cin >> my_num; The keyboard entry is stored into a local variable called my_num. Read as: “get from my_num”.

cin cin >> var1; Syntax: cin >> var1; Examples: cin >> last_name; cin >> ch; cin >> my_id#; *

cin (concatenation) cin >> var1 >> var2 >>... Syntax: cin >> var1 >> var2 >>... cin >> first >> last >> my_num; * 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” whitespace characters 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 const DataType Name = Literal Value; Syntax: const DataType Name = Literal Value; Examples const double PI = ; const double OT_RATE = 1.5; *

const Qualifier double radius, area; const double PI = cout > radius; cout << “The area is your circle is “ << PI * radius * radius; *

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