鱼C论坛

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

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

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

回帖奖励 +3 鱼币

我来帮忙顶一下。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +3 鱼币

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

要不这样吧,六个月后我学差不多了,我在你写个 :big
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +3 鱼币

我来顶一顶{:1_1:}{:1_1:}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +3 鱼币

学java的,我也无解
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +3 鱼币

我是来回复的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +3 鱼币

顶一下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2015-4-16 04:58:38 | 显示全部楼层
挣鱼币
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2015-4-21 18:58:54 | 显示全部楼层
看到楼主的,我打算自己写写这个当做练习了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

使用道具 举报

发表于 2015-5-3 17:04:05 | 显示全部楼层
求鱼币~~~~~~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +3 鱼币

支持下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +3 鱼币

顶一下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +3 鱼币

看到困难了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-11-4 10:08:54 | 显示全部楼层
只能用c++?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +3 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

使用道具 举报

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

当然可以!下面是一个简单的C++程序,用于实现你描述的学生信息管理系统。
#include <iostream>#include <fstream>#include <string>using namespace std;struct Student {    string id;    string name;    int age;    string gender;    string birthdate;    string address;    string phone;    string email;};// 函数声明void displayMenu();void addStudent();void viewStudents();void searchStudentsById();void searchStudentsByName();bool deleteStudent();bool modifyStudent();int main() {    int choice;    do {        displayMenu();        cin >> choice;        cin.ignore();  // 忽略输入缓冲中的换行符                switch (choice) {            case 1:                addStudent();                break;            case 2:                viewStudents();                break;            case 3:                searchStudentsById();                break;            case 4:                searchStudentsByName();                break;            case 5:                if (!deleteStudent())                    cout << "学生信息删除失败!" << endl;                break;            case 6:                if (!modifyStudent())                    cout << "学生信息修改失败!" << endl;                break;            case 0:                cout << "感谢使用学生信息管理系统,再见!" << endl;                break;            default:                cout << "无效的选择,请重新输入!" << endl;        }        cout << endl;    } while (choice != 0);    return 0;}void displayMenu() {    cout << "====== 学生信息管理系统 ======" << endl;    cout << "1. 录入学生信息" << endl;    cout << "2. 浏览学生信息" << endl;    cout << "3. 按学号查询学生信息" << endl;    cout << "4. 按姓名查询学生信息" << endl;    cout << "5. 删除学生信息" << endl;    cout << "6. 修改学生信息" << endl;    cout << "0. 退出系统" << endl;    cout << "请输入选项:";}void addStudent() {    Student newStudent;    cout << "学号:";    getline(cin, newStudent.id);    cout << "姓名:";    getline(cin, newStudent.name);    cout << "年龄:";    cin >> newStudent.age;    cin.ignore();    cout << "性别:";    getline(cin, newStudent.gender);    cout << "出生年月:";    getline(cin, newStudent.birthdate);    cout << "地址:";    getline(cin, newStudent.address);    cout << "电话:";    getline(cin, newStudent.phone);    cout << "E-mail:";    getline(cin, newStudent.email);    // 将学生信息写入文件    ofstream outFile("students.txt", ios::app);  // 打开文件以追加写入数据    outFile << newStudent.id << ' '            << newStudent.name << ' '            << newStudent.age << ' '            << newStudent.gender << ' '            << newStudent.birthdate << ' '            << newStudent.address << ' '            << newStudent.phone << ' '            << newStudent.email << endl;    outFile.close();  // 关闭文件    cout << "学生信息录入成功!" << endl;}void viewStudents() {    ifstream inFile("students.txt");    if (!inFile) {        cout << "无法打开学生信息文件!" << endl;        return;    }    string line;    while (getline(inFile, line)) {        cout << line << endl;    }    inFile.close();}void searchStudentsById() {    string targetId;    cout << "请输入要查询的学号:";    getline(cin, targetId);    ifstream inFile("students.txt");    if (!inFile) {        cout << "无法打开学生信息文件!" << endl;        return;    }    string line;    bool found = false;    while (getline(inFile, line)) {        size_t pos = line.find(targetId);        if (pos != string::npos) {            cout << line << endl;            found = true;        }    }    if (!found) {        cout << "未找到该学号对应的学生信息!" << endl;    }    inFile.close();}void searchStudentsByName() {    string targetName;    cout << "请输入要查询的姓名:";    getline(cin, targetName);    ifstream inFile("students.txt");    if (!inFile) {        cout << "无法打开学生信息文件!" << endl;        return;    }    string line;    bool found = false;    while (getline(inFile, line)) {        size_t pos = line.find(targetName);        if (pos != string::npos) {            cout << line << endl;            found = true;        }    }    if (!found) {        cout << "未找到该姓名对应的学生信息!" << endl;    }    inFile.close();}bool deleteStudent() {    string targetId;    cout << "请输入要删除的学号:";    getline(cin, targetId);    ifstream inFile("students.txt");    if (!inFile) {        cout << "无法打开学生信息文件!" << endl;        return false;    }    ofstream outFile("temp.txt");  // 创建一个临时文件存放其他学生的信息    string line;    bool found = false;    while (getline(inFile, line)) {        size_t pos = line.find(targetId);        if (pos == string::npos) {            outFile << line << endl;        } else {            found = true;        }    }    inFile.close();    outFile.close();    // 删除旧的学生信息文件,并将临时文件重命名为新的学生信息文件    if (remove("students.txt") != 0 || rename("temp.txt", "students.txt") != 0) {        cout << "删除学生信息失败!" << endl;        return false;    }    if (found) {        cout << "学生信息删除成功!" << endl;    } else {        cout << "未找到该学号对应的学生信息,无法删除!" << endl;    }    return found;}bool modifyStudent() {    string targetId;    cout << "请输入要修改的学号:";    getline(cin, targetId);    fstream file("students.txt");    if (!file) {        cout << "无法打开学生信息文件!" << endl;        return false;    }    ofstream tempFile("temp.txt");    string line;    bool found = false;    while (getline(file, line)) {        size_t pos = line.find(targetId);        if (pos != string::npos) {            cout << "原信息:" << line << endl;            Student modifiedStudent;            modifiedStudent.id = targetId;            cout << "新姓名(不修改请直接回车):";            getline(cin, modifiedStudent.name);            cout << "新年龄(不修改请直接回车):";            cin >> modifiedStudent.age;            cin.ignore();            cout << "新性别(不修改请直接回车):";            getline(cin, modifiedStudent.gender);            cout << "新出生年月(不修改请直接回车):";            getline(cin, modifiedStudent.birthdate);            cout << "新地址(不修改请直接回车):";            getline(cin, modifiedStudent.address);            cout << "新电话(不修改请直接回车):";            getline(cin, modifiedStudent.phone);            cout << "新E-mail(不修改请直接回车):";            getline(cin, modifiedStudent.email);            if (modifiedStudent.name.empty()) {                size_t endPos = line.find(' ', pos + 1);                modifiedStudent.name = line.substr(pos + targetId.length() + 1, endPos - pos - targetId.length() - 1);            }            if (modifiedStudent.age == 0) {                size_t startPos = line.find_last_of(' ') + 1;                size_t endPos = line.find(' ', startPos);                modifiedStudent.age = stoi(line.substr(startPos, endPos - startPos));            }            if (modifiedStudent.gender.empty()) {                size_t startPos = line.find_last_of(' ') + 1;                size_t endPos = line.find(' ', startPos);                modifiedStudent.gender = line.substr(startPos, endPos - startPos);            }            if (modifiedStudent.birthdate.empty()) {                size_t startPos = line.find_last_of(' ') + 1;                size_t endPos = line.find(' ', startPos);                modifiedStudent.birthdate = line.substr(startPos, endPos - startPos);            }            if (modifiedStudent.address.empty()) {                size_t startPos = line.find_last_of(' ') + 1;                size_t endPos = line.find(' ', startPos);                modifiedStudent.address = line.substr(startPos, endPos - startPos);            }            if (modifiedStudent.phone.empty()) {                size_t startPos = line.find_last_of(' ') + 1;                size_t endPos = line.find(' ', startPos);                modifiedStudent.phone = line.substr(startPos, endPos - startPos);            }            if (modifiedStudent.email.empty()) {                size_t startPos = line.find_last_of(' ') + 1;                modifiedStudent.email = line.substr(startPos);            }            cout << "修改后的信息:" << modifiedStudent.id << ' '                << modifiedStudent.name << ' '                << modifiedStudent.age << ' '                << modifiedStudent.gender << ' '                << modifiedStudent.birthdate << ' '                << modifiedStudent.address << ' '                << modifiedStudent.phone << ' '                << modifiedStudent.email << endl;            tempFile << modifiedStudent.id << ' '                     << modifiedStudent.name << ' '                     << modifiedStudent.age << ' '                     << modifiedStudent.gender << ' '                     << modifiedStudent.birthdate << ' '                     << modifiedStudent.address << ' '                     << modifiedStudent.phone << ' '                     << modifiedStudent.email << endl;            found = true;        } else {            tempFile << line << endl;        }    }    file.close();    tempFile.close();    // 删除旧的学生信息文件,并将临时文件重命名为新的学生信息文件    if (remove("students.txt") != 0 || rename("temp.txt", "students.txt") != 0) {        cout << "修改学生信息失败!" << endl;        return false;    }    if (found) {        cout << "学生信息修改成功!" << endl;    } else {        cout << "未找到该学号对应的学生信息,无法修改!" << endl;    }    return found;}
这个程序使用了一个结构体`Student`来表示学生信息。主要功能包括学生信息录入、浏览、查询、删除和修改。学生信息会保存在一个名为`students.txt`的文件中。

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

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-10-3 12:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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