FALL 2001ICOM 4015 - Lecture 11 ICOM 4015 Advanced Programming Lecture 1 Computer/Human Interaction Readings: LMM 2.3 & 3.3 Prof. Bienvenido Velez.

Slides:



Advertisements
Similar presentations
Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Advertisements

CPS120: Introduction to Computer Science INPUT/OUTPUT.
Computer Science 1620 Loops.
1 Lecture 6: Input/Output (II) Introduction to Computer Science Spring 2006.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
C++ Numerical Data Input/Output Programming. COMP 102 Prog Fundamentals I:C++ Numerical Data, Input/Output /Slide 2 Rules for Division l C++ treats integers.
1 CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 3: Input/Output.
1 9/26/07CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
Lecture 17: 10/29/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Input and Output in Console Mode UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.
Chapter 3 COMPLETING THE BASICS Programming Fundamentals with C++1.
M. Taimoor Khan #include void main() { //This is my first C++ Program /* This program will display a string message on.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 3: Input/Output.
Lecture 6: Expressions and Interactivity (Part II) Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Output Formatting No, I don't want 6 digits…. Standard Behavior Rules for printing decimals: – No decimal point: prints as 1 – No trailing zeros:
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output.
I/O and Data Formatting Introduction to Class Concepts INFSY 307 Spring 2003 Lecture 3.
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:
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
CSC 107 – Programming For Science. Announcements.
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 3: Input/Output
Lecture 4 Function example. Example1 int max (int a, int b) { int c; if (a > b) c = a; else c = b; return (c); } void main ( ) {int x, y; cin>>x>>y; cout.
Chapter 3 Working with Batches of Data. Objectives Understand vector class and how it can be used to collect, store and manipulate data. Become familiar.
FALL 2001ICOM Lecture 01 ICOM 4015 Advanced Programming Lecture 0 Review of Programming I Reading: LNN Chapters 1-3,5-6.
Chapter -7 Basic function of Input/output system basics and file processing Stream classes : I/O Streams. A stream is a source or destination for collection.
11/10/2016CS150 Introduction to Computer Science 1 Last Time  We covered “for” loops.
Operating System Using setw and setprecision functions Using setiosflags function Using cin function Programming 1 DCT
Arrays Dr. Jose Annunziato. Arrays Up to this point we have been working with individual primitive data types Arrays allow working with multiple instances.
Programming Fundamentals with C++1 Chapter 3 COMPLETING THE BASICS.
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.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
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.
INPUT & OUTPUT 10/20/2016Department of Computer Science, UOM | Introduction | Fakhre Alam.
Introduction Every program takes some data as input and generate processed data as out put . It is important to know how to provide the input data and.
Basic concepts of C++ Presented by Prof. Satyajit De
Topic 2 Input/Output.
Introduction to C++ (Extensions to C)
What Actions Do We Have Part 1
Programming Fundamentals
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Chapter 2 part #3 C++ Input / Output
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.
Counting Loops.
Chapter 3: Input/Output
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Introduction to cout / cin
Chapter 3 Input output.
Formatting the Output The C++ standard library supplies many manipulators: endl, setw, fixed, showpoint, setprecesion. If we want to use endl, fixed, or.
Review for Midterm Exam
Review for Midterm Exam
Review for Midterm Exam
Fundamental Programming
Chapter 2 part #3 C++ Input / Output
C++ Programming Basics
Introduction to cout / cin
CS150 Introduction to Computer Science 1
Presentation transcript:

FALL 2001ICOM Lecture 11 ICOM 4015 Advanced Programming Lecture 1 Computer/Human Interaction Readings: LMM 2.3 & 3.3 Prof. Bienvenido Velez

FALL 2001ICOM Lecture 12 Computer/Human Interaction Outline Output Streams Input Streams Formatting output

FALL 2001ICOM Lecture 13 Layered Software Design Library/Component Appl Programming Interface (API) GUI Text-based Interactive Interface Text-based Batch Interface ICOM 4015

FALL 2001ICOM Lecture 14 Example 1 Simple output program * ** *** **** ***** ****** ******* ******** ********* #include main() { for(int i=0; i<10; i++) { for(int j=0; j<i; j++) { cout << "*"; } cout << endl; } example1.cc output

FALL 2001ICOM Lecture 15 Output Stream insertion operator cout << expression output stream insertion operator argument expression returns an output stream

FALL 2001ICOM Lecture 16 Example 2 0 stars * 1 stars ** 2 stars *** 3 stars **** 4 stars ***** 5 stars ****** 6 stars ******* 7 stars ******** 8 stars ********* 9 stars #include main() { for(int i=0; i<10; i++) { for(int j=0; j<i; j++) { cout << "*"; } cout << " " << i << " stars"; cout << endl; } example2.cc output

FALL 2001ICOM Lecture 17 Input Stream extraction operator cin >> variable input stream extraction operator argument expression returns an input stream

FALL 2001ICOM Lecture 18 Example 3 ~ >> example3 Enter number of rows: 7 0 stars * 1 stars ** 2 stars *** 3 stars **** 4 stars ***** 5 stars ****** 6 stars ~ >> #include main() { int entered; cout << “Enter number of rows: "; cin >> entered; for(int i=0; i<entered; i++) { for(int j=0; j<i; j++) { cout << "*"; } cout << " " << i << " stars"; cout << endl; } example3.cc shell

FALL 2001ICOM Lecture 19 Example 4 ~ >> example4 Enter number of rows(-1 to end): 5 0 stars * 1 stars ** 2 stars *** 3 stars **** 4 stars Please enter an integer (-1 to end): -1 ~ >> #include main() { while (true) { cout << " Enter number of rows (-1 to end): "; int entered; cin >> entered; if (entered == -1) { break; } for(int i=0; i<entered; i++) { for(int j=0; j<i; j++) { cout << "*"; } cout << " " << i << " stars"; cout << endl; } example4.cc shell

FALL 2001ICOM Lecture 110 Example 5 I/O Manipulators extern "C"{ #include } #include main() { int rows = 0; cout << "Please enter number of rows: "; cin >> rows; int columns = 0; cout << "Please enter number of columns: "; cin >> columns; unsigned int seed = 511; srand (seed); for (int i=0; i<rows; i++) { for (int j=0; j<columns; j++) { cout << setprecision(4) // prints only 4 decimal digits << setw(10) // prints each number is field of 10 spaces << setfill('*') // fills empty spaces with '*' << rand()/float(RAND_MAX) << " "; } cout << endl; } ~/icom4015/lec2 >>./example5 Please enter number of rows: 5 Please enter number of columns: 5 **** **** *** **** **** **** *****0.756 **** **** **** **** **** **** **** **** **** *****0.583 **** *** *** **** **** **** **** **** ~/icom4015/lec02 >> example5.cc shell

FALL 2001ICOM Lecture 111 Example 6 Computing Statistics in One Pass ~/icom4015/lec02 >> example6 Please enter a number (-1 to end): 5 Please enter a number (-1 to end): 6 Please enter a number (-1 to end): 7 Please enter a number (-1 to end): 8 Please enter a number (-1 to end): -1 Statistics: Average: 6.5 Count: 4 Max: 8 Min: 5 ~/icom4015/lec02 >> #include main() { float nextNumber; float sum = 0; float count = 0; float max; float min; bool firstTime = true; while (true) { cout << "Please enter a number (-1 to end): "; cin >> nextNumber; if (nextNumber == -1) { break; } sum += nextNumber; count++; if (firstTime) { max = nextNumber; min = nextNumber; firstTime = false; } else { max = (max < nextNumber) ? nextNumber : max; min = (min > nextNumber) ? nextNumber : min; } cout << "Statistics:" << endl; cout << "Average: " << sum / count << endl; cout << "Count: "<< count << endl; cout << "Max: " << max << endl; cout << "Min: " << min << endl; } example6.cc shell

FALL 2001ICOM Lecture 112 Example 6 With Input redirection ~/icom4015/lec02 >> example6 < example6.txt Please enter a number (-1 to end): Please enter a number (-1 to end): Please en\ ter a number (-1 to end): Please enter a number (-1 to end): Please enter a num\ ber (-1 to end): Statistics: Average: 6.5 Count: 4 Max: 8 Min: 5 ~/icom4015/lec02 >> example6.txt shell

FALL 2001ICOM Lecture 113 Example 6 With Input/Output redirection ~/icom4015/lec02 >> example6 example6.out ~/icom4015/lec02 >> shell Please enter a number (-1 to end): Please enter a number (-1 to end): Please en\ ter a number (-1 to end): Please enter a number (-1 to end): Please enter a num\ ber (-1 to end): Statistics: Average: 6.5 Count: 4 Max: 8 Min: 5 example6.txt example1.out

FALL 2001ICOM Lecture 114 Summary of Concepts Fundamentals Computer-Human Interaction is a subarea of study in its own right within Computer Science One pass computing - Process input as you read it. Less memory required to store data. Limited algorithmic expressiveness. Input redirection allows me to store input input in a file. Helpful for debugging because don’t need to re-enter test input every time. Output redirection allows me to dump the output of a program to a file. A file can be examined, saved, ed, …

FALL 2001ICOM Lecture 115 Summary of Concepts Language Issues Language issues –Must #include –Stream insertion operators can be chained. Example: (cout << expr1) << expr2 –Stream extraction operator can be chained. Example: (cin >> var1) >> var2 –I/O manipulators provide fine-grain control over format of output setprecision – decimal digits setw – width of output field setfill – filler for empty space