使用者工具

網站工具


cpp:2026spring:hw8

Turnin 作業 8

  • Turnin Code: cpp.hw8
  • Due Date: 5/18 Monday 23:59:00 (midnight) Hard Deadline

繳交方式說明

本次作業繳交將以資料夾的形式繳交,需要為每一題建立一個資料夾(資料夾名稱為該題題目前方之代號,第一題為「p1」,第二題為「p2」,餘以此類推)。

繳交說明可參考【Turnin 作業 4】中 p6 到 p10

任何未依照正確繳交格式的檔案將以 0 分計。

本文使用「▴」及「↵」代表「空白字元」與「Enter 換行字元」,並且將使用者輸入的部份使用灰階方式顯示。 另外,題目的執行結果中,如果出現「(」、「)」、「:」、「;」、「.」與「,」等符號,皆為英文半形!


p1 學生類別實作(封裝)

封裝是為了隱藏物件的內部實作細節,透過一些介面存取物件內的資料並保護資料不被外部隨意修改,可提升程式碼的安全性與可維護性。本題的目的是計算所有學生的學期成績,請參考下列的 main.cpp 程式(請依據檔名旁的路徑至 ws 取得程式碼):

#include "student.h"
#define MAX 10

int main()
{
    double class_average = 0;
    Student **student = new Student *[MAX];
    string names[MAX] = {"Daphne Lloyd", "Aaron Gold", "Julia Ruth", "Mick Felix", "Adonis Attlee",
                         "Renata Grote", "Abner Piers", "Kama Hood", "Kennedy George", "Ian Blake"};

    for (int i = 0; i < MAX; i++)
    {
        student[i] = new Student;
        student[i]->set_name(names[i]);
        student[i]->set_stu_id("cbb11341" + to_string(i));
    }

    student[0]->set_score(87.42, 73.56, 95.30, 68.18);
    student[1]->set_score(62.15, 78.94, 94.01, 73.67);
    student[2]->set_score(15.33, 65.76, 82.89, 74.24);
    student[3]->set_score(68.02, 84.19, 82.47, 65.85);
    student[4]->set_score(99.11, 65.62, 84.78, 78.49);
    student[5]->set_score(84.54, 86.30, 93.92, 85.06);
    student[6]->set_score(67.28, 81.45, 65.17, 86.31);
    student[7]->set_score(79.66, 83.22, 91.50, 97.03);
    student[8]->set_score(83.79, 76.81, 53.04, 61.46);
    student[9]->set_score(90.23, 70.88, 65.55, 74.72);

    cout << "Student ID\tName\t\tgeneral performance\texam1\t\texam2\t\tfinal exam\tterm score" << endl;
    for (int i = 0; i < MAX; i++)
    {
        student[i]->calculate_term_score();
        cout << student[i]->get_stu_id() << "\t"
             << student[i]->get_name() << "\t\t"
             << student[i]->get_general_performance() << "\t\t"
             << student[i]->get_exam1() << "\t\t"
             << student[i]->get_exam2() << "\t\t"
             << student[i]->get_final_exam() << "\t\t"
             << student[i]->get_term_score() << endl;
    }

    for (int i = 0; i < MAX; i++)
    {
        delete student[i];
    }
    delete[] student;
    student = nullptr;
    return 0;
}

請參考 18~27 行 set_score 函式,其引數從左至右分別為「general performance(平時成績)」、「exam1(第一次期中考)」、「exam2(第二次期中考)」與「final exam(期末考)」,這四項成績分別佔學期成績的 25%,計算學期成績時請四捨五入到小數點後第一位。

請完成名為 student.hstudent.cpp 的 C++ 程式,它們分別是 Student 類別的 宣告定義實作請注意,Student 類別中的所有成員變數請放置於「private」區塊,所有成員函式請放置於「public」區塊,否則不予計分

本題的相關程式將使用以下的 Makefile 進行編譯:

all: main.cpp student.o
	c++ main.cpp student.o
student.o: student.cpp student.h
	c++ student.cpp -c
clean:
	rm -f *.o *~ *.*~ a.out*

此題的執行結果可參考如下:

[3:23▴user@ws▴p1]▴./a.out↵
Student▴ID▴▴▴▴▴▴Name▴▴▴▴▴▴▴▴▴▴▴▴general▴performance▴▴▴▴▴exam1▴▴▴▴▴▴▴▴▴▴▴exam2▴▴▴▴▴▴▴▴▴▴▴final▴exam▴▴▴▴▴▴term▴score↵
cbb113410▴▴▴▴▴▴▴Daphne▴Lloyd▴▴▴▴▴▴▴▴▴▴▴▴87.42▴▴▴▴▴▴▴▴▴▴▴73.56▴▴▴▴▴▴▴▴▴▴▴95.3▴▴▴▴▴▴▴▴▴▴▴▴68.18▴▴▴▴▴▴▴▴▴▴▴81.1↵
cbb113411▴▴▴▴▴▴▴Aaron▴Gold▴▴▴▴▴▴▴▴▴▴▴▴▴▴62.15▴▴▴▴▴▴▴▴▴▴▴78.94▴▴▴▴▴▴▴▴▴▴▴94.01▴▴▴▴▴▴▴▴▴▴▴73.67▴▴▴▴▴▴▴▴▴▴▴77.2↵
cbb113412▴▴▴▴▴▴▴Julia▴Ruth▴▴▴▴▴▴▴▴▴▴▴▴▴▴15.33▴▴▴▴▴▴▴▴▴▴▴65.76▴▴▴▴▴▴▴▴▴▴▴82.89▴▴▴▴▴▴▴▴▴▴▴74.24▴▴▴▴▴▴▴▴▴▴▴59.6↵
cbb113413▴▴▴▴▴▴▴Mick▴Felix▴▴▴▴▴▴▴▴▴▴▴▴▴▴68.02▴▴▴▴▴▴▴▴▴▴▴84.19▴▴▴▴▴▴▴▴▴▴▴82.47▴▴▴▴▴▴▴▴▴▴▴65.85▴▴▴▴▴▴▴▴▴▴▴75.1↵
cbb113414▴▴▴▴▴▴▴Adonis▴Attlee▴▴▴▴▴▴▴▴▴▴▴99.11▴▴▴▴▴▴▴▴▴▴▴65.62▴▴▴▴▴▴▴▴▴▴▴84.78▴▴▴▴▴▴▴▴▴▴▴78.49▴▴▴▴▴▴▴▴▴▴▴82↵
cbb113415▴▴▴▴▴▴▴Renata▴Grote▴▴▴▴▴▴▴▴▴▴▴▴84.54▴▴▴▴▴▴▴▴▴▴▴86.3▴▴▴▴▴▴▴▴▴▴▴▴93.92▴▴▴▴▴▴▴▴▴▴▴85.06▴▴▴▴▴▴▴▴▴▴▴87.5↵
cbb113416▴▴▴▴▴▴▴Abner▴Piers▴▴▴▴▴▴▴▴▴▴▴▴▴67.28▴▴▴▴▴▴▴▴▴▴▴81.45▴▴▴▴▴▴▴▴▴▴▴65.17▴▴▴▴▴▴▴▴▴▴▴86.31▴▴▴▴▴▴▴▴▴▴▴75.1↵
cbb113417▴▴▴▴▴▴▴Kama▴Hood▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴79.66▴▴▴▴▴▴▴▴▴▴▴83.22▴▴▴▴▴▴▴▴▴▴▴91.5▴▴▴▴▴▴▴▴▴▴▴▴97.03▴▴▴▴▴▴▴▴▴▴▴87.9↵
cbb113418▴▴▴▴▴▴▴Kennedy▴George▴▴▴▴▴▴▴▴▴▴83.79▴▴▴▴▴▴▴▴▴▴▴76.81▴▴▴▴▴▴▴▴▴▴▴53.04▴▴▴▴▴▴▴▴▴▴▴61.46▴▴▴▴▴▴▴▴▴▴▴68.8↵
cbb113419▴▴▴▴▴▴▴Ian▴Blake▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴90.23▴▴▴▴▴▴▴▴▴▴▴70.88▴▴▴▴▴▴▴▴▴▴▴65.55▴▴▴▴▴▴▴▴▴▴▴74.72▴▴▴▴▴▴▴▴▴▴▴75.3↵
[3:23▴user@ws▴p1]▴

