C++ ReviewEECE 3521 EECS 352 Data Structures and Algorithms José M. Vidal Office: 3A47.

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
CMPUT 101 Lab # 5 October 22, :00 – 17:00.
I/O and Program Control Statements Dick Steflik. Overloading C++ provides two types of overloading –function overloading the ability to use the same function.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
Input/Output Main Memory istream ostream Disk Drive Keyboard Scanner Disk Drive Monitor Printer stream = sequence of bytes.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 3: Input/Output.
Streams, Files. 2 Stream Stream is a sequence of bytes Input stream In input operations, the bytes are transferred from a device to the main memory Output.
Basic Elements of C++ Chapter 2.
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Seventh.
CSIS 123A Lecture 5 Friend Functions Glenn Stevenson CSIS 113A MSJC.
Stream Handling Streams - means flow of data to and from program variables. - We declare the variables in our C++ for holding data temporarily in the memory.
Input & Output: Console
Chapter 3 COMPLETING THE BASICS Programming Fundamentals with C++1.
CS Class 13 Today  File I/O (reading from and writing to files)  Reading until EOF  Formatting output  Nested Loops Announcements  Programming.
Output Formatting. Precision #include... float grade = f; cout.precision(4); cout
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 3: Input/Output.
CSC 107 – Programming For Science. Announcements  Memorization is not important, but…  … you will all still be responsible for information  Instead.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ Streams Lecture-2.
1 Streams In C++, I/O occurs in streams. A stream is a sequence of bytes Each I/O device (e.g. keyboard, mouse, monitor, hard disk, printer, etc.) receives.
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.
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.
Fundamental File Processing Operations C++
1 Simple Input/Output  C++ offers the iostream library, which defines a system of character-oriented Input/Output (I/O) using object oriented programming.
CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 31 Thanks for Lecture Slides: C How to Program by Paul Deital &
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Sixth.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
Chapter 3: Input/Output
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.
C++ REVIEW INPUT/OUTPUT (I/O). BRIEF NOTE “CLASSES” AND “STRUCTS” AND “TYPES” They are ADTs… They define data and operations on that data The ADTs in.
#include int main() { char *string1=”C++”; char *string2=”Program”; int m=strlen(string1); int n=strlen(string2); for(int i=1;i
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 CSci 588: Data Structures, Algorithms and Software Design Fall 2011 All material not from online sources copyright © Travis Desell, 2011
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
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.
File I/O in C++ I. Using Input/Output Files A computer file is stored on a secondary storage device (e.g., disk); is permanent; can be used to provide.
CS116 SENEM KUMOVA METİN. Outline What is C++ ? Some features of C++ Input and Output Operations Manipulators C++ header files Namespaces and scope resolution.
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
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.
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.
C++ Lesson 1.
Today Variable declaration Mathematical Operators Input and Output Lab
Introduction to C++ (Extensions to C)
Chapter Topics The Basics of a C++ Program Data Types
Basics (Variables, Assignments, I/O)
Chapter 1.2 Introduction to C++ Programming
Chapter 2: Introduction to C++
CPS120: Introduction to Computer Science
Basic Elements of C++.
TMF1414 Introduction to Programming
Chapter 21 - C++ Stream Input/Output Stream Manipulators
Output Stream Formatting
Chapter 21 - C++ Stream Input/Output
Basic Elements of C++ Chapter 2.
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Chapter 3: Input/Output
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Chapter 3 Input output.
CSC 143 Stream I/O Classes and Files [A11-A15, A38-A50]
Chapter 4 INPUT AND OUTPUT OBJECTS
Engineering Problem Solving with C++ An Object Based Approach
CS150 Introduction to Computer Science 1
File I/O in C++ I.
Presentation transcript:

C++ ReviewEECE 3521 EECS 352 Data Structures and Algorithms José M. Vidal Office: 3A47

C++ ReviewEECE 3522 C++ Review Data types Input/Output Classes –Data abstraction (public/private) –Constructors/Destructors –Operator Overloading –Inheritance

C++ ReviewEECE 3523 C++ Data Types char1 byte short2 bytes int4 bytes long4 bytes float4 bytes double8 bytes bool 1 byte Signed and unsigned keywords can be used with char, short, int and long. Variations are possible: long double, long long, signed char, unsigned long...

C++ ReviewEECE 3524 Output #include Tell compiler that we are doing I/O cout Object to which we can send data. << Device for sending data. endl `\n’ `\t’ Special symbols that we can send.

C++ ReviewEECE 3525 Formatting Output ios::left left justify the output ios::right right justify the output ios::scientific use scientific notation for numbers ios::hex print numbers in hexadecimal base ios::dec print numbers in decimal base ios::uppercase print all characters in upper case cout.setf(long flag)cout.unsetf(long flag) Set different formatting parameters for next output. Disable these formatting parameters.

C++ ReviewEECE 3526 Example Code #include main() { cout.width(10); //sets width to 10 cout << “hello” << endl; cout.setf(ios::left); cout << “hello” << endl; cout << 16 << endl; cout.setf(ios::hex); cout << 16 << endl; } hello Output

C++ ReviewEECE 3527 Input #include Tell the linker we are doing basic I/O cin The input object. It retrieves input from the keyboard >> The extractor operator.

C++ ReviewEECE 3528 Example Code #include main () { int userInput; cout << “Enter number:”; cin >> userInput; cout << “You entered ” << userInput << endl; } Enter number:12345 You entered Output

C++ ReviewEECE 3529 I/O From a File I/O from a file is done in a similar way. #include main() { int inputNumber; ofstream myOutputFile(“outfile”); ifstream myInputFile(“infile”); myOutputFile << “text to file.” << endl; myInputFile >> inputNumber; }

C++ ReviewEECE Classes Provide a mechanism for defining classes of objects. –We can define the class of all computers to have certain characteristics. –An instance of a computer is your home PC. Classes contain member variables and member functions.

C++ ReviewEECE Classes and Objects Mammals Humans Tigers HankPeggy Tony class inherits instance-of

C++ ReviewEECE Example Class class human { // this data is private to instances of the class int height; char name[]; int weight; public: void setHeight(int heightValue); int getHeight(); }

C++ ReviewEECE Function Definitions void human::setHeight(int heightValue) { if (heightValue > 0) height = heightValue; else height = 0; } int human::getHeight() { return(height); }

C++ ReviewEECE Example Usage // first we define the variables. int height = 72; int result = 0; human hank; //set our human’s height hank.setHeight(height); //get his height result = hank.getHeight(); cout << “Hank is = “ << result << “inches tall” << endl; Hank is 72 inches tall Output