标题:帮忙解决一个MFC问题
只看楼主
小城
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-10-10
结帖率:100%
 问题点数:0 回复次数:5 
帮忙解决一个MFC问题
如何在VC中编写一个成绩管理系统(不是用数据库的),可以实现排序查询等功能
搜索更多相关主题的帖子: MFC 
2008-10-11 19:53
nwpu063417
Rank: 3Rank: 3
等 级:论坛游民
威 望:8
帖 子:428
专家分:28
注 册:2007-5-11
得分:0 
不用数据库可以用C++ STL中的vector啊,STL中还有一些关于算法的模板,用起来很方便的

2008-10-12 15:11
mayudong1
Rank: 2
等 级:论坛游民
威 望:1
帖 子:348
专家分:21
注 册:2006-4-18
得分:0 
数据结构定义
功能实现
界面表示

2008-10-13 09:39
江湖未冷
Rank: 1
等 级:新手上路
帖 子:140
专家分:0
注 册:2008-9-20
得分:0 
我这里有源代码,,,但是调试时有点问题,,高手帮忙改一下吧。。。谢谢啊。。。
# include"student.h"
const int MaxStuNum=51;
class CStuDatabase{
public:
    CStuDatabase();
    ~CStuDatabase();
    void ListScore();
    void SelectStuInfo();
    void AddStuInfo();
    void DelStuInfo();
    void EditStuInfo();
    void AnalyScore();
    void StuDBM(int);
    int FunctionMenu();
    void SortStu();
   
private :
    
    int num;
    CStudent stu[MaxStuNum];
    int SearchStu(const char*id);
    
};
# include"student.h"
const int MaxStuNum=51;
class CStuDatabase{
public:
    CStuDatabase();
    ~CStuDatabase();
    void ListScore();
    void SelectStuInfo();
    void AddStuInfo();
    void DelStuInfo();
    void EditStuInfo();
    void AnalyScore();
    void StuDBM(int);
    int FunctionMenu();
    void SortStu();
   
private :
    
    int num;
    CStudent stu[MaxStuNum];
    int SearchStu(const char*id);
    
};
# include"student.h"
const int MaxStuNum=51;
class CStuDatabase{
public:
    CStuDatabase();
    ~CStuDatabase();
    void ListScore();
    void SelectStuInfo();
    void AddStuInfo();
    void DelStuInfo();
    void EditStuInfo();
    void AnalyScore();
    void StuDBM(int);
    int FunctionMenu();
    void SortStu();
   
private :
    
    int num;
    CStudent stu[MaxStuNum];
    int SearchStu(const char*id);
    
};
# include<iomanip.h>
# include<string.h>
# include"student.h"
CStudent::CStudent(char *id,char*na,int us,int ts){
    strcpy(ID,id);
    strcpy(name,na);
    UsualScore=us;
    TestScore=ts;
    CalcTotalScore();
}
CStudent::CStudent(const CStudent &s)
{
    strcpy(ID,s.ID);
    strcpy(name,s.name);
    UsualScore=s.UsualScore;
    TestScore=s.TestScore;
    TotalScore=s.TotalScore;
}
CStudent::~CStudent()
{}
char *CStudent::GetID()
{
    return ID;
}
double CStudent::GetTotalScore()
{
    return TotalScore;
}
void CStudent::TableHead()
{
    cout<<setw(4)<<"学号"<<setw(10)<<"姓名"<<setw(10)
        <<"平时成绩"<<setw(10)<<"考试成绩"<<setw(12)<<"总成绩\n";
}
void CStudent::Display()
{
    cout<<setw(3)<<ID<<setw(10)<<name<<setw(10)<<UsualScore<<setw(10)<<TestScore<<setw(10)<<TotalScore<<endl;
}
void CStudent::CalcTotalScore()
{
    TotalScore=UsualScore*0.2+TestScore*0.8;
}
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
#include<iomanip.h>
#include<conio.h>
#include"StuDataBase.h"
int InputScore()
{
    int score;
    cin>>score;
    while(score<0||score>100)
    {
        cout<<"成绩超出范围,请重新输入百分制成绩(0----100):";
        cin>>score;
    }
    return score;
}
CStuDatabase::CStuDatabase()
{
    CStudent s;
    num=0;
    fstream StuFile;
    StuFile.open("StuInfo.dat",ios::in);
    if(!StuFile){
        cout<<"文件StuInfo.dat不能打开!\n";
        return;
    }
    StuFile.read((char*)&s,sizeof(s));
    while(!StuFile.eof())
    { num++;
    stu[num]=s;
    StuFile.read((char*)&s,sizeof(s));
    }
    StuFile.close();
}
CStuDatabase::~CStuDatabase()
{
    fstream StuFile;
    StuFile.open("StuInfo.dat",ios::out);
    if(!StuFile)
    {
        cout<<"文件StuInfo.dat不能创建!\n";
        return ;
    }
    for (int i=1;i<=num;i++)
    {
        StuFile.write((char*)&stu[i],sizeof(stu[i]));}
    StuFile.close();
}
int CStuDatabase::SearchStu(const char*id)
{
    for (int i=1;i<=num;i++)
        if(strcmp(stu[i].GetID(),id)==0)
            return i;
        return -1;
}
int CStuDatabase::FunctionMenu()
{
    int FuncNum;
    system("cls");
    cout<<"\n\n\n";
    cout<<setw(20)<<' '<<"**********************************************\n\n\n";
    cout<<setw(24)<<' '<<"请选择要进行的操作:\n\n";
    cout<<setw(28)<<' '<<"1----查询学生成绩\n\n"
        <<setw(28)<<' '<<"2----显示学生成绩单\n\n"
        <<setw(28)<<' '<<"3----添加学生信息\n\n"
        <<setw(28)<<' '<<"4----删除学生信息\n\n"
        <<setw(28)<<' '<<"5----修改学生信息\n\n"
        <<setw(28)<<' '<<"6----对成绩进行统计分析\n\n"
        <<setw(28)<<' '<<"0----退出\n\n\n";
        cout<<setw(20)<<' '<<"*************************************\n\n\n";
        cin>>FuncNum;
        while(FuncNum<0||FuncNum>6)
        {
            cout<<"请重新选择要进行的操作:"<<endl;
            cin>>FuncNum;
        }
        return FuncNum;
}
void CStuDatabase::StuDBM(int FuncNum)
{
    switch(FuncNum){
    case 1:SelectStuInfo();break;
    case 2:ListScore();break;
    case 3:AddStuInfo();break;
    case 4:DelStuInfo();break;
    case 5:EditStuInfo();break;
    case 6:AnalyScore();break;
    }
}
void CStuDatabase::SelectStuInfo()
{
    system("cls");
    char no[5];
    cout<<"\n请输入要查询的学生学号:"<<endl;
    cin>>no;
    int i=SearchStu(no);
    if (i==-1)
    {
        cout<<"\n你查找的学生不存在!\n";}
    else {
        cout<<"\n你查找的学生成绩如下:\n\n";
        CStudent::TableHead();
        stu[i].Display();
    }
    cout<<"\n按任意键返回..."<<endl;
    getch();
}
void CStuDatabase::ListScore()
{
    system("cls");
    if(num==0)
    {
        cout<<"当前还没有学生成绩!\n";}
    else {
        SortStu();
        CStudent::TableHead();
        for(int i=1;i<=num;i++)
            stu[i].Display();
        cout<<"\n共有"<<num<<"条学生成绩信息\n";
    }
    cout<<"\n显示成绩完毕!\n\n按任意键返回...."<<endl;
    getch();
}
void CStuDatabase::AddStuInfo()
{
    system("cls");
    char no[5];
    cout<<"请输入要添加的学生的学号(输入-1结束):";
    cin>>no;
    while(strcmp(no,"-1")!=0)
    {
        int i=SearchStu(no);
        while(i!=-1)
        {
            cout<<"\n你添加的学生已存在!\n请重新输入学号(-1结束):";
            cin>>no;
            if(strcmp(no,"-1")==0)
            {
                cout<<"\n本次操作完成!\n\n按任意键返回...."<<endl;
                getch();
                return ;
            }
            i=SearchStu(no);
        }
        num++;
        char na[10];
        cout<<"\n请输入要添加的学生的姓名:";
        cin>>na;
        cout<<"\n请输入要添加的学生的平时成绩:\n";
        int us=InputScore();
        cout<<"\n请输入要添加的学生的考试成绩:\n";
        int ts=InputScore();
        CStudent s(no,na,us,ts);
        stu[num]=s;
        cout<<"\n\n请输入要添加的学生的的学号(输入-1结束):";
        cin>>no;
    }
    cout<<"\n本次操作完成!\n\n按任意键返回...."<<endl;
    getch();
}
void CStuDatabase::DelStuInfo()
{
    system("cls");
    char no[5];
    cout<<"\n请输入要删除的学生学号:"<<endl;
    cin>>no;
    int i=SearchStu(no);
    if(i==-1)
    {
        cout<<"\n您要删除的学生不存在!\n";}
    else
    {cout<<"\n您所删除的学生信息如下:\n\n";
    stu[i].Display();
    char anser;
    cout<<"\n是否真的要删除该学生?(y/n):";
    cin>>anser;
    if(anser=='y'||anser=='Y')
    {
        for(int j=i+1;j<=num;j++)
            stu[j-1]=stu[j];
        num--;
        cout<<"\n删除信息成功!"<<endl;
    }
    }
    cout<<"\n\n按任意键返回...."<<endl;
    getch();
}
void CStuDatabase::EditStuInfo()
{
    system("cls");
    char no[5];
    cout<<"\n请输入要修改的学生学号:"<<endl;
    cin>>no;
    int i=SearchStu(no);
    if(i==-1)
    {
        cout<<"\n你要修改的学生不存在!\n";}

    else
    {
        cout<<"\n您所修改的学生成绩如下:\n\n";
        stu[i].Display();
        cout<<"\n请输入学生的新信息:";
        cout<<"\n请输入学生的姓名:";
        char na[10];
        cin>>na;
        cout<<"\n请输入学生的平时成绩:\n";
        int us=InputScore();
        cout<<"\n请输入学生的考试成绩:\n";
        int ts=InputScore();
        CStudent s(no,na,us,ts);
        stu[i]=s;
        cout<<"\n修改信息成功!"<<endl;
        getch();
    }

    void CStuDatabase::AnalyScore()
    {  
        system("cls")
        int c[5]={0};
        double AveScore=0;
        double ts;
        for (int i=1;i<=num;i++)
        {
            ts=stu[i].GetTotalScore();
            AveScore+=ts;
            switch(int(ts/10)){
            case 10:
            case  9:c[0]++;break;
            case  8:c[1]++;break;
            case  7:c[2]++;break;
            case  6:c[3]++;break;
            default :c[4]++;break;
            }
        }
        AveScore/=num;
        cout<<"\n学生成绩分布情况如下:\n\n";
        cout<<"优秀(90分--100分)人数:"<<c[0]<<",\t占"
            <<double(c[0])/num*100<<"%\n\n";
        cout<<"良好(80分--89分)人数:"<<c[1]<<",\t占"<<(double(c[1])/num)*100<<"%\n\n";
        cout<<"中等(70分--79分)人数:"<<c[2]<<",\t占"<<(double(c[2])/num)*100<<"%\n\n";
        cout<<"及格(60分--69分)人数:"<<c[3]<<",\t占"<<(double(c[3])/num)*100<<"%\n\n";
        cout<<"不及格(60分以下)人数:"<<c[4]<<",\t占"<<(double(c[4])/num)*100<<"%\n\n";
        cout<<"学生总人数:"<<num<<endl;
        cout<<"\n班级平均成绩为:"<<AveScore<<endl;
        cout<<"\n按任意键返回...."<<endl;
        getch();
    }
    void CStuDatabase::SortStu()
    {
        int i,j,k;
        for (i=1;i<num;i++)
        {
            k=i;
            for(j=i+1;j<=num;j++)
                if(strcmp(stu[j].GetID(),stu[k].GetID())<0)
                    k=j;
                CStudent temp=stu[i];
                stu[i]=stu[k];
                stu[k]=temp;
        }
    }
}
#include<iomanip.h>
#include<conio.h>
#include"StuDatabase.h"
void welcome();
void main()
{
    welcome();
    CStuDatabase stuDB;
    int FuncNum;
    FuncNum=stuDB.FunctionMenu();
    while(FuncNum!=0)
    {
        stuDB.StuDBM(FuncNum);
        FuncNum=stuDB.FunctionMenu();
    }
}
void welcome()
{
    cout<<"\n\n\n";
    cout<<setw(20)<<' '<<"*************************************\n\n\n";
    cout<<setw(24)<<' '<<"欢迎使用学生成绩单管理系统\n\n\n";
    cout<<setw(20)<<' '<<"*************************************\n\n\n";
    cout<<"\n按任意键继续...."<<endl;
    getch();
}
2008-10-13 13:37
汪帮主
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-10-13
得分:0 
需要做成有界面的吗?
不要数据库,学生信息是临时的?不存储起来?

我倒是有现成的学生成绩系统,只不过是数据库的,呵呵。
2008-10-13 14:22
小城
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-10-10
得分:0 
把它写进文件
2008-10-13 21:09



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




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

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