為便利同學起見,以上的執行結果以固定寬度字型再次顯示如下:

[3:23▴user@ws▴p1]▴./a.out↵
Student▴ID▴▴▴▴▴▴Name▴▴▴▴▴▴▴▴▴▴▴▴general▴performance▴▴▴▴▴exam1▴▴▴▴▴▴▴▴▴▴▴exam2▴▴▴▴▴▴▴▴▴▴▴final▴exam▴▴▴▴▴▴term▴score↵
cbb113410▴▴▴▴▴▴▴Daphne▴Lloyd▴▴▴▴▴▴▴▴▴▴▴▴87.42▴▴▴▴▴▴▴▴▴▴▴73.56▴▴▴▴▴▴▴▴▴▴▴95.3▴▴▴▴▴▴▴▴▴▴▴▴68.18▴▴▴▴▴▴▴▴▴▴▴81.1↵
cbb113411▴▴▴▴▴▴▴Aaron▴Gold▴▴▴▴▴▴▴▴▴▴▴▴▴▴62.15▴▴▴▴▴▴▴▴▴▴▴78.94▴▴▴▴▴▴▴▴▴▴▴94.01▴▴▴▴▴▴▴▴▴▴▴73.67▴▴▴▴▴▴▴▴▴▴▴77.2↵
cbb113412▴▴▴▴▴▴▴Julia▴Ruth▴▴▴▴▴▴▴▴▴▴▴▴▴▴15.33▴▴▴▴▴▴▴▴▴▴▴65.76▴▴▴▴▴▴▴▴▴▴▴82.89▴▴▴▴▴▴▴▴▴▴▴74.24▴▴▴▴▴▴▴▴▴▴▴59.6↵
cbb113413▴▴▴▴▴▴▴Mick▴Felix▴▴▴▴▴▴▴▴▴▴▴▴▴▴68.02▴▴▴▴▴▴▴▴▴▴▴84.19▴▴▴▴▴▴▴▴▴▴▴82.47▴▴▴▴▴▴▴▴▴▴▴65.85▴▴▴▴▴▴▴▴▴▴▴75.1↵
cbb113414▴▴▴▴▴▴▴Adonis▴Attlee▴▴▴▴▴▴▴▴▴▴▴99.11▴▴▴▴▴▴▴▴▴▴▴65.62▴▴▴▴▴▴▴▴▴▴▴84.78▴▴▴▴▴▴▴▴▴▴▴78.49▴▴▴▴▴▴▴▴▴▴▴82↵
cbb113415▴▴▴▴▴▴▴Renata▴Grote▴▴▴▴▴▴▴▴▴▴▴▴84.54▴▴▴▴▴▴▴▴▴▴▴86.3▴▴▴▴▴▴▴▴▴▴▴▴93.92▴▴▴▴▴▴▴▴▴▴▴85.06▴▴▴▴▴▴▴▴▴▴▴87.5↵
cbb113416▴▴▴▴▴▴▴Abner▴Piers▴▴▴▴▴▴▴▴▴▴▴▴▴67.28▴▴▴▴▴▴▴▴▴▴▴81.45▴▴▴▴▴▴▴▴▴▴▴65.17▴▴▴▴▴▴▴▴▴▴▴86.31▴▴▴▴▴▴▴▴▴▴▴75.1↵
cbb113417▴▴▴▴▴▴▴Kama▴Hood▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴79.66▴▴▴▴▴▴▴▴▴▴▴83.22▴▴▴▴▴▴▴▴▴▴▴91.5▴▴▴▴▴▴▴▴▴▴▴▴97.03▴▴▴▴▴▴▴▴▴▴▴87.9↵
cbb113418▴▴▴▴▴▴▴Kennedy▴George▴▴▴▴▴▴▴▴▴▴83.79▴▴▴▴▴▴▴▴▴▴▴76.81▴▴▴▴▴▴▴▴▴▴▴53.04▴▴▴▴▴▴▴▴▴▴▴61.46▴▴▴▴▴▴▴▴▴▴▴68.8↵
cbb113419▴▴▴▴▴▴▴Ian▴Blake▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴90.23▴▴▴▴▴▴▴▴▴▴▴70.88▴▴▴▴▴▴▴▴▴▴▴65.55▴▴▴▴▴▴▴▴▴▴▴74.72▴▴▴▴▴▴▴▴▴▴▴75.3↵
[3:23▴user@ws▴p1]▴

  • 本題相關的程式碼路徑已註明於檔名右側,同學們可以透過路徑複製到自己的家目錄。
  • Student 類別中的所有成員變數請放置於「private」區塊,所有成員函式請放置於「public」區塊,否則不予計分
  • 本題若有使用浮點數的需求,請使用 double 型態。
  • 本題應繳交檔案如下(至於 main.cpp 與 Makefile 則不需繳交):
    • student.h
    • student.cpp

