160 likes | 296 Views
Lab3. EECE 351 Spring 2000 Section 1 Lecture # 7. Overview. Introduction More I/O Lab Homework What we know Where we are going. Introduction. Help clear up some I/O issues Continue to provide I/O options C++ streams only I/O lab I/O Homework (Builds on the lab). More I/O.
E N D
Lab3 EECE 351 Spring 2000 Section 1 Lecture # 7 EECE 351 – Lecture 7
Overview • Introduction • More I/O • Lab • Homework • What we know • Where we are going EECE 351 – Lecture 7
Introduction • Help clear up some I/O issues • Continue to provide I/O options • C++ streams only • I/O lab • I/O Homework (Builds on the lab) EECE 351 – Lecture 7
More I/O • cout << nX << nY << nZ << endl; • Prints normally, but happens this way: • nZ is stored in buffer first, then nY, then nX. Usually this is not a problem, but be wary. • Another way to put it (MSDN): EECE 351 – Lecture 7
More I/O (cont.) • How do you point a char*’s value (memory location)? • Type-cast it to void* 1st • void*? – Granddaddy of all pointers • Can be type casted to any other pointer type. • To help, What does this do? char* szTemp = "Hello"; cout << szTemp << endl; //Hello cout << *szTemp << endl; //H cout << &szTemp << endl; //Pointer’s pos cout << (void*) szTemp << endl; //Hello’s pos EECE 351 – Lecture 7
More I/O (cont.) • Manipulator options: • dec, oct, hex – set base number to print • Setbase accepts (10, 8, or 16) • Precision/setprecision (allows you to specify # of trailing digits)—pass # sets to that, nothing passed returns current state • Showpoint – specifies to print “.” or not. • Setw/width – amount of space to set aside for output. • fill() – returns current fill char. fill(char) sets current fill char. EECE 351 – Lecture 7
More I/O (cont.) • More Manipulator options: • left, right, internal -- justification flags. • setf(flag) – turns on passed flag. • unsetf(flag) – turns off passed flag. • Don’t forget <iomanip.h> • Just another way to do the same thing. EECE 351 – Lecture 7
Lab • This lab will introduce an integer parser. • Download to c:\temp\YOURNAME\Lab3 • Open .dsw file • Build application. Any errors? • Execute application. Any errors? Why? • Add Input.txt to project & Project settings (Alt-F7). • See next slides. EECE 351 – Lecture 7
Lab (cont.) EECE 351 – Lecture 7
Lab (cont.) EECE 351 – Lecture 7
Lab (cont.) • Place a breakpoint on the first cout statement. Begin the debugger. • Press F-11 to go into Init. What is argc’s value? Is file correctly openend? • Step into ParseInput. Place cursor inside: elseif ((ch == '-') && (g_nValue == 0)) • What line of input file brings you here? • Step into DisplayError. What happens? EECE 351 – Lecture 7
Lab (cont.) • Continue walking until you understand the lab. Then, terminate debugger. • Switch to Input.txt (FileView). Add 5682 WITH NO CARRIAGE RETURN! Execute program. Does it print the number to the screen? • Add 123d45 after above number WITH NO CARRIAGE RETURN! Execute program. What happens? EECE 351 – Lecture 7
Homework • Read D&D 11 & 14. MMM 6 & 7. • Take today’s lab and convert it into a floating point parser. • Specifications: • Only one complete # per line of input file. • Each number allowed is to have at most one decimal point. • Only allow 4 digits after “.” Either truncate (and inform user) or print error • Display line # of text file in each msg. EECE 351 – Lecture 7
Homework (cont.) • Specifications (cont.): • Don’t allow errors to affect any other parses • Identify which line contains EOF. Print correct message for entry. • Deliverables (In .zip file): • Time & Defects template • .pas file • .cpp (coding standard & COMMENTS) • .exe • Due 2/17/00 Before class starts. EECE 351 – Lecture 7
What we know • More I/O • An Integer Parser EECE 351 – Lecture 7
Where we are going • Lecture – Software Engineering. Read all required chapters of MMM! • No Lab • Review • Midterm (Yuck!) EECE 351 – Lecture 7