1 / 18

Hands-on #03

Hands-on #03. Review. Program assignment Check to see your grading Q&A with TAs Program assignment submission ftp to Review on workshop. POS Improvement. 大富翁遊戲中的 12-8 商店老闆 Miya 希望繼續完善 POS 系統,能夠幫店裡的各項作業電腦化 ! 目前規劃中作業: n - Next Customer ( 銷貨作業 ) t - Term Over ( 交班作業 )

Download Presentation

Hands-on #03

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. Hands-on #03

  2. Review • Program assignment • Check to see your grading • Q&A with TAs • Program assignment submission • ftp to • Review on workshop

  3. POS Improvement • 大富翁遊戲中的12-8商店老闆Miya希望繼續完善POS系統,能夠幫店裡的各項作業電腦化! • 目前規劃中作業: • n - Next Customer (銷貨作業) • t - Term Over (交班作業) • u - Update goods (進貨作業) • q – Quit(打烊) • Your choise?

  4. Procedural Abstraction • Modulize 銷貨、交班、進貨、打烊 • 銷貨=> NextCustomer() • 交班=>TermOver() • 進貨=>UpdateGoods() • 打烊=> not necessary! • Check to see H03-01.cpp • Compile program • What’s wrong?

  5. Function Implementation • Implement functions: • NextCustomer(): copy codes • TermOver(), UpdateGoods(): dummy! • Function Structure (Components) • See page 3-18 in chap3cpp3rd.ppt • Mimic main()

  6. Function Implementation (Contd.) • Writing codes • See H03-02.cpp • Compile • What’s wrong? • Case 1: identifier not found • ‘NextCustomer’, ‘TermOver’, ‘UpdateGoods’ • Case 2: undeclared identifier • ‘unitPrice’, ‘quantity’, …

  7. Function Declaration • Case 1 solutions • Declare function • Function definition placement, page 3-21 • syntax • <return_type> FunName(<parameter-list>); • Reference: declaring functions->Function declaration syntax • See H03-03.cpp

  8. Scope Rules • Case 2 solutions • Local variables • Global variables • Compile local variable version • Run H03-03.exe

  9. Functions in Separate Files • See H03-04.cpp

  10. Parameter Passing • Implement TermOver() such that it can sum up total revenue in a term • Hint • Sum up “tmpAmount” in NextCustomer.cpp • return tmpAmount; • Total returned tmpAmount • totalRevenue= totalRevenue+ NextCustomer();

  11. Parameter Passing (Contd.) • See H03-05.cpp • TermOver() • TermOver(totalRevenue, numOfCustomer); • Compile H03-05.cpp

  12. Compile Errors!!! • Error C2061: syntax error : identifier 'TermOver' • error C2143: syntax error : missing ';' before '{' • error C2181: illegal else without matching if • error C2601: 'NextCustomer' : local function definitions are illegal • this line contains a '{' which has not yet been matched • error C2601: 'TermOver' : local function definitions are illegal • this line contains a '{' which has not yet been matched • error C2601: 'UpdateGoods' : local function definitions are illegal • this line contains a '{' which has not yet been matched • fatal error C1075: end of file found before the left brace '{'

  13. Debug for Compiling Errors • Error C2061: syntax error : identifier 'TermOver‘ • Solution • Press “F1” for “error C2061…” • Press “F1” for “if” • Compile again!

  14. Compile Errors • error C2601: 'NextCustomer' : local function definitions are illegal • this line contains a '{' which has not yet been matched • error C2601: 'TermOver' : local function definitions are illegal • this line contains a '{' which has not yet been matched • 'UpdateGoods' : local function definitions are illegal • this line contains a '{' which has not yet been matched • fatal error C1075: end of file found before the left brace '{' at 'd:\twk\coursestuff\cpp\ppt\hands-on-03\h03-05\h03-05.cpp(12)' was matched

  15. Debug for Compiling Errors • error C2601: 'NextCustomer' : local function definitions are illegal • Our code is correct! @@” • this line contains a '{' which has not yet been matched • Else { } in case ‘t’ • Compile again!!! • error C2059: syntax error : 'return'

  16. Debug for Compiling Errors • error C2059: syntax error : 'return‘ • Solution • Press “F1” for “?” • choice= ((answer== 'y') || (answer== 'Y'))? true: false;

  17. Debug for Logical Errors! • *** Strating term over process *** • There are 0 in this term. • The total revenue is 0.00 • Solution: move statements • float termRevenue= 0.0; • unsigned int termCustomers= 0; • See H03-06.cpp

  18. Using Standard Library • Eliminate fractions! • Ceiling or floor? • See H03-07.cpp • Compile • Press “F1” on “ceil()” • #include <cmath> • Find standard library • Sync with table of content • Visual Studio->Visual c++ -> Reference -> Libraries Reference ->Run-Time Library -> Alphabetical Function Reference • Math.h/ cmath.h

More Related