Math Library and IO formatting

Slides:



Advertisements
Similar presentations
Dale/Weems/Headington
Advertisements

1 Algorithms Basic Control Structures Comparisons and if (…) statement What is a function? Math Library Functions Character Functions Reading Sample Programs.
I/O Streams as an Introduction to Objects and Classes
I/O and Program Control Statements Dick Steflik. Overloading C++ provides two types of overloading –function overloading the ability to use the same function.
Programming Stream Manipulators. COMP102 Prog. Fundamentals I: Stream Manipulator Slide 2 Stream Manipulators in iostream.h Library I/O stream manipulators.
1 Lecture 6 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
1 Lecture 6: Input/Output (II) Introduction to Computer Science Spring 2006.
1 Lecture 14:User-Definded function I Introduction to Computer Science Spring 2006.
1 Engineering Problem Solving with C++ An Object Based Approach Chapter 2 Simple C++ Programs.
1 Chapter 3 Topics Constants of Type int and float l Evaluating Arithmetic Expressions l Implicit Type Coercion and Explicit Type Conversion l Calling.
Functions and methods A method is a function that is a member of a class A method is a function that is a member of a class FCL(Framework Class Library)
1 CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
CSE202: Lecture 8The Ohio State University1 Formatting Numbers for Output.
1 9/26/07CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
1 Lecture 7 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Chapter 3: Input/Output
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) MATH Functions in C Language.
Numeric Types, Expressions, and Output 1. Chapter 3 Topics Constants of Type int and float Evaluating Arithmetic Expressions Implicit Type Coercion and.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems.
1 Chapter 3 Numeric Types, Expressions, and Output CS185/09 - Introduction to Programming Caldwell College.
CSE1222: Lecture 9The Ohio State University1. Formatting Numbers for Output  Number formatters are to be used in conjunction with cout  For example,
Output Formatting. Precision #include... float grade = f; cout.precision(4); cout
STANDARD FUNCTIONS Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Output Formatting No, I don't want 6 digits…. Standard Behavior Rules for printing decimals: – No decimal point: prints as 1 – No trailing zeros:
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 3 Formatting Output.
Chapter 6 User-Defined Functions I. Objectives Standard (predefined) functions What are they, and How to use them User-Defined Functions Value returning.
1 Chapter 3 Numeric Types, Expressions, and Output.
Chapter 3 Arithmetic Expressions, Function Calls, and Output
Input/Output Sujana Jyothi C++ Workshop Day 2. C++ I/O Basics 2 I/O - Input/Output is one of the first aspects of programming that needs to be mastered:
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Visual Basic I Programming
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
CSCI 125 & 161 / ENGR 144 Lecture 8 Martin van Bommel.
Formatting Output  Escape Sequences  iomanip.h Objects  setw()  setiosflags(…)  setprecision()
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.
1 Manipulators manipulators are used only in input and output statements endl, fixed, showpoint, setw, and setprecision are manipulators that can be used.
2/4/2016Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs.
C++ Data Types Check sample values of? ‘4’
USING & CREATING FUNCTIONS. MODULAR PROGRAMMING  Why Modular Programming?  Improves Readability & Understandability  Improve Maintainability  Allows.
Recursion It is a process of calling the same function itself again and again until some condition is satisfied. Syntax: func1() { ……….. func1(); }
Mathematical Manipulation Data types Operator precedence Standard mathematical functions Worked examples.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
CSCI 125 & 161 / ENGR 144 Lecture 6 Martin van Bommel.
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.
Chapter 3 Numeric Types, Expressions, and Output
Today Variable declaration Mathematical Operators Input and Output Lab
Introduction to C++ (Extensions to C)
C++ Basic Input and Output (I/O)
CS102 Introduction to Computer Programming
C++.
BIL 104E Introduction to Scientific and Engineering Computing
Chapter 3 L7.
EGR 2261 Unit 3 Input/Output Read Malik, Chapter 3.
Chapter 21 - C++ Stream Input/Output Stream Manipulators
Output Stream Formatting
FUNCTIONS EXAMPLES.
Copyright © 2012 Pearson Education, Inc.
Lecture 2B Expressions Richard Gesick
Input/Output Handouts: Quiz 2, Unit 3 practice sheets.
Using Free Functions Chapter 3 Computing Fundamentals with C++
Basic Input and Output C++ programs can read and write information using streams A simple input stream accepts typed data from a keyboard A simple output.
بسم الله الرحمن الرحيم.
Chapter 5 Input and Output Streams
Formatting the Output The C++ standard library supplies many manipulators: endl, setw, fixed, showpoint, setprecesion. If we want to use endl, fixed, or.
Chapter 4 INPUT AND OUTPUT OBJECTS
Let’s all Repeat Together
class 5 retrieving a previous statement in Thonny or IDLE // %
Output Formatting Bina Ramamurthy 4/16/2019 BR.
Output Formatting Bina Ramamurthy 9/25/2019 BR.
Presentation transcript:

Math Library and IO formatting B. Ramamurthy

Functions in <cmath> abs(x) computes absolute value of x sqrt(x) computes square root of x, where x >=0 pow(x,y) computes xy ceil(x) nearest integer larger than x floor(x) nearest integer smaller than x exp(x) computes ex log(x) computes ln x, where x >0 log10(x) computes log10x, where x>0 sin(x) sine of x, where x is in radians cos(x) cosine of x, where x is in radians tan(x) tangent of x, where x is in radians

Manipulators and methods setf() and unsetf() Flag Meaning ios:: showpoint display the decimal point ios::fixed fixed decimal notation ios::scientific scientific notation ios::right right justification ios::left left justification Manipulators in <iomanip> setprecision(n) setw(n)

Using IO manipulators #include <iostream> #include <iomanip> #include <cmath> using namespace std; const double PI=acos(-1.0); int main() { // Declare and initialize objects. double radius(4.6777), area; area = PI*radius*radius; cout << setprecision(4) << "The radius of the circle is: " << setw(10) << radius << " centimeters" << endl; cout.setf(ios::scientific); cout << "The area of the circle is: " << setw(12) << area << " square centimeters" << endl; return 0; }

Lab2 Applying the concepts.