p2 旅客類別實作(封裝)

延續 cpp.hw7 的 p3,本題仍是幫助鳳梨航空寄出關於航班起飛前相關資訊的 email 給旅客,但本題增加了 show_email_content() 函式供 main() function 呼叫使用,請參考下列的 main.cpp 程式(請依據檔名旁的路徑至 ws 取得程式碼):

#include "tourist.h"
using namespace std;

void show_email_content(Tourist tourist)
{
    cout << "Dear " << tourist.get_first_name() << " " << tourist.get_last_name() << "," << endl;
    cout << "Thank you for choosing Pineapple Airlines. We are excited to welcome you on board for your upcoming flight to "
         << tourist.flight.get_destination() << ". Please find your flight details below to ensure a smooth journey." << endl
         << endl;

    cout << "Flight Information: " << endl;
    cout << "\tFlight Number: " << tourist.flight.get_flight_no() << endl;
    cout << "\tFrom: " << tourist.flight.get_departure() << endl;
    cout << "\tTo: " << tourist.flight.get_destination() << endl;
    cout << "\tLuggage Limit: " << tourist.get_luggage_limitation() << endl;
    cout << "\tCabin Class: " << tourist.get_cabin_class() << endl;
    cout << "\tDate: " << tourist.flight.get_date() << endl;
    cout << "\tBoarding Time: " << tourist.flight.get_boarding_time() << endl;
    cout << "\tGate: " << tourist.flight.get_gate() << endl;
    cout << "Safe travels,\nThe Pineapple Airlines Team" << endl;
}

int main()
{
    Tourist Alex, Jamie, Dennis;
    cout << "------------------------------------------------------------------------" << endl;
    //          first name, last name, cabin class
    Alex.set_info("Alex", "Brookes", "Economy");
    //                  flight no.      from               to               mm/dd/yyyy   hr:mm   gate no.
    Alex.flight.set_info("PI 564", "Hong Kong(HKG)", "Taiwan Taoyuan(TPE)", "9/27/2021", "18:45", "527");
    show_email_content(Alex);

    cout << "------------------------------------------------------------------------" << endl;
    Jamie.set_info("Jamie", "Davis", "Business");
    Jamie.flight.set_info("PI 612", "Osaka (KIX)", "Seoul(ICN)", "3/26/2026", "06:30", "7");
    show_email_content(Jamie);

    cout << "------------------------------------------------------------------------" << endl;
    Dennis.set_info("Dennis", "Wilson", "First");
    Dennis.flight.set_info("PI 950", "Kaohsiung (KHH)", "Hong Kong(HKG)", "1/30/2026", "10:00", "092");
    show_email_content(Dennis);

    return 0;
}

請特別注意,鳳梨航空公司與其他的航空公司一樣有「economy class(經濟艙)」、「business class(商務艙)」以及「first class(頭等艙)」三個艙等。其中經濟艙的行李限制以 23 kg 為上限,其餘兩個艙等則以 32 kg 為上限。

請完成名為 tourist.htourist.cpp 的 C++ 程式,它們分別是 Tourist 與 Flight 類別的 宣告定義實作請注意,Tourist 中的以 Flight 類別所宣告的物件 flight 需放置在「public」區塊以外,Tourist (除 flight 物件外)與 Flight 類別所有成員變數請放置於「private」區塊,所有成員函式請放置於「public」區塊,否則不予計分

本題的相關程式將使用以下的 Makefile 進行編譯:

all: main.cpp tourist.o
	c++ main.cpp tourist.o
tourist.o: tourist.cpp tourist.h
	c++ tourist.cpp -c
clean:
	rm -f *.o *~ *.*~ a.out*

此題的執行結果可參考如下:

[3:23▴user@ws▴p2]▴./a.out↵
------------------------------------------------------------------------↵
Dear▴Alex▴Brookes,↵
Thank▴you▴for▴choosing▴Pineapple▴Airlines.▴We▴are▴excited▴to▴welcome▴you▴on▴board▴for▴your▴upcoming▴flight▴to▴Taiwan▴Taoyuan(TPE).▴Please▴find▴your▴flight▴details▴below▴to▴ensure▴a▴smooth▴journey.↵

Flight▴Information:▴↵
▴▴▴▴▴▴▴▴Flight▴Number:▴PI▴564↵
▴▴▴▴▴▴▴▴From:▴Hong▴Kong(HKG)↵
▴▴▴▴▴▴▴▴To:▴Taiwan▴Taoyuan(TPE)↵
▴▴▴▴▴▴▴▴Luggage▴Limit:▴23↵
▴▴▴▴▴▴▴▴Cabin▴Class:▴Economy↵
▴▴▴▴▴▴▴▴Date:▴9/27/2021↵
▴▴▴▴▴▴▴▴Boarding▴Time:▴18:45↵
▴▴▴▴▴▴▴▴Gate:▴527↵
Safe▴travels,↵
The▴Pineapple▴Airlines▴Team↵
------------------------------------------------------------------------↵
Dear▴Jamie▴Davis,↵
Thank▴you▴for▴choosing▴Pineapple▴Airlines.▴We▴are▴excited▴to▴welcome▴you▴on▴board▴for▴your▴upcoming▴flight▴to▴Seoul(ICN).▴Please▴find▴your▴flight▴details▴below▴to▴ensure▴a▴smooth▴journey.↵

Flight▴Information:▴↵
▴▴▴▴▴▴▴▴Flight▴Number:▴PI▴612↵
▴▴▴▴▴▴▴▴From:▴Osaka▴(KIX)↵
▴▴▴▴▴▴▴▴To:▴Seoul(ICN)↵
▴▴▴▴▴▴▴▴Luggage▴Limit:▴32↵
▴▴▴▴▴▴▴▴Cabin▴Class:▴Business↵
▴▴▴▴▴▴▴▴Date:▴3/26/2026↵
▴▴▴▴▴▴▴▴Boarding▴Time:▴06:30↵
▴▴▴▴▴▴▴▴Gate:▴7↵
Safe▴travels,↵
The▴Pineapple▴Airlines▴Team↵
------------------------------------------------------------------------↵
Dear▴Dennis▴Wilson,↵
Thank▴you▴for▴choosing▴Pineapple▴Airlines.▴We▴are▴excited▴to▴welcome▴you▴on▴board▴for▴your▴upcoming▴flight▴to▴Hong▴Kong(HKG).▴Please▴find▴your▴flight▴details▴below▴to▴ensure▴a▴smooth▴journey.↵

