👉博__主👈:米碼收割機
👉技__能👈:C++/Python語言
👉公眾號👈:測試開發自動化【獲取源碼+商業合作】
👉榮__譽👈:阿里云博客專家博主、51CTO技術博主
👉專__注👈:專注主流機器人、人工智能等相關領域的開發、測試技術。
【C++】C+±機房收費管理系統(源碼+注釋)【獨一無二】
目錄
- 【C++】C++-機房收費管理系統(源碼+注釋)【獨一無二】
- 一、設計要求
- 二、設計思路
- 結構體
- 輸入學生信息
- 計算上機費用
- 查詢學生信息
- 顯示機器使用情況
- 將信息寫入文件
- 從文件讀取信息
- 主函數
- 三、可視化分析
一、設計要求
(21)機房收費管理系統
功能要求:
1)輸入功能:輸入30名學生的學號、班級、姓名、上機起始時間。
2)計算功能:計算每個下機學生的上機費用,每小時1元。(上機費用=上機時間*1.0/h ,不足一小時按一小時計算)
3)查詢功能:按條件(班級、學號、姓名)顯示學生的上機時間。
4)機器使用情況的顯示(顯示方式不限但要一目了然)
5)能將所有信息讀寫文件
👉👉👉 源碼獲取 關注【測試開發自動化】公眾號,回復 “ 機房 ” 獲取。👈👈👈
二、設計思路
結構體
struct Student {string student_id;string class_name;string name;time_t start_time;double fee;
};vector<Student> students;
- 結構體
Student
: 用于存儲學生信息,包括學號、班級、姓名、上機起始時間和上機費用。 - 全局變量
students
: 存儲所有學生信息的容器。
👉👉👉 源碼獲取 關注【測試開發自動化】公眾號,回復 “ 機房 ” 獲取。👈👈👈
輸入學生信息
void inputStudentInfo() {for (int i = 0; i < 30; ++i) {Student student;cout << "請輸入第 " << i + 1 << " 個學生的信息:" << endl;cout << "學號: ";cin >> student.student_id;cout << "班級: ";cin >> student.class_name;cout << "姓名: ";cin >> student.name;// 此處略去 至少10行 代碼。。。student.fee = 0.0;students.push_back(student);}
}
- 函數
inputStudentInfo
: 輸入30個學生的信息并存儲在students
容器中。
👉👉👉 源碼獲取 關注【測試開發自動化】公眾號,回復 “ 機房 ” 獲取。👈👈👈
計算上機費用
void calculateFee() {for (auto& student : students) {tm tm_end = {};cout << "請輸入學生 " << student.name << " 的下機時間 (格式: YYYY MM DD HH MM SS): ";// 此處略去 至少10行 代碼。。。double hours = difftime(end_time, student.start_time) / 3600.0;student.fee = ceil(hours) * 1.0; // 每小時 1 元,不足一小時按一小時計算}
}
- 函數
calculateFee
: 計算每個學生的上機費用,根據輸入的下機時間計算上機時長并按每小時1元收費。
查詢學生信息
void queryStudentInfo() {string condition;cout << "請輸入查詢條件(班級/學號/姓名): ";cin >> condition;for (const auto& student : students) {// 此處略去 至少10行 代碼。。。}}
}
- 函數
queryStudentInfo
: 根據輸入的查詢條件(班級、學號或姓名)查詢并顯示學生信息。
👉👉👉 源碼獲取 關注【測試開發自動化】公眾號,回復 “ 機房 ” 獲取。👈👈👈
顯示機器使用情況
void displayUsage() {cout << left << setw(12) << "學號" << setw(10) << "班級" << setw(10) << "姓名" << setw(20) << "上機起始時間" << "上機費用" << endl;for (const auto& student : students) {// 此處略去 至少10行 代碼。。。}
}
- 函數
displayUsage
: 顯示所有學生的上機使用情況,包括學號、班級、姓名、上機起始時間和上機費用。
將信息寫入文件
void writeToFile() {ofstream file("student_info.txt");// 此處略去 至少10行 代碼。。。file.close();
}
- 函數
writeToFile
: 將所有學生信息寫入文件student_info.txt
中。
從文件讀取信息
👉👉👉 源碼獲取 關注【測試開發自動化】公眾號,回復 “ 機房 ” 獲取。👈👈👈
void readFromFile() {ifstream file("student_info.txt");if (!file.is_open()) return;Student student;// 此處略去 至少10行 代碼。。。file.close();
}
- 函數
readFromFile
: 從文件student_info.txt
中讀取學生信息并存儲到students
容器中。
主函數
int main() {int choice;readFromFile();while (true) {cout << "\n機房收費管理系統\n";cout << "1. 輸入學生信息\n";cout << "2. 計算上機費用\n";cout << "3. 查詢學生信息\n";cout << "4. 顯示機器使用情況\n";cout << "5. 保存并退出\n";cout << "請選擇操作(1-5): ";cin >> choice;// 此處略去 至少10行 代碼。。。}}
>👉👉👉 源碼獲取 關注【測試開發自動化】公眾號,回復 “ 機房 ” 獲取。👈👈👈return 0;
}
- 主函數
main
: 提供用戶界面,用戶可以選擇輸入學生信息、計算上機費用、查詢學生信息、顯示機器使用情況以及保存并退出。根據用戶選擇執行相應的操作。
三、可視化分析
👉👉👉 源碼獲取 關注【測試開發自動化】公眾號,回復 “ 機房 ” 獲取。👈👈👈
剩余截圖不再繼續展示
👉👉👉 源碼獲取 關注【測試開發自動化】公眾號,回復 “ 機房 ” 獲取。👈👈👈