Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 11: Handling Real-World Data Entry.

Slides:



Advertisements
Similar presentations
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Advertisements

Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
16/24/2015 1:00 AM6/24/2015 1:00 AM6/24/2015 1:00 AMStreams and Files All the data used in our programs so far has been entered through the keyboard and.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Introduction to C++ Programming
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
1 CS161 Introduction to Computer Science Topic #3.
Introduction to C++ Version 1.1. Topics C++ Structure Primitive Data Types I/O Casting Strings Control Flow.
L function n predefined, programmer-defined l arguments, (formal) parameters l return value l function call, function invocation l function definition.
Lecture #6 OPERATORS AND ITS TYPES By Shahid Naseem (Lecturer)
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Lecture 19 CIS 208 Wednesday, April 06, Welcome to C++ Basic program style and I/O Class Creation Templates.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
1 8/31/05CS150 Introduction to Computer Science 1 Hello World!
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
CSE 1341 Honors Note Set 2 1. Overview  Java vs. C++  Functions in C++  First Programming Packet  Development Environment 2.
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
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.
Learners Support Publications Introduction to C++
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
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
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Today’s Lecture  I/O Streams  Console I/O  File I/O  Tools for File I/O  Sequential.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Computer Programming II Lecture 9. Files Processing - We have been using the iostream standard library, which provides cin and cout methods for reading.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني I/O and File management Concept of streams. cin and cout objects. C++stream classes. Unformatted I/O.
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.
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.
CS212: Object Oriented Analysis and Design
Bill Tucker Austin Community College COSC 1315
Chapter 1.2 Introduction to C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
What Is? function predefined, programmer-defined
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Basic Elements of C++.
CSC 113: Computer Programming (Theory = 03, Lab = 01)
COMP 2710 Software Construction File I/O
Copyright © 2003 Pearson Education, Inc.
week 1 - Introduction Goals
Basic Elements of C++ Chapter 2.
Standard Input/Output Streams
Standard Input/Output Streams
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.
Programming with Data Files
Today’s Lecture I/O Streams Tools for File I/O
Chapter 3: Input/Output
Mr. Dave Clausen La Cañada High School
Chapter 2: Introduction to C++.
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Lecture 2 Fall 2011 September 13-15, 2011 Ghufran Ahmed
CHAPTER 4 File Processing.
C++ Programming Basics
C++ Programming Lecture 20 Strings
What Is? function predefined, programmer-defined
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Chapter 1 c++ structure C++ Input / Output
4.1 Introduction Arrays A few types Structures of related data items
Presentation transcript:

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 11: Handling Real-World Data Entry

In This Lesson We Will: Use pre-processor #defines to declare global constants Use pre-processor #defines to declare global constants Read data from a file Read data from a file Write data to a file Write data to a file Address the formatting of input and output with respect to I/O streams Address the formatting of input and output with respect to I/O streams

Topic Pre-Processor Directives

The Pre-Processor Recall our discussion of the way the C++ compiler works: though we often treat it as a single operation, there are discreet steps within the process Recall our discussion of the way the C++ compiler works: though we often treat it as a single operation, there are discreet steps within the process pre-processor step pre-processor step compilation step compilation step link step link step #include allows the use of external code within our programs #include allows the use of external code within our programs

#define The #define directive is used to assign a value to a symbolic name. The #define directive is used to assign a value to a symbolic name. Generally placed outside any functions Generally placed outside any functions With the way a #define is used, the scope usually propagates throughout the program With the way a #define is used, the scope usually propagates throughout the program Most often used for global constants Most often used for global constants The const declaration is preferred, except for special purposes The const declaration is preferred, except for special purposes

Special Purposes One candidate is for system-specific information One candidate is for system-specific information Another is for controlling the inclusion of files in compilation Another is for controlling the inclusion of files in compilation We will see some of the former today We will see some of the former today We will see the latter when we begin dividing our code across multiple files We will see the latter when we begin dividing our code across multiple files

Topic Reading Input and Writing Output

Standard Objects The iostream library defines objects which may be used for console I/O The iostream library defines objects which may be used for console I/O cout for output cout for output cin for input cin for input Familiar operators: Familiar operators: << is the insertion operator << is the insertion operator >> is the extraction operator >> is the extraction operator The endl object starts a new line The endl object starts a new line Objects defined by the system Objects defined by the system

Other Functions The cout object allows you to put data one character at a time: The cout object allows you to put data one character at a time:cout.put(aChar); The cin object allows you to get data one character at a time: The cin object allows you to get data one character at a time:cin.get(aChar); Also offers a special (Boolean) function to test for the end of a file: Also offers a special (Boolean) function to test for the end of a file:cin.eof();

Worth Noting The eof() function returns true after the EOF character is read by get() The eof() function returns true after the EOF character is read by get() The extraction operator generally ignores whitespace The extraction operator generally ignores whitespace The get() function does not The get() function does not

Food For Thought This class has de-emphasized input filtering; generally we expect that the extraction operator will give valid data This class has de-emphasized input filtering; generally we expect that the extraction operator will give valid data Imagine using the cin.get() function to parse every character Imagine using the cin.get() function to parse every character

Topic Non-Standard I/O Streams

File I/O The standard I/O objects represent the terminal and keyboard The standard I/O objects represent the terminal and keyboard Also may want to use files for I/O Also may want to use files for I/O Represent the files as stream objects similar to cout and cin Represent the files as stream objects similar to cout and cin Access file streams using the fstream library Access file streams using the fstream library

Example Go back to the fundraiser assignment Go back to the fundraiser assignmentfundraiser assignmentfundraiser assignment Did you find it painful to enter values for testing? Did you find it painful to enter values for testing? Come up with a set of values we can use for that purpose and save it in a file Come up with a set of values we can use for that purpose and save it in a file Modify your program so that it will open the file, read from it, then write to another Modify your program so that it will open the file, read from it, then write to another FundContribs.txt FundContribs.txt FundResults.txt FundResults.txt

Topic Formatting Output

Console Formatting GUI interfaces have changed the way formatting is handled in the real world GUI interfaces have changed the way formatting is handled in the real world However, here are some formatting operators provided by the iomanip library However, here are some formatting operators provided by the iomanip library setw(int n) setw(int n) setprecision(int n) setprecision(int n) left left right right

In This Lesson We Have: Used pre-processor #defines to declare global constants Used pre-processor #defines to declare global constants Read data from a file Read data from a file Written data to a file Written data to a file Addressed the formatting of input and output with respect to I/O streams Addressed the formatting of input and output with respect to I/O streams