Flight▴Information:▴↵
▴▴▴▴▴▴▴▴Flight▴Number:▴PI▴950↵
▴▴▴▴▴▴▴▴From:▴Kaohsiung▴(KHH)↵
▴▴▴▴▴▴▴▴To:▴Hong▴Kong(HKG)↵
▴▴▴▴▴▴▴▴Luggage▴Limit:▴32↵
▴▴▴▴▴▴▴▴Cabin▴Class:▴First↵
▴▴▴▴▴▴▴▴Date:▴1/30/2026↵
▴▴▴▴▴▴▴▴Boarding▴Time:▴10:00↵
▴▴▴▴▴▴▴▴Gate:▴092↵
Safe▴travels,↵
The▴Pineapple▴Airlines▴Team↵
[3:23▴user@ws▴p2]▴

  • 本題相關的程式碼路徑已註明於檔名右側,同學們可以透過路徑複製到自己的家目錄。
  • 請注意,Tourist 中的以 Flight 類別所宣告的物件 flight 需放置在「public」區塊以外,Tourist (除 flight 物件外)與 Flight 類別所有成員變數請放置於「private」區塊,所有成員函式請放置於「public」區塊,否則不予計分
  • 本題若有使用浮點數的需求,請使用 double 型態。
  • 本題應繳交檔案如下(至於 main.cpp 與 Makefile 則不需繳交):
    • tourist.h
    • tourist.cpp

p3 銀行帳戶類別實作(封裝)

接續 cpp.hw7 的 p1,本題要對 BankAccount 類別進行封裝處理。

請參考下列的 main.cpp 程式(請依據檔名旁的路徑至 ws 取得程式碼):

#include "bank.h"
#define SUCCESS "\e[0;32m[ SUCCESS ]\e[0m " // show "[ SUCCESS ] " with green color
#define FAIL "\e[0;31m[   FAIL  ]\e[0m "      // show "[   FAIL  ] " with red color

class Banking
{
public:
    void show_status(BankAccount a)
    {
        cout << a.get_name() << "\'s current balance: " << a.get_balance() << endl;
    }

    void save(BankAccount &a, int money)
    {
        string output;
        if (a.save(money))
        {
            output = SUCCESS + a.get_name() + " saved $" + to_string(money);
        }
        else
        {
            output = FAIL + a.get_name() + " failed to save $" + to_string(money);
        }
        cout << output << endl;
        a.write_transaction_record(to_string(a.get_transaction_record_count()) + " " + output + "\n");
    }

    void transfer(BankAccount &a, BankAccount &b, int money)
    {
        string output;
        if (a.transfer(money, b))
        {
            output = SUCCESS + a.get_name() + " transfered $" + to_string(money) + " to " + b.get_name();
        }
        else
        {
            output = FAIL + a.get_name() + " failed to transfer $" + to_string(money) + " to " + b.get_name();
        }
        cout << output << endl;
        a.write_transaction_record(to_string(a.get_transaction_record_count()) + " " + output + "\n");
    }

    void withdraw(BankAccount &a, int money)
    {
        string output;
        if (a.withdraw(money))
        {
            output = SUCCESS + a.get_name() + " withdrew $" + to_string(money);
        }
        else
        {
            output = FAIL + a.get_name() + " failed to withdraw $" + to_string(money);
        }
        cout << output << endl;
        a.write_transaction_record(to_string(a.get_transaction_record_count()) + " " + output + "\n");
    }
};

int main()
{
    Banking bank;
    BankAccount Justin("Justin");
    BankAccount Amy("Amy");

    cout << "[1] ------------------------" << endl;
    bank.show_status(Justin);
    bank.show_status(Amy);

    cout << "[2] ------------------------" << endl;
    bank.save(Amy, 4090);
    bank.save(Amy, 0);
    bank.save(Amy, -216);

    cout << "[3] ------------------------" << endl;
    bank.transfer(Amy, Justin, 1080);
    bank.transfer(Amy, Justin, 4050);
    bank.transfer(Amy, Justin, 0);

    cout << "[4] ------------------------" << endl;
    bank.withdraw(Amy, 12000);
    bank.withdraw(Amy, 3000);
    bank.withdraw(Amy, 0);

    cout << "[5] ------------------------" << endl;
    bank.show_status(Amy);
    bank.show_status(Justin);

    cout << "[6] ------------------------" << endl;
    Amy.show_transaction_record();

    return 0;
}

