鱼C论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: 小天狼星

C++程序的一个课程设计

[复制链接]
发表于 2015-2-12 21:46:49 | 显示全部楼层

回帖奖励 +3 鱼币

我来帮忙顶一下。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2015-2-12 23:07:30 | 显示全部楼层

回帖奖励 +3 鱼币

这人东西呀,我倒是想帮你,可是心有余力不足呀;

要不这样吧,六个月后我学差不多了,我在你写个 :big
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2015-2-13 08:33:42 | 显示全部楼层

回帖奖励 +3 鱼币

我来顶一顶{:1_1:}{:1_1:}
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2015-3-9 17:32:26 | 显示全部楼层

回帖奖励 +3 鱼币

学java的,我也无解
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2015-3-11 18:31:09 | 显示全部楼层

回帖奖励 +3 鱼币

我是来回复的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2015-4-16 04:50:49 | 显示全部楼层

回帖奖励 +3 鱼币

顶一下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2015-4-16 04:58:38 | 显示全部楼层
挣鱼币
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2015-4-21 18:58:54 | 显示全部楼层
看到楼主的,我打算自己写写这个当做练习了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2015-4-21 22:35:47 | 显示全部楼层
比我好多了,我是自学的,好多东西一头雾水,有时候很简单的问题要弄几个小时才明白呢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2015-5-3 17:04:05 | 显示全部楼层
求鱼币~~~~~~
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-20 15:31:42 | 显示全部楼层

回帖奖励 +3 鱼币

支持下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-22 08:46:33 | 显示全部楼层

回帖奖励 +3 鱼币

顶一下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-24 11:43:57 | 显示全部楼层

回帖奖励 +3 鱼币

看到困难了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-11-4 10:08:54 | 显示全部楼层
只能用c++?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-11-4 10:09:26 | 显示全部楼层

回帖奖励 +3 鱼币

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-12-24 20:27:09 | 显示全部楼层
@FishC 用c++编写一个程序任务:学生信息管理系统设计
学生信息包括:学号,姓名,年龄,性别,出生年月,地址,电话,E-mail等。试设计一学生信息管理系统,使之能提供以下功能:
1、系统以菜单方式工作
2、学生信息录入功能(学生信息用文件保存)--输入
3、学生信息浏览功能--输出
4、学生信息查询功能--算法按学号查询、按姓名查询
5、学生信息的删除与修改(可选项)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-12-24 20:27:45 | 显示全部楼层
卷帘红尘亦爱她 发表于 2023-12-24 20:27
@FishC 用c++编写一个程序任务:学生信息管理系统设计 ...

当然可以!下面是一个简单的C++程序,用于实现你描述的学生信息管理系统。
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5. struct Student {
  6.     string id;
  7.     string name;
  8.     int age;
  9.     string gender;
  10.     string birthdate;
  11.     string address;
  12.     string phone;
  13.     string email;
  14. };
  15. // 函数声明
  16. void displayMenu();
  17. void addStudent();
  18. void viewStudents();
  19. void searchStudentsById();
  20. void searchStudentsByName();
  21. bool deleteStudent();
  22. bool modifyStudent();
  23. int main() {
  24.     int choice;
  25.     do {
  26.         displayMenu();
  27.         cin >> choice;
  28.         cin.ignore();  // 忽略输入缓冲中的换行符
  29.         
  30.         switch (choice) {
  31.             case 1:
  32.                 addStudent();
  33.                 break;
  34.             case 2:
  35.                 viewStudents();
  36.                 break;
  37.             case 3:
  38.                 searchStudentsById();
  39.                 break;
  40.             case 4:
  41.                 searchStudentsByName();
  42.                 break;
  43.             case 5:
  44.                 if (!deleteStudent())
  45.                     cout << "学生信息删除失败!" << endl;
  46.                 break;
  47.             case 6:
  48.                 if (!modifyStudent())
  49.                     cout << "学生信息修改失败!" << endl;
  50.                 break;
  51.             case 0:
  52.                 cout << "感谢使用学生信息管理系统,再见!" << endl;
  53.                 break;
  54.             default:
  55.                 cout << "无效的选择,请重新输入!" << endl;
  56.         }
  57.         cout << endl;
  58.     } while (choice != 0);
  59.     return 0;
  60. }
  61. void displayMenu() {
  62.     cout << "====== 学生信息管理系统 ======" << endl;
  63.     cout << "1. 录入学生信息" << endl;
  64.     cout << "2. 浏览学生信息" << endl;
  65.     cout << "3. 按学号查询学生信息" << endl;
  66.     cout << "4. 按姓名查询学生信息" << endl;
  67.     cout << "5. 删除学生信息" << endl;
  68.     cout << "6. 修改学生信息" << endl;
  69.     cout << "0. 退出系统" << endl;
  70.     cout << "请输入选项:";
  71. }
  72. void addStudent() {
  73.     Student newStudent;
  74.     cout << "学号:";
  75.     getline(cin, newStudent.id);
  76.     cout << "姓名:";
  77.     getline(cin, newStudent.name);
  78.     cout << "年龄:";
  79.     cin >> newStudent.age;
  80.     cin.ignore();
  81.     cout << "性别:";
  82.     getline(cin, newStudent.gender);
  83.     cout << "出生年月:";
  84.     getline(cin, newStudent.birthdate);
  85.     cout << "地址:";
  86.     getline(cin, newStudent.address);
  87.     cout << "电话:";
  88.     getline(cin, newStudent.phone);
  89.     cout << "E-mail:";
  90.     getline(cin, newStudent.email);
  91.     // 将学生信息写入文件
  92.     ofstream outFile("students.txt", ios::app);  // 打开文件以追加写入数据
  93.     outFile << newStudent.id << ' '
  94.             << newStudent.name << ' '
  95.             << newStudent.age << ' '
  96.             << newStudent.gender << ' '
  97.             << newStudent.birthdate << ' '
  98.             << newStudent.address << ' '
  99.             << newStudent.phone << ' '
  100.             << newStudent.email << endl;
  101.     outFile.close();  // 关闭文件
  102.     cout << "学生信息录入成功!" << endl;
  103. }
  104. void viewStudents() {
  105.     ifstream inFile("students.txt");
  106.     if (!inFile) {
  107.         cout << "无法打开学生信息文件!" << endl;
  108.         return;
  109.     }
  110.     string line;
  111.     while (getline(inFile, line)) {
  112.         cout << line << endl;
  113.     }
  114.     inFile.close();
  115. }
  116. void searchStudentsById() {
  117.     string targetId;
  118.     cout << "请输入要查询的学号:";
  119.     getline(cin, targetId);
  120.     ifstream inFile("students.txt");
  121.     if (!inFile) {
  122.         cout << "无法打开学生信息文件!" << endl;
  123.         return;
  124.     }
  125.     string line;
  126.     bool found = false;
  127.     while (getline(inFile, line)) {
  128.         size_t pos = line.find(targetId);
  129.         if (pos != string::npos) {
  130.             cout << line << endl;
  131.             found = true;
  132.         }
  133.     }
  134.     if (!found) {
  135.         cout << "未找到该学号对应的学生信息!" << endl;
  136.     }
  137.     inFile.close();
  138. }
  139. void searchStudentsByName() {
  140.     string targetName;
  141.     cout << "请输入要查询的姓名:";
  142.     getline(cin, targetName);
  143.     ifstream inFile("students.txt");
  144.     if (!inFile) {
  145.         cout << "无法打开学生信息文件!" << endl;
  146.         return;
  147.     }
  148.     string line;
  149.     bool found = false;
  150.     while (getline(inFile, line)) {
  151.         size_t pos = line.find(targetName);
  152.         if (pos != string::npos) {
  153.             cout << line << endl;
  154.             found = true;
  155.         }
  156.     }
  157.     if (!found) {
  158.         cout << "未找到该姓名对应的学生信息!" << endl;
  159.     }
  160.     inFile.close();
  161. }
  162. bool deleteStudent() {
  163.     string targetId;
  164.     cout << "请输入要删除的学号:";
  165.     getline(cin, targetId);
  166.     ifstream inFile("students.txt");
  167.     if (!inFile) {
  168.         cout << "无法打开学生信息文件!" << endl;
  169.         return false;
  170.     }
  171.     ofstream outFile("temp.txt");  // 创建一个临时文件存放其他学生的信息
  172.     string line;
  173.     bool found = false;
  174.     while (getline(inFile, line)) {
  175.         size_t pos = line.find(targetId);
  176.         if (pos == string::npos) {
  177.             outFile << line << endl;
  178.         } else {
  179.             found = true;
  180.         }
  181.     }
  182.     inFile.close();
  183.     outFile.close();
  184.     // 删除旧的学生信息文件,并将临时文件重命名为新的学生信息文件
  185.     if (remove("students.txt") != 0 || rename("temp.txt", "students.txt") != 0) {
  186.         cout << "删除学生信息失败!" << endl;
  187.         return false;
  188.     }
  189.     if (found) {
  190.         cout << "学生信息删除成功!" << endl;
  191.     } else {
  192.         cout << "未找到该学号对应的学生信息,无法删除!" << endl;
  193.     }
  194.     return found;
  195. }
  196. bool modifyStudent() {
  197.     string targetId;
  198.     cout << "请输入要修改的学号:";
  199.     getline(cin, targetId);
  200.     fstream file("students.txt");
  201.     if (!file) {
  202.         cout << "无法打开学生信息文件!" << endl;
  203.         return false;
  204.     }
  205.     ofstream tempFile("temp.txt");
  206.     string line;
  207.     bool found = false;
  208.     while (getline(file, line)) {
  209.         size_t pos = line.find(targetId);
  210.         if (pos != string::npos) {
  211.             cout << "原信息:" << line << endl;
  212.             Student modifiedStudent;
  213.             modifiedStudent.id = targetId;
  214.             cout << "新姓名(不修改请直接回车):";
  215.             getline(cin, modifiedStudent.name);
  216.             cout << "新年龄(不修改请直接回车):";
  217.             cin >> modifiedStudent.age;
  218.             cin.ignore();
  219.             cout << "新性别(不修改请直接回车):";
  220.             getline(cin, modifiedStudent.gender);
  221.             cout << "新出生年月(不修改请直接回车):";
  222.             getline(cin, modifiedStudent.birthdate);
  223.             cout << "新地址(不修改请直接回车):";
  224.             getline(cin, modifiedStudent.address);
  225.             cout << "新电话(不修改请直接回车):";
  226.             getline(cin, modifiedStudent.phone);
  227.             cout << "新E-mail(不修改请直接回车):";
  228.             getline(cin, modifiedStudent.email);
  229.             if (modifiedStudent.name.empty()) {
  230.                 size_t endPos = line.find(' ', pos + 1);
  231.                 modifiedStudent.name = line.substr(pos + targetId.length() + 1, endPos - pos - targetId.length() - 1);
  232.             }
  233.             if (modifiedStudent.age == 0) {
  234.                 size_t startPos = line.find_last_of(' ') + 1;
  235.                 size_t endPos = line.find(' ', startPos);
  236.                 modifiedStudent.age = stoi(line.substr(startPos, endPos - startPos));
  237.             }
  238.             if (modifiedStudent.gender.empty()) {
  239.                 size_t startPos = line.find_last_of(' ') + 1;
  240.                 size_t endPos = line.find(' ', startPos);
  241.                 modifiedStudent.gender = line.substr(startPos, endPos - startPos);
  242.             }
  243.             if (modifiedStudent.birthdate.empty()) {
  244.                 size_t startPos = line.find_last_of(' ') + 1;
  245.                 size_t endPos = line.find(' ', startPos);
  246.                 modifiedStudent.birthdate = line.substr(startPos, endPos - startPos);
  247.             }
  248.             if (modifiedStudent.address.empty()) {
  249.                 size_t startPos = line.find_last_of(' ') + 1;
  250.                 size_t endPos = line.find(' ', startPos);
  251.                 modifiedStudent.address = line.substr(startPos, endPos - startPos);
  252.             }
  253.             if (modifiedStudent.phone.empty()) {
  254.                 size_t startPos = line.find_last_of(' ') + 1;
  255.                 size_t endPos = line.find(' ', startPos);
  256.                 modifiedStudent.phone = line.substr(startPos, endPos - startPos);
  257.             }
  258.             if (modifiedStudent.email.empty()) {
  259.                 size_t startPos = line.find_last_of(' ') + 1;
  260.                 modifiedStudent.email = line.substr(startPos);
  261.             }
  262.             cout << "修改后的信息:" << modifiedStudent.id << ' '
  263.                 << modifiedStudent.name << ' '
  264.                 << modifiedStudent.age << ' '
  265.                 << modifiedStudent.gender << ' '
  266.                 << modifiedStudent.birthdate << ' '
  267.                 << modifiedStudent.address << ' '
  268.                 << modifiedStudent.phone << ' '
  269.                 << modifiedStudent.email << endl;
  270.             tempFile << modifiedStudent.id << ' '
  271.                      << modifiedStudent.name << ' '
  272.                      << modifiedStudent.age << ' '
  273.                      << modifiedStudent.gender << ' '
  274.                      << modifiedStudent.birthdate << ' '
  275.                      << modifiedStudent.address << ' '
  276.                      << modifiedStudent.phone << ' '
  277.                      << modifiedStudent.email << endl;
  278.             found = true;
  279.         } else {
  280.             tempFile << line << endl;
  281.         }
  282.     }
  283.     file.close();
  284.     tempFile.close();
  285.     // 删除旧的学生信息文件,并将临时文件重命名为新的学生信息文件
  286.     if (remove("students.txt") != 0 || rename("temp.txt", "students.txt") != 0) {
  287.         cout << "修改学生信息失败!" << endl;
  288.         return false;
  289.     }
  290.     if (found) {
  291.         cout << "学生信息修改成功!" << endl;
  292.     } else {
  293.         cout << "未找到该学号对应的学生信息,无法修改!" << endl;
  294.     }
  295.     return found;
  296. }
复制代码

这个程序使用了一个结构体`Student`来表示学生信息。主要功能包括学生信息录入、浏览、查询、删除和修改。学生信息会保存在一个名为`students.txt`的文件中。

你可以根据需要自行扩展其他功能,比如按年龄查询、按性别查询等。另外,由于这只是一个简单的示例程序,没有进行输入验证、异常处理等,在实际应用中需要添加这些功能以提高系统的健壮性。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-19 10:38

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表