【文章內(nèi)容簡(jiǎn)介】
。 // data member }。 endif // include iostream using std::cout。 using std::endl。 include “” /* constructor function(s) definition */ /* Get functions definition */ /* Set functions definition */ /* Display date function definition */ // Test_3 include iostream using std::cout。 using std::cin。 using std::endl。 include “” int main() { /* create a object */ /* demonstrates class Date’s capabilities */ return 0。 } 4. 解決 步驟 : (1) 首先 ,實(shí)現(xiàn) Date 類成員函數(shù)的函數(shù)原型 (語(yǔ)句 )。 (2) 其次 ,根據(jù)函數(shù)原型,實(shí)現(xiàn) Date 類成員函數(shù)的函數(shù)定義 。 (3) 最后 ,在 main 函數(shù)中,創(chuàng)建一個(gè)或多個(gè)對(duì)象,并利用該對(duì)象實(shí)現(xiàn)對(duì) Date 類的 public成員函數(shù)的調(diào)用 。 東 南大學(xué) 計(jì)算機(jī)科學(xué)與工程學(xué)院 程序設(shè)計(jì)基礎(chǔ)及語(yǔ)言指導(dǎo)手冊(cè) 10 實(shí)驗(yàn)三 : 控制結(jié)構(gòu) 實(shí)驗(yàn)?zāi)康? 1.掌握“自頂向下求精”算法 2.編寫(xiě) C++程序: if 語(yǔ)句、 if/else 語(yǔ)句、 switch 語(yǔ)句 3.編寫(xiě) C++程序: while 語(yǔ)句、 do… while 語(yǔ)句、 for 語(yǔ)句 4.掌握計(jì)數(shù)器控制和標(biāo)記控制兩種循環(huán) 5.理解自增、自減和邏輯運(yùn)算符 6.應(yīng)用 break 和 continue 程序控制跳轉(zhuǎn)語(yǔ)句 實(shí)驗(yàn)作業(yè) 1 1. 問(wèn)題描述 (中文 ) 開(kāi)發(fā)一個(gè)程序,確定百貨商店的顧客是否已經(jīng)超出信用卡的透支額度。對(duì)于每位顧客可以獲取以下信息: a) 信 用卡的賬號(hào) ( int 型 ) b) 月初欠款 (beginning credits) c) 本月內(nèi)該顧客購(gòu)買(mǎi)商品的金額 (total charges) d) 本月內(nèi)顧客賬號(hào)中的存款 (total credits) e) 允許的信貸額度 程序輸入以上信息,計(jì)算新的欠款 ( = beginning balance + total charges – total credits),并判斷新的欠款 是否超過(guò)了顧客 的信貸額度。對(duì)于超出信貸額度的顧客,程序應(yīng)該顯示顧客的賬號(hào)、信貸額度、新的欠款 ,并輸出信息 “Credit limit exceeded”。 (英文 ) Develop a C++ program that will determine whether a departmentstore customer has exceeded the credit limit on a charge account. For each customer, the following facts are available: a) Account number (an integer) b) Balance at the beginning of the month c) Total of all items charged by this customer this month d) Total of all credits applied to this customer’s account this month e) Allowed credit limit The program should use a while structure to input each of these facts, calculate the new balance (= beginning balance + charges credits) and determine whether the new balance exceeds the customer’s credit limit. For those customers whose credit limit is exceeded, the program should display the customer’s account number, credit limit, new balance and the message “Credit limit exceeded”. 2. 實(shí)例結(jié)果輸出 // 略 ,詳見(jiàn) 英文 教材 P152 東 南大學(xué) 計(jì)算機(jī)科學(xué)與工程學(xué)院 程序設(shè)計(jì)基礎(chǔ)及語(yǔ)言指導(dǎo)手冊(cè) 11 3. 偽代碼設(shè)計(jì) 通過(guò)實(shí)驗(yàn),完成自頂向下的逐步求精的算法設(shè)計(jì)。 // 頂部 // 第一次精化 // 第二次精化 // ~ 4. 程序模板 // Test_4 //通過(guò)實(shí)驗(yàn),將程序代碼補(bǔ)充完整 5. 解決 步驟 : (1) 編程之前,先使用偽代碼進(jìn)行 自頂向下的逐步求精的算法設(shè)計(jì) 。 (2) 由于沒(méi)有指定顧客的數(shù)量,程序中需要使用標(biāo)記值來(lái)控制循環(huán)。 (3) 由于貨幣值是帶小數(shù)部分的,程序中需要使用 float 或 double 聲明浮點(diǎn)變量,以便存儲(chǔ)貨幣數(shù)值。 (4) 使用 while 或 for 循環(huán)語(yǔ)句來(lái)處理多組顧客的數(shù)據(jù)。 考慮 是否可以使用 do… while循環(huán)語(yǔ)句,對(duì)結(jié)果有什么影響? (5) 確定新的差額已經(jīng)超過(guò)信貸額度? (6) 在輸出格式的控制中, 控制打印貨幣值得精度為 2? 東 南大學(xué) 計(jì)算機(jī)科學(xué)與工程學(xué)院 程序設(shè)計(jì)基礎(chǔ)及語(yǔ)言指導(dǎo)手冊(cè) 12 實(shí)驗(yàn)作業(yè) 2 1. 問(wèn)題描述 (中文 ) 編寫(xiě)一個(gè)程序,打印以下的菱形。要求輸出的語(yǔ)句要么打印一個(gè)星號(hào) (*),要么打印一個(gè)空格。使用嵌套 for 語(yǔ)句,同時(shí)盡量減少輸出語(yǔ)句的使用次數(shù)。 (英文 ) Write a program that prints the following diamond shape. You may use output staements that print either a single asterisk (*) or a single blank. Maximize your of repetition (with nested for statements) and minimize the number of output statements. 2. 實(shí)例結(jié)果輸出 * *** ***** ******* ********* ******* ***** *** * 3. 偽代碼設(shè)計(jì) 通過(guò)實(shí)驗(yàn),完成自頂向下的逐步求精的算法設(shè)計(jì)。 /