Try   HackMD
tags: 實習額外加分題

第十次實習課額外加分題 - 簡易成績單查詢系統

Description

在資料庫的世界裡,基本上每個資料都會有一個獨立的流水號,我們稱為 id,用以辨識每筆不同的紀錄,而成績單就是一個很好的資料庫的例子。
今天有張成績單,上面記錄了 id,student_id(學號),程設期末考成績跟計概成績,表格設計如下。

ID Sid 程設期末 計概期末
1 410735038 100 100
2 410835046 100 100
3 410935025 100 100
以下省略數行
100 411234567 100 100

假設現在班級內有 10 位同學,請你設計一支程式,其內有三個 function,分別為 input_score(輸入成績),change_score(修改成績),display_score(檢視成績),而參數設定及實際輸出請見下方。

本來想要有第四個做 delete,但發現刪除太狠了,先不出好了。
Orange

Constraint

  • 請仔細閱讀過範例輸出!!!
  • 三個函式 return type 皆為 bool,若成功修改查詢或輸入回傳 true,否則回傳 false
  • input_score
    • 其有兩個參數,分別是此成績單的陣列,以及當前的流水號(此參數為一 call-by reference 變數)
    • 每次呼叫 input_score,一定會把計概跟程設的成績連續輸入,不會分開呼叫分開輸入。(因為這樣出你們會死掉)
    • 若學號已存在於成績單中,則結束輸入
  • change_score
    • 修改前請先輸入學號,並查看成績單內是否已經有此學號的紀錄,若沒有則結束修改
    • 結束上面的判斷後請他輸入修改程設還是計概的成績,若輸入錯誤則結束修改
  • display_score
    • 查詢前先輸入學號,並查看成績單內是否已經有此學號的紀錄,若沒有則結束查詢
    • 結束上面的判斷後請他輸入查詢程設還是計概的成績,若輸入錯誤則結束查詢

請你完全複製以下的程式碼,並設計三個函式

#include <iostream> using namespace std; bool input_score(int score_list[][4],int &id){ //請完成此處程式碼 } bool change_score(int score_list[][4]){ //請完成此處程式碼 } bool display_score(int score_list[][4]){ //請完成此處程式碼 } int main(){ int score_list[10][4] = {}; int oper = 0; int id = 1; while(true){ cout << "歡迎使用成績單查詢系統,你想執行甚麼操作呢?\n" << "輸入成績請輸入 1,修改成績請輸入 2,查詢成績請輸入 3,離開系統請輸入 -1\n"; cin >> oper; if(oper != 1 && oper != 2 && oper != 3 && oper != -1){ cout << "請輸入正確的指令!\n"; continue; } if(oper == -1){ cout << "謝謝您使用本系統,系統即將關閉\n"; break; } if(oper == 1){ input_score(score_list, id); } else if(oper == 2){ change_score(score_list); } else if(oper == 3){ display_score(score_list); } } return 0; }

Sample Input and Output

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →