180 likes | 275 Views
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 ( 交班作業 )
E N D
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 (交班作業) • u - Update goods (進貨作業) • q – Quit(打烊) • Your choise?
Procedural Abstraction • Modulize 銷貨、交班、進貨、打烊 • 銷貨=> NextCustomer() • 交班=>TermOver() • 進貨=>UpdateGoods() • 打烊=> not necessary! • Check to see H03-01.cpp • Compile program • What’s wrong?
Function Implementation • Implement functions: • NextCustomer(): copy codes • TermOver(), UpdateGoods(): dummy! • Function Structure (Components) • See page 3-18 in chap3cpp3rd.ppt • Mimic main()
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’, …
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
Scope Rules • Case 2 solutions • Local variables • Global variables • Compile local variable version • Run H03-03.exe
Functions in Separate Files • See H03-04.cpp
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();
Parameter Passing (Contd.) • See H03-05.cpp • TermOver() • TermOver(totalRevenue, numOfCustomer); • Compile H03-05.cpp
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 '{'
Debug for Compiling Errors • Error C2061: syntax error : identifier 'TermOver‘ • Solution • Press “F1” for “error C2061…” • Press “F1” for “if” • Compile again!
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
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'
Debug for Compiling Errors • error C2059: syntax error : 'return‘ • Solution • Press “F1” for “?” • choice= ((answer== 'y') || (answer== 'Y'))? true: false;
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
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