Standard Input - Output

Slides:



Advertisements
Similar presentations
I/O: SPARC Assembly Department of Computer Science Georgia State University Georgia State University Updated Spring 2014.
Advertisements

Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
CS-1030 Dr. Mark L. Hornick 1 IOStreams revisited Streams, strings, and files.
CS1061 C Programming Lecture 16: Formatted I/0 A. O’Riordan, 2004.
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.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Unformatted and Formatted I/O Operations. 2 Unformatted Input/output is the most basic form of input/output. Unformatted I/O transfers the internal binary.
Input/Output in C++ C++ iostream.h instead of stdio.h Why change? –Input/output routines in iostream can be extended to new types declared by the user.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
Input and Output in Console Mode UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
© Janice Regan, CMPT 128, Sept CMPT 128: Introduction to Computing Science for Engineering Students C++ Basic Input and output.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Chapter 3 COMPLETING THE BASICS Programming Fundamentals with C++1.
Bit Manipulation when every bit counts. Questions on Bit Manipulation l what is the motivation for bit manipulation l what is the binary, hexadecimal,
C++ Streams Lecture-2.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
C++ Streams Lecture-2. C++ Streams Stream  A transfer of information in the form of a sequence of bytes I/O Operations:  Input stream: A stream that.
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 Simple Input/Output  C++ offers the iostream library, which defines a system of character-oriented Input/Output (I/O) using object oriented programming.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester 1436 King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah Alakeel.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Programming Fundamentals with C++1 Chapter 3 COMPLETING THE BASICS.
1 COMS 261 Computer Science I Title: Functions Date: October 24, 2005 Lecture Number: 22.
1 Manipulators manipulators are used only in input and output statements endl, fixed, showpoint, setw, and setprecision are manipulators that can be used.
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.
Input/Output in C++ C++ iostream.h instead of stdio.h Why change? –Input/output routines in iostream can be extended to new types declared by the user.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 2.
arithmetic operator & cin I.Mona Alshehri The output formatting functions setw(width) setw(n) - output the value of the next expression in n columns.
Formatted I/O ä ä Standard Output ä ä printf() family of functions ä ä Standard Input ä ä scanf() family of functions.
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
Introduction to C Programming II & Formatted Input/Output Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
INPUT & OUTPUT 10/20/2016Department of Computer Science, UOM | Introduction | Fakhre Alam.
Chapter 9 - Formatted Input/Output
C Formatted Input/Output
C++ Basic Input and Output (I/O)
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Functions, Part 2 of 2 Topics Functions That Return a Value
TMF1414 Introduction to Programming
Input & Output Operations
Chapter 18 I/O in C.
Introduction to C CSE 2031 Fall /3/ :33 AM.
Output Stream Formatting
Plan of the Day: More on type conversions scanf printf format strings
By: Syed Shahrukh Haider
Chapter 08- printf and scanf
C Formatted Input / Output Review and Lab Assignments
Ken D. Nguyen Department of Computer Science Georgia State University
توابع ورودي-خروجي.
Manipulators CSCE 121 J. Michael Moore
Chapter 9 - Formatted Input/Output
There are 10 types of people of people in this world…
Chapter 3: Input/Output
Chapter 4 Managing Input and Output Operations
Conversion Check your class notes and given examples at class.
Introduction to C Programming
Remember the 10 types of people of people in this world…
Ken D. Nguyen Department of Computer Science Georgia State University
Sequential Programming
Presentation transcript:

Standard Input - Output By: Muhammad Zidny Naf’an Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

Output Command cout() printf() puts() putchar() Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

cout() Show the data to screen We must include header file “iostream.h” Ex: Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

printf() Function declaration: printf(“string control”, argument1, argument2); Use header header “stdio.h” Data type Determining format Integer %d Float decimal form exponential decimal and exponential %f %e %g Double precission %lf Character %c String %s Unsigned integer %u Long integer %ld Long unsigned integer %lu Unsigned hexadecimal integer %x Unsigned octal integer %o Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

printf() Ex: Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

puts() Print the string in the screen Use “stdio.h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

putchar() Print a character to screen Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

Manipulation Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

endl() Insert new line Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

ends() Insert null character Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

dec, oct, hex Convert number to decimal, octal, and hexadecimal Use “iomanip.h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

setprecission() Formatting the number of decimal digit that will showed Use “iomanip.h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

setbase(base number) To convert decimal, hexadesimal, and octal. Base number: 10 for decimal, 8 for octal, 16 for hexdecimal Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

setw(int width) Set variable’s width in screen User “iomanip.h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

setfill(char character) Fill blank from setw with character Use iomanip.h Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

setiosflags() Formatting output Example: Align text in screen (align left or right) Using “iomanip.h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

Input Command cin scanf() gets() getch() getche() Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

cin Without formatting input Use “iostream.h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

scanf(“format setting”, &variable) Input data with formatting Data type Determining format Integer %d Float decimal form exponential %f %e Double precision %lf Character %c String %s Unsigned integer %u Long integer %ld Long unsigned integer %lu Unsigned hexadecimal integer %x Unsigned octal integer %o Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

scanf(“format setting”, variable) Example: Use “stdio.h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

gets(char[] string) Input string from keyboard Use “stdio.h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

getch() Stands for get character and echo Input one character, and we aren’t need push “enter” button to execute, and character will not be showed in screen Use “conio.h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

getch() Stands for get character and echo Input one character, and we aren’t need push “enter” button to execute, and character will be showed in screen Use “conio.h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

Exercise Write the program to count average from a student’s score. The are 3 scores. Average Formula = (score1+score2+ score3)/3 Input format: Output format: ********** INPUT SCORE ********* Name : <input> score 1 : <input> score 2 : <input> score 3 : <input> ********** AVERAGE SCORE ********* Name : <name> score 1 : <score1> score 2 : < score2> score 3 : < score3> Average: <average> Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012