請完成名為 bank.hbank.cpp 的 C++ 語言程式,它們分別是 BankAccount 類別的 宣告定義實作請注意,BankAccount 類別中的所有成員變數請放置於「private」區塊,所有成員函式請放置於「public」區塊,否則不予計分

本題將使用以下的 Makefile 進行編譯:

all: main.cpp bank.o bank.h
	c++ main.cpp bank.o
bank.o: bank.cpp bank.h
	c++ bank.cpp -c
clean:
	rm -f *.o *~ *.*~ a.out*

此題的執行結果可參考如下:

[3:23▴user@ws▴p3]▴./a.out↵
[1]▴------------------------↵
Justin's▴current▴balance:▴0↵
Amy's▴current▴balance:▴0↵
[2]▴------------------------↵
[▴SUCCESS▴]▴Amy▴saved▴\$4090↵
[▴▴▴FAIL▴▴]▴Amy▴failed▴to▴save▴\$0↵
[▴▴▴FAIL▴▴]▴Amy▴failed▴to▴save▴\$-216↵
[3]▴------------------------↵
[▴SUCCESS▴]▴Amy▴transfered▴\$1080▴to▴Justin↵
[▴▴▴FAIL▴▴]▴Amy▴failed▴to▴transfer▴\$4050▴to▴Justin↵
[▴▴▴FAIL▴▴]▴Amy▴failed▴to▴transfer▴\$0▴to▴Justin↵
[4]▴------------------------↵
[▴▴▴FAIL▴▴]▴Amy▴failed▴to▴withdraw▴\$12000↵
[▴SUCCESS▴]▴Amy▴withdrew▴\$3000↵
[▴▴▴FAIL▴▴]▴Amy▴failed▴to▴withdraw▴\$0↵
[5]▴------------------------↵
Amy's▴current▴balance:▴10↵
Justin's▴current▴balance:▴1080↵
[6]▴------------------------↵
Amy's▴transaction▴record:▴↵
1▴[▴SUCCESS▴]▴Amy▴saved▴\$4090↵
2▴[▴▴▴FAIL▴▴]▴Amy▴failed▴to▴save▴\$0↵
3▴[▴▴▴FAIL▴▴]▴Amy▴failed▴to▴save▴\$-216↵
4▴[▴SUCCESS▴]▴Amy▴transfered▴\$1080▴to▴Justin↵
5▴[▴▴▴FAIL▴▴]▴Amy▴failed▴to▴transfer▴\$4050▴to▴Justin↵
6▴[▴▴▴FAIL▴▴]▴Amy▴failed▴to▴transfer▴\$0▴to▴Justin↵
7▴[▴▴▴FAIL▴▴]▴Amy▴failed▴to▴withdraw▴\$12000↵
8▴[▴SUCCESS▴]▴Amy▴withdrew▴\$3000↵
9▴[▴▴▴FAIL▴▴]▴Amy▴failed▴to▴withdraw▴\$0↵
[3:23▴user@ws▴p3]▴

  • 本題相關的程式碼路徑已註明於檔名右側,同學們可以透過路徑複製到自己的家目錄。
  • BankAccount 類別中的所有成員變數請放置於「private」區塊,所有成員函式請放置於「public」區塊,否則不予計分
  • 本題應繳交檔案如下(至於 main.cpp 與 Makefile 則不需繳交):
    • bank.h
    • bank.cpp
cpp/2026spring/hw8.txt · 上一次變更: 2026/05/13 15:04 由 dengyi

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki