ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 4: Continuing with C++ I/O Basics.

Slides:



Advertisements
Similar presentations
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
Advertisements

Introduction Kingdom of Saudi Arabia Shaqra University
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
1 Copyright (C) 2008 by Dennis A. Fairclough all rights reserved.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 6: Continuing with output formatting.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics.
Chapter 1 Working with strings. Objectives Understand simple programs using character strings and the string library. Get acquainted with declarations,
Chapter 02 (Part III) Introduction to C++ Programming.
ECE 264 Object-Oriented Software Development Instructor: Dr. Michael Geiger Spring 2009 Lecture 2: Basic C++ Programs.
CSC 107 – Programming For Science. Announcements  Memorization is not important, but…  … you will all still be responsible for information  Instead.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Fall 2012 Lecture 8: File I/O; Introduction to classes.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 2: Software Design Cycle.
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.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 5: Continuing with C++ I/O Basics.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 31: Operator overloading examples, inheritance intro.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 22: Pointers.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 11: Class diagrams; class relationships.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 9: Continuing with classes.
 for loop  while loop  do-while loop for (begin point; end point ; incrementation ) { //statements to be repeated }
1 EECS230 Course Introduction and a First Program Ying Wu Electrical Engineering and Computer Science Northwestern University
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 29: Operator overloading.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 5: Continuing with output formatting.
C++ Programming Lecture 13 Functions – Part V The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
C++ Programming Lecture 14 Arrays – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 20: Container classes; strings.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Lecture 4: Part1 Arrays Introduction Arrays  Structures of related data items  Static entity (same size throughout program)
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 19: Abstract Classes.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 19: Container classes; strings.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 13: Exam 1 Preview.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 2: Software Design Cycle, Requirements Specification and.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1: Introduction to computers and C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
ECE 264 Object-Oriented Software Development
Two-Dimensional Arrays Lesson xx
Introduction to C++ October 2, 2017.
Chapter 2 Elementary Programming
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
One-Dimensional Array Introduction Lesson xx
Console input.
Value returning Functions
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Introduction to C++ Programming
CS150 Introduction to Computer Science 1
Programs written in C and C++ can run on many different computers
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Fundamental Programming
Capitolo 1 – Introduction C++ Programming
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
EECE.2160 ECE Application Programming
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Instructor: Dr. Michael Geiger Spring 2019 Lecture 6: Strings
Presentation transcript:

ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 4: Continuing with C++ I/O Basics

Lecture outline Announcements/reminders  TA: Justin R Lacle  TA Office hour: 10-11:00 am, Tuesday and 11:00- 12:00 pm, Thursday  Class folder now set up on M:\ drive Should have folder under M:\ECE-264\ Continue with C++ basics  Review basic I/O  Work through examples Applying design cycle to ECE /3/2015 ECE 264: Lecture 4 2

Review Covered basic C++ program structure—very similar to C! Namespaces  Introduced std namespace—includes cin, cout, etc.  Could include entire namespace: using namespace std;  Or, just include members being used: using std::cout; Output ( cout ) streams  Can output multiple values in same statement cout << “x=“ << x << “, y=“ << y << endl; Input ( cin ) streams  Use cin to read values into variables E.g., cin >> x; Skips whitespace characters Input value must be compatible with type of x 10/3/2015 ECE 264: Lecture 4 3

4 Another C++ Program: Adding Integers Variable  Is a location in memory where a value can be stored  Common data types (fundamental, primitive or built-in) int – for integer numbers char – for characters double – for floating point numbers  Declare variables with data type and name before use int integer1; int integer2; int sum; 10/3/2015 ECE 264: Lecture 4

Basic program 2 // Adapted from figure 2.5 in text // Addition program that displays the sum of two integers. #include using std::cout; using std::cin; using std::endl; int main() { // variable declarations int number1; int number2; int sum; // prompt user for data and read into appropriate variables cout << "Enter first integer: "; cin >> number1; cout << "Enter second integer: "; cin >> number2; sum = number1 + number2; // add the numbers; store result in sum cout << "Sum is " << sum << endl; // display sum; end line return 0; // indicate that program ended successfully } // end function main 10/3/2015 ECE 264: Lecture 4 5

10/3/2015 ECE 264: Lecture 4 6 output 1,2 4.5 cm _ //Example 1: Determine the output #include using std::cout; using std::cin; using std::endl; #include using std::string; int main() { int i, j; double x; string units = " cm"; cin >> i >> j; cin >> x; cout << "output \n"; cout << i << ',' << j << endl << x << units << endl; return 0; } //Input stream is:

10/3/2015 ECE 264: Lecture 4 7 //Example 2: Determine the output #include using std::cout; using std::cin; using std::endl; int main() { int i, j; double x, y; cin >> i >> j >> x >> y; cout << "First output " << endl; cout << i << ',' << j << ',' << x << ',' << y << endl; cin >> x >> y >> i >> j; cout << "Second output" << endl; cout << i << ',' << j << ',' << x << ',' << y << endl; return 0; } //Input stream is: First output 1,2,3.4,5 Second output 3,2,2,3 _

Example 2 (cont.) Issues with second output  Before highlighted lines i = 1, j = 2, x = 3.4, y = 5  Second cin appears to assign: x = 2, y = 3, i = 3.4, j = 7  But printing i, j, x, and y in order yields: 3,2,2,3 j never gets value 7—what happens?  i and j are integers  cin reads 3 into i and then stops at decimal point  cin can’t skip non-whitespace character  j doesn’t change 10/3/2015 ECE 264: Lecture 4 8

Applying life cycle to ECE 264 How does the software cycle apply to ECE 264?  Project: You’ll be working in teams and taking a project through these stages  Labs: Don’t just sit down and start coding! Read the lab handout  will give you, in essence  Requirements: what should your program be able to do?  Hints about design / programming:  How might you organize your program?  How might you implement that design?  Basic system tests: given particular inputs to your “system” (program), what should the output look like? Identify each of those parts as you read the handout Based on what you read, formulate a high-level design  Given requirements, how are we going to organize the code?  What function(s) do we need?  What class(es) might we use?  We will often provide hints to point you in the right direction  Later labs may ask you to use UML to formalize parts of your design Once high-level design is done and you have a sense of overall program, then start writing code! 10/3/2015 ECE 264: Lecture 4 9

Final notes Next time Formatted output Acknowledgements: this lecture borrows heavily from lecture slides provided with the following texts: Deitel & Deitel, C++ How to Program, 8 th ed. Etter & Ingber, Engineering Problem Solving with C++, 2 nd ed. 10/3/2015 ECE 264: Lecture 4 10