标题:学生管理系统,开头就出现问题了
只看楼主
BobMaster
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2018-1-4
结帖率:85.71%
已结贴  问题点数:15 回复次数:10 
学生管理系统,开头就出现问题了
#include<iostream>
#include<iomanip>
#include<string>
#include<stdlib.h>
#include<string.h>
#include<fstream>
using namespace std;
struct student
{
    char name[10];
    char sex[10];
    int classnum;
    double phonenum;
    char address[20];
    char profession[20];
    int stunum;
    int highmath;
    int english;
    int linegeneration;
    int os;
    int programmingdesigh;
    int sum;
    int ave;
    int num;
};
void showprogram();
void Tmenu( struct student stu[]);
void Smenu(int num,struct student stu[]);
void addf(struct student stu[]);
void addg(struct student stu[]);
void showclass(struct student stu[]);
void showall(int i,struct student stu[]);
void showfundation(int i, struct student stu[]);
void changef(struct student stu[]);
void changeg(struct student stu[]);
void del(struct student stu[]);
void search(struct student stu[]);
static int n;//学生条数
struct student stu[15];
void main ()
{
    system("color 0A");
    int choice; int username[15];  int i = 0; char ch;
    int select = username[0];
    int num = 10 * username[9] + username[10];
    int classnum = username[8];
    cout << "1.登陆 2.注册\n" << "请输入操作代码:\n";
    cin >> choice;
    switch (choice)
    {
    case 1:system("cls");
        cout << "请输入您的学号或工号:";
        getchar();
        while (getchar() != '\n')
        {
            cin>>username[i];
            i++;
        }
        system("pause");
        switch (select)
    {
        case 1:
            if (n == 0){ cout << "查无此人,请先注册!\n"; return; }
            else
                system("cls"); Smenu(num, stu); break;
        case 2:system("cls"); Tmenu(stu); break;
    }
        break;
    case 2:
        system("cls");
        addf(stu);
        break;
    }
}
void Smenu(int num,student stu[])
{
    cout << "  -----------------------------学生信息显示系统------------------------------------------\n";
    cout << "  |      1.显示本人信息   2.显示全部学生基本信息 3.显示本班级学生信息                    | ";
    cout << "  |      4.显示本班级课表                                                                |\n";
    cout << "  |      0.退出系统                                                                    |\n";
    cout << "  ---------------------------------------------------------------------------------------\n";
    cout << "                                请输入操作代码\n";
    int select=0;
    switch (select){
    case 1: showall(num,stu);
    case 2:showfundation(num, stu);
    case 3:showclass( stu);
    case 4:showprogram();
    case 0:exit(0);
    }
}
void Tmenu(student stu[])
{
    cout << "  -----------------------------班级信息编辑系统-------------------------------------------------\n";
    cout << "  |      1.修改学生基本信息      2.删除指定学生信息                                             |\n";
    cout << "  |      3.录入学生科目成绩      4.修改学生科目信息                                             |\n";
    cout << "  |      5.修改课表                                                                             |\n";
    cout << "                               请输入操作代码\n";
    int select=0;
    switch (select){
    case 1: changef(stu);
    }
}
void showprogram()
{
    char a[5];
    cout << "┏━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┓\n";
    cout << "┃           ┃    周一   ┃    周二   ┃    周三   ┃    周四   ┃    周五   ┃\n";
    for (int i = 1; i < 6; i++)
    {
        cout << "┣━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━━━━╋━━━━━━━━━━━┫\n";
        cout << "┃   第" << i << "节   ┃";
        for (int j = 1; j < 6; j++)
        {
            cin >> a; cout << "━━━━━━╋";
        }

        cout << "┗━━━━━━━━━━━┻━━━━━━━━━━━┻━━━━━━━━━━━┻━━━━━━━━━━━┻━━━━━━━━━━━┻━━━━━━━━━━━┛\n";
    }
    system("pause");
}
void showall(int i,struct student stu[])
{
        if (n == 0)
        {
            cout << "请先录入学生信息!"; return;
        }
        int j = 0;
        for (j = 0; j < n; j++)
            showfundation(i,stu);
    }
void showfundation(int i, struct student stu[])
    {
        cout << "姓名:" << stu[i].name << "\t";
        cout << "性别:" << stu[i].sex << "\t";
        cout << "班级:" << stu[i].classnum << "\t";
        cout << "学号:" << stu[i].stunum << "\t";
        cout << "专业:" << stu[i].profession << "\t";
        cout << "手机:" << stu[i].phonenum << "\t";
        cout << "家庭住址:" << stu[i].address << "\t";
    }   
void showclass(struct student stu[])
    {
        int classnum, i;
        if (n == 0){
            cout << "请先录入学生信息!";
        }
        else
            cout << "请输入查看班级号\n";
        cin >> classnum;
        for (i = 0; i < n; i++)
        {
            if (classnum == stu[i].classnum)
                cout << stu[i].name << "\n";
        }
    }
void addf(struct student stu[])
    {
        int i; char Name[10]; char YN;
        cout << "**********学生注册***********\n";
        do{
            cout << "请输入:\n"<<"姓名:"; cin >> Name;
            for (i = 0; i < n; i++)
            {
                if (strcmp(Name, stu[n].name) == 0)
                {
                    cout << "该生已存在!\n";
                    return;
                }
            }
            ofstream fin("d:\\file.txt");
            cout << "性别:"; cin >> stu[n].sex;
            cout << "学号:"; cin >> stu[n].stunum;
            cout << "手机:"; cin >> stu[n].phonenum;
            cout << "住址:"; cin >> stu[n].address;
            n++;
            cout << "还要添加么?填Y或者N:"; cin >> YN;
        } while (YN == 'Y');
        return;
    }
void addg(struct student stu[])
    {
        int i, Num; char YN;
        if (n == 0){
            cout << "请先录入学生信息!";
            return;
        }
        do {
            cout << "请输入学号:"; cin >> Num; int j = 0;
            for (i = 0; i < n; i++)
            if (stu[i].stunum == Num)
            {
                cout << "请输入高数成绩:"; cin >> stu[i].highmath;
                cout << "请输入英语成绩:"; cin >> stu[i].english;
                cout << "请输入线性代数成绩:"; cin >> stu[i].linegeneration;
                cout << "请输入操作系统成绩:"; cin >> stu[i].os;
                cout << "请输入程序设计成绩:"; cin >> stu[i].programmingdesigh;
                cout << "总分:" << (stu[i].highmath + stu[i].english + stu[i].linegeneration + stu[i].os + stu[i].programmingdesigh);
                cout << "均分:" << (stu[i].highmath + stu[i].english + stu[i].linegeneration + stu[i].os + stu[i].programmingdesigh) / 5;
                n++; j++;
                cout << "是否继续添加?填Y或者N:"; cin >> YN;
            }
            if (j == 0)cout << "该生不存在!";
        } while (YN == 'Y');
        return;
    }
void changef(struct student stu[])
    {
        int select;
        if (n == 0){
            cout << "请先录入学生信息!";
        }
        char Name[10]; char Sex[10]; int Classnum; int Stunum; double Phonenum; char Address[20]; char Profession[20]; int i;
        cout << "请输入想要修改的学生学号:"; cin >> Stunum;
        for (i = 0; i < n; i++)
        if (stu[i].stunum == Stunum)
        {
            cout << "请输入要修改的项目序号: (1.姓名 2.性别 3.班级 4.学号 5.专业 6.手机 7.家庭住址)" << "\n"; cin >> select;
            switch (select){
            case 1:cout << "请输入新的姓名:"; cin >> Name; strcpy_s(stu[i].name , Name);
            case 2:cout << "请输入新的性别:"; cin >> Sex;
            case 3:cout << "请输入新的班级:"; cin >> Classnum; stu[i].classnum = Classnum;
            case 4:cout << "请输入新的学号:"; cin >> Stunum; stu[i].stunum = Stunum;
            case 5:cout << "请输入新的专业:"; cin >> Profession;
            case 6:cout << "请输入新的手机号:"; cin >> Phonenum; stu[i].phonenum = Phonenum;
            case 7:cout << "请输入新的家庭住址:"; cin >> Address;
            }
        }
    }
            
            
            
搜索更多相关主题的帖子: stu int void cout cin 
2018-09-25 09:49
BobMaster
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2018-1-4
得分:0 
switch (choice)
    {
    case 1:system("cls");
        cout << "请输入您的学号或工号:";
        getchar();
        while (getchar() != '\n')
        {
            cin>>username[i];
            i++;
        }
        system("pause");
        switch (select)
    {
        case 1:
            if (n == 0){ cout << "查无此人,请先注册!\n"; return; }
            else
                system("cls"); Smenu(num, stu); break;
        case 2:system("cls"); Tmenu(stu); break;
    }
        break;
    case 2:
        system("cls");
        addf(stu);
        break;
    }
那一块直接跳出去了
2018-09-25 09:50
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:8 
我编译你代码时,编译器报 uninitialized local variable 'username' used
看你的代码
    int choice; int username[15];  int i = 0; char ch;
    int select = username[0];
果然是这样
2018-09-25 10:09
BobMaster
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2018-1-4
得分:0 
int username[15] = { } 还是不行啊

[此贴子已经被作者于2018-9-25 10:26编辑过]

2018-09-25 10:11
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:0 
回复 4楼 BobMaster
我猜吧,对于 int select = username[0]; 这一句。你是不是认为以后 username[0] 改变了时 select 就会自动地改变?!
2018-09-25 10:46
BobMaster
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2018-1-4
得分:0 
回复 5楼 rjsp
对的,我就是那么想的。
2018-09-25 10:51
BobMaster
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2018-1-4
得分:0 
是不是得用指针啊
2018-09-25 10:51
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:0 
回复 7楼 BobMaster
int select = username[0];
改为
int& select = username[0];

BTW:你对C/C++一窍不通呀,应该先看点儿相关的书
2018-09-25 11:15
BobMaster
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2018-1-4
得分:0 
还是不行
2018-09-25 11:23
Jonny0201
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:52
帖 子:488
专家分:2603
注 册:2016-11-7
得分:8 
回复 9楼 BobMaster
还是不行 那编译器怎么提示的?
2018-09-25 12:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-489981-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.052130 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved