1 / 10

HW 5

HW 5. Overview. Try/catch framework is required for main function Please indent your files rightly I suggest that you try all examples on the book if you find it difficulty to go on with homework Do not wait for the last moment to ask for help, have a schedule for each problem ahead.

Download Presentation

HW 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HW 5

  2. Overview • Try/catch framework is required for main function • Please indent your files rightly • I suggest that you try all examples on the book if you find it difficulty to go on with homework • Do not wait for the last moment to ask for help, have a schedule for each problem ahead.

  3. PR 1 Second run :: ./a.out There were 97 0's. There were 100 1's. There were 99 2's. There were 87 3's. There were 107 4's. There were 104 5's. There were 104 6's. There were 96 7's. There were 93 8's. There were 113 9's. First run :: ./a.out There were 99 0's. There were 119 1's. There were 118 2's. There were 98 3's. There were 87 4's. There were 105 5's. There were 94 6's. There were 94 7's. There were 102 8's. There were 84 9's.

  4. PR 1 • You will write three files, randint.h, randint.cpp, hw5pr1.cpp • Source code for randint.cpp is given • Why and how to write code in separate files. • http://cse230.artifice.cc/lecture/splitting-code.html • P.51 on text book about linking • How to compile multiple source code. • g++-4.7 -std=c++11 hw5pr1.cpp randint.cpp

  5. PR 2 file1: abc def g h i file2: abc DEf ghi uub • output: • 1:OK • 2:DIFF • 3:DIFF • 4:DIFF

  6. PR 2 • Read and Write file, see Chapter 10.4 & 10.5 on text book • Use getline(…) function string str; ifstream file("file.dat"); While(getline(file, str)) { // do something here }

  7. PR 3 • Input • (2000,1,2) • Output • (2000,1,3) • Input • (2000,12,31) • Output • (2001,1,1)

  8. PR 3 • Based on Chrono.h and Chrono.cpp of section 9.8. • Add dummy “return d” in the last 3 functions on page 332 to make the code compiles OK. • Add ++ operator overload to class Data type • putting the declaration in the Date class in Chrono.h and the definition in Chrono.cpp.

  9. PR 3 • Pseudocode for ++ overload is Date& operator++(){ //add 1 to d //tomorrow, unless we were at the end of the month //if is_date is false // //need to change to first of next month // set d to 1 // if m is December // //need to change to next year too // set m to January // increment y // else // increment m return *this; }

  10. More about prefix and suffix ++ overload, see this page • http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr330.htm

More Related