| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 692 人关注过本帖
标题:大家帮个忙?看下这个c++程序题题怎么做?万分感谢!!!!!
只看楼主 加入收藏
王鑫
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-6-14
结帖率:0
收藏
已结贴  问题点数:20 回复次数:5 
大家帮个忙?看下这个c++程序题题怎么做?万分感谢!!!!!
一、题目:成绩处理
输入某班级30名同学、姓名、学号以及5门课成绩(随机输入,无论是成绩还是学号不按序输入。考虑用几个数组处理,或用结构体、或用类和对象)
程序完成前一步后,通过循环可以不断选择下面的某项功能执行(用提示语句列出菜单,通过读入某变量值,可用switch判断该变量,如接受到1表示执行第一项,依次类推,某项功能执行完可以返回菜单,也可退出系统):
1、    按学生查询
1.1    查询某学生某门课成绩(输入学号,输出成绩)
1.2    查询某学生平均成绩(输入学号,输出成绩)
1.3    查询某学生某门课等级(输入学号,输出“优、良、…)
2.按课程查询
2.1  查询某门课平均成绩(输入课程,输出平均成绩)
2.2  查询某门课及格率(输入课程,输出及格率)
3.3  查询该门课程最小成绩(输入课程,输出姓名、最小成绩)
3.4  查询该门课程最大成绩(输入课程,输出姓名、最大成绩)
3 按班级查询
3.1 查询班级所有课程平均分
3.2 将班级各课程按成绩从小到大输出成绩(一行一门课,行首写明课程名)
3.2 将班级各课程按学号从小到大输出成绩(一行一门课,行首写明课程名)
4 填加课程及学生相应成绩
5 填加学生及相应课程成绩
搜索更多相关主题的帖子: 查询 结构体 
2012-06-14 12:55
zxwangyun
Rank: 4
来 自:云南
等 级:业余侠客
威 望:1
帖 子:232
专家分:299
注 册:2008-10-17
收藏
得分:5 
随机输入,无论是成绩还是学号不按序输入
要怎么理解?

努力改变一点点!!
2012-06-14 17:46
yang400b
Rank: 2
等 级:论坛游民
帖 子:14
专家分:17
注 册:2012-6-13
收藏
得分:5 
随机输入是用随机函数吧。                您发这个题目是想我们来帮您做完?     不太好吧。。。
2012-06-14 18:01
liudw2
Rank: 4
等 级:业余侠客
帖 子:85
专家分:248
注 册:2011-7-31
收藏
得分:5 
不是随机函数,是随机输入数据,就是A学生和B学生的数据谁先输入都可以
2012-06-14 21:45
zxwangyun
Rank: 4
来 自:云南
等 级:业余侠客
威 望:1
帖 子:232
专家分:299
注 册:2008-10-17
收藏
得分:0 
程序代码:
#include<iostream>
#include<vector>
using namespace std;

#define MAX_NAME_LEN 30
#define COURSE1_NAME "课程1"
#define COURSE2_NAME "课程2"
#define COURSE3_NAME "课程3"
#define COURSE4_NAME "课程4"
#define COURSE5_NAME "课程5"

typedef struct tagSTUDENT
{
    unsigned int uNo;//学号
    char szName[MAX_NAME_LEN];    //姓名
    float fCourse1;
    float fCourse2;
    float fCourse3;
    float fCourse4;
    float fCourse5;
    float fAvg;
    float fTotal;
    tagSTUDENT()
    {
        memset(this,0,sizeof(tagSTUDENT));
    }
}STUDENT,*LPSTUDENT;

class CStudent
{
private:
    STUDENT m_stu;
    static int m_iTotal;//学生总人数
    static int m_iCourse1TotalPass;//课程1及格人数
    static int m_iCourse2TotalPass;
    static int m_iCourse3TotalPass;
    static int m_iCourse4TotalPass;
    static int m_iCourse5TotalPass;

    static float m_fCourse1MinScore;//课程1最低分
    static float m_fCourse2MinScore;
    static float m_fCourse3MinScore;
    static float m_fCourse4MinScore;
    static float m_fCourse5MinScore;
    static char m_szNameOfMinScore[5][MAX_NAME_LEN];//最低分学生名字

    static float m_fCourse1MaxScore;//课程1最高分
    static float m_fCourse2MaxScore;
    static float m_fCourse3MaxScore;
    static float m_fCourse4MaxScore;
    static float m_fCourse5MaxScore;
    static char m_szNameOfMaxScore[5][MAX_NAME_LEN];//最高分学生名字

    static float m_fCourse1TotalScore;//课程1总分
    static float m_fCourse2TotalScore;
    static float m_fCourse3TotalScore;
    static float m_fCourse4TotalScore;
    static float m_fCourse5TotalScore;

public:
    CStudent(unsigned int no,char * name,float c1,float c2,float c3,float c4,float c5)
    {
        if(   c1< 0.0f||c1 > 100.0f
            ||c2< 0.0f||c2 > 100.0f
            ||c3< 0.0f||c3 > 100.0f
            ||c4< 0.0f||c4 > 100.0f
            ||c5< 0.0f||c5 > 100.0f
            )
        {
            throw "分数有误";
        }
        m_iTotal++;
        m_stu.uNo = no;
        strcpy_s(m_stu.szName,MAX_NAME_LEN,name);
        m_stu.fCourse1 = c1;
        m_stu.fCourse2 = c2;
        m_stu.fCourse3 = c3;
        m_stu.fCourse4 = c4;
        m_stu.fCourse5 = c5;
        m_stu.fTotal = c1 + c2 + c3 + c4 + c5;
        m_stu.fAvg = m_stu.fTotal / 5;
        if(m_fCourse1MinScore>c1)
        {
            m_fCourse1MinScore=c1;
            strcpy_s(m_szNameOfMinScore[0],MAX_NAME_LEN,name);
        }
        if(m_fCourse2MinScore>c2)
        {
            m_fCourse2MinScore=c2;
            strcpy_s(m_szNameOfMinScore[1],MAX_NAME_LEN,name);
        }
        if(m_fCourse3MinScore>c3)
        {
            m_fCourse3MinScore=c3;
            strcpy_s(m_szNameOfMinScore[2],MAX_NAME_LEN,name);
        }
        if(m_fCourse4MinScore>c4)
        {
            m_fCourse4MinScore=c4;
            strcpy_s(m_szNameOfMinScore[3],MAX_NAME_LEN,name);
        }
        if(m_fCourse5MinScore>c5)
        {
            m_fCourse5MinScore=c5;
            strcpy_s(m_szNameOfMinScore[4],MAX_NAME_LEN,name);
        }
        if(m_fCourse1MaxScore<c1)
        {
            m_fCourse1MaxScore = c1;
            strcpy_s(m_szNameOfMaxScore[0],MAX_NAME_LEN,name);
        }
        if(m_fCourse2MaxScore<c2)
        {
            m_fCourse2MaxScore = c2;
            strcpy_s(m_szNameOfMaxScore[1],MAX_NAME_LEN,name);
        }
        if(m_fCourse3MaxScore<c3)
        {
            m_fCourse3MaxScore = c3;
            strcpy_s(m_szNameOfMaxScore[2],MAX_NAME_LEN,name);
        }
        if(m_fCourse4MaxScore<c4)
        {
            m_fCourse4MaxScore = c4;
            strcpy_s(m_szNameOfMaxScore[3],MAX_NAME_LEN,name);
        }
        if(m_fCourse5MaxScore<c5)
        {
            m_fCourse5MaxScore = c5;
            strcpy_s(m_szNameOfMaxScore[4],MAX_NAME_LEN,name);
        }
        if(c1>=60.0f)
            m_iCourse1TotalPass++;
        if(c2>=60.0f)
            m_iCourse2TotalPass++;
        if(c3>=60.0f)
            m_iCourse3TotalPass++;
        if(c4>=60.0f)
            m_iCourse4TotalPass++;
        if(c5>=60.0f)
            m_iCourse5TotalPass++;

        m_fCourse1TotalScore += c1;
        m_fCourse2TotalScore += c2;
        m_fCourse3TotalScore += c3;
        m_fCourse4TotalScore += c4;
        m_fCourse5TotalScore += c5;
    }
    bool QueryCourseScore(int course)//查询某门课程成绩
    {
        static char *szCourses[]={COURSE1_NAME,COURSE2_NAME,COURSE3_NAME,COURSE4_NAME,COURSE5_NAME};
        static float *coursesScore[]={&m_stu.fCourse1,&m_stu.fCourse2,&m_stu.fCourse3,&m_stu.fCourse4,&m_stu.fCourse5};
        if(course<0||course>=sizeof(szCourses)/sizeof(char*))
            return false;
        cout<<"\t"<<szCourses[course]<<":"<<*coursesScore[course]<<endl;
        return true;
    }
    unsigned int GetNo(){return m_stu.uNo;}//获取学号
    void QueryAvg()
    {
        cout<<"\t平均分:"<<m_stu.fAvg<<endl;
    }
    static void PrintCourses()
    {
        cout<<"==================================\n"
            <<"\t 1 "<<COURSE1_NAME<<"\n"
            <<"\t 2 "<<COURSE2_NAME<<"\n"
            <<"\t 3 "<<COURSE3_NAME<<"\n"
            <<"\t 4 "<<COURSE4_NAME<<"\n"
            <<"\t 5 "<<COURSE5_NAME<<"\n"
            <<"==================================\n";
    }
    bool QuerygGrade(int course)//等级
    {
        static char * szGrade[]={"","","","","不及格"};
        static char *szCourses[]={COURSE1_NAME,COURSE2_NAME,COURSE3_NAME,COURSE4_NAME,COURSE5_NAME};
        static float *coursesScore[]={&m_stu.fCourse1,&m_stu.fCourse2,&m_stu.fCourse3,&m_stu.fCourse4,&m_stu.fCourse5};
        if(course<0||course>=sizeof(szCourses)/sizeof(char*))
            return false;
        int i=4;
        if(*szCourses[course]>=90)
            i=0;
        else if(*szCourses[course]>=80)
            i=1;
        else if(*szCourses[course]>=70)
            i=2;
        else if(*szCourses[course]>=60)
            i=3;
        cout<<"\t"<<szCourses[course]<<":"<<szGrade[course]<<endl;
        return true;
    }
    float GetScore(int  course)
    {
        static float *coursesScore[]={&m_stu.fCourse1,&m_stu.fCourse2,&m_stu.fCourse3,&m_stu.fCourse4,&m_stu.fCourse5};
        return *coursesScore[course];
    }
    static void PrintCourseAvg(int course)//平均分
    {
        static char *szCourses[]={COURSE1_NAME,COURSE2_NAME,COURSE3_NAME,COURSE4_NAME,COURSE5_NAME};
        static float *totalScore[]={&m_fCourse1TotalScore,&m_fCourse2TotalScore,&m_fCourse3TotalScore,&m_fCourse4TotalScore,&m_fCourse5TotalScore};
        if(m_iTotal ==0)
            throw "无学生成绩信息";
        cout<<"\t"<<szCourses[course]<<"平均成绩:"<<*totalScore[course]/m_iTotal<<endl;
    }
    static void PrintCoursePassedPercent(int course)//及格率
    {
        static char *szCourses[]={COURSE1_NAME,COURSE2_NAME,COURSE3_NAME,COURSE4_NAME,COURSE5_NAME};
        static int *totalPass[]={&m_iCourse1TotalPass,&m_iCourse2TotalPass,&m_iCourse3TotalPass,&m_iCourse4TotalPass,&m_iCourse5TotalPass};
        if(m_iTotal ==0)
            throw "无学生成绩信息";
        cout<<"\t"<<szCourses[course]<<"及格率:"<<*totalPass[course]*100/m_iTotal<<"%"<<endl;
    }
    static void PrintCourseMinScore(int course)//最低分
    {
        static char *szCourses[]={COURSE1_NAME,COURSE2_NAME,COURSE3_NAME,COURSE4_NAME,COURSE5_NAME};
        static float *minScore[]={&m_fCourse1MinScore,&m_fCourse2MinScore,&m_fCourse3MinScore,&m_fCourse4MinScore,&m_fCourse5MinScore};
        if(m_iTotal ==0)
            throw "无学生成绩信息";
        cout<<"\t"<<szCourses[course]<<"最低分:"<<*minScore[course]<<"\t学生名字:"<<m_szNameOfMinScore[course]<<endl;
    }
    static void PrintCourseMaxScore(int course)//最高分
    {
        static char *szCourses[]={COURSE1_NAME,COURSE2_NAME,COURSE3_NAME,COURSE4_NAME,COURSE5_NAME};
        static float *maxScore[]={&m_fCourse1MaxScore,&m_fCourse2MaxScore,&m_fCourse3MaxScore,&m_fCourse4MaxScore,&m_fCourse5MaxScore};
        if(m_iTotal ==0)
            throw "无学生成绩信息";
        cout<<"\t"<<szCourses[course]<<"最高分:"<<*maxScore[course]<<"\t学生名字:"<<m_szNameOfMaxScore[course]<<endl;
    }
};

int CStudent::m_iTotal=0;//学生总人数
int CStudent::m_iCourse1TotalPass=0;//课程1及格人数
int CStudent::m_iCourse2TotalPass=0;
int CStudent::m_iCourse3TotalPass=0;
int CStudent::m_iCourse4TotalPass=0;
int CStudent::m_iCourse5TotalPass=0;
float CStudent::m_fCourse1MinScore=100.0f;
float CStudent::m_fCourse2MinScore=100.0f;
float CStudent::m_fCourse3MinScore=100.0f;
float CStudent::m_fCourse4MinScore=100.0f;
float CStudent::m_fCourse5MinScore=100.0f;
float CStudent::m_fCourse1MaxScore=0.0f;
float CStudent::m_fCourse2MaxScore=0.0f;
float CStudent::m_fCourse3MaxScore=0.0f;
float CStudent::m_fCourse4MaxScore=0.0f;
float CStudent::m_fCourse5MaxScore=0.0f;
float CStudent::m_fCourse1TotalScore=0.0f;
float CStudent::m_fCourse2TotalScore=0.0f;
float CStudent::m_fCourse3TotalScore=0.0f;
float CStudent::m_fCourse4TotalScore=0.0f;
float CStudent::m_fCourse5TotalScore=0.0f;
char CStudent::m_szNameOfMinScore[5][MAX_NAME_LEN]={0};
char CStudent::m_szNameOfMaxScore[5][MAX_NAME_LEN]={0};

vector<CStudent> vstu;
void show_usage()
{
    cout<<"================================\n"
        <<"1 按学生查询\n"
        <<"2 按课程查询\n"
        <<"3 按班级查询\n"
        <<"4 添加学生成绩\n"
        <<"0 退出\n"
        <<"================================\n";
}
typedef void (*USAGE_FUN)();
int get_user_sel(USAGE_FUN f,int min_sel,int max_sel)
{
    f();
    int sel;
    cout<<"请输入选择:";
    cin>>sel;
    while(sel<min_sel|| sel > max_sel)
    {
        cout<<"输入有误,请重新输入:\n";
        f();
        cout<<"请输入选择:";
        cin>>sel;
    }
    return sel;
}
void add_stu_score()
{
    unsigned int no;
    char name[MAX_NAME_LEN]={0};
    float c1,c2, c3, c4, c5;
    cout<<"输入学号:";
    cin>>no;
    cout<<"输入姓名:";
    cin>>name;
    cout<<"输入"<<COURSE1_NAME<<"成绩:";
    cin>>c1;
    cout<<"输入"<<COURSE2_NAME<<"成绩:";
    cin>>c2;
    cout<<"输入"<<COURSE3_NAME<<"成绩:";
    cin>>c3;
    cout<<"输入"<<COURSE4_NAME<<"成绩:";
    cin>>c4;
    cout<<"输入"<<COURSE5_NAME<<"成绩:";
    cin>>c5;
    vstu.push_back(CStudent(no,name,c1,c2,c3,c4,c5));
}
void show_usage_cource()
{
    cout<<"===============================\n"
        <<"1 查询平均成绩\n"
        <<"2 查询及格率\n"
        <<"3 查询课程最小成绩\n"
        <<"4 查询课程最大成绩\n"
        <<"===============================\n";
}
void show_usage_student()
{
    cout<<"===============================\n"
        <<"1 查询学生某门课成绩\n"
        <<"2 查询学生平均成绩\n"
        <<"3 查询学生某门课等级\n"
        <<"===============================\n";
}
CStudent* get_stu(unsigned int no)
{
    for(unsigned int i=0;i<vstu.size();i++)
    {
        if(vstu[i].GetNo() == no)
        {
            return &vstu[i];
        }
    }
    return NULL;
}
int main(int argc,char * argv[])
{
    int sel=0;
    try
    {
        while((sel=get_user_sel(show_usage,0,4)) != 0)
        {
            switch(sel)
            {
            case 1:
                {
                    int stu_sel = get_user_sel(show_usage_student,1,3);
                    cout<<"输入学生学号:";
                    unsigned int no;
                    cin>>no;
                    CStudent* pstu = get_stu(no);
                    int course_sel =0;
                    if(stu_sel == 1 || stu_sel == 3)
                    {
                        course_sel = get_user_sel(CStudent::PrintCourses,1,5);
                    }
                    course_sel--;
                    if(pstu)
                    {
                        switch(stu_sel)
                        {
                        case 1:pstu ->QueryCourseScore(course_sel);break;
                        case 2:pstu ->QueryAvg();break;
                        case 3:pstu ->QuerygGrade(course_sel);break;
                        default:
                            break;
                        }
                    }
                    else
                    {
                        cout<<"无学生信息"<<endl;
                    }
                }
                break;
            case 2:
                {
                    int query_sel = get_user_sel(show_usage_cource,1,4);
                    int course_sel = get_user_sel(CStudent::PrintCourses,1,5);
                    course_sel--;
                    switch(query_sel)
                    {
                    case 1:CStudent::PrintCourseAvg(course_sel);break;
                    case 2:CStudent::PrintCoursePassedPercent(course_sel);break;
                    case 3:CStudent::PrintCourseMinScore(course_sel);break;
                    case 4:CStudent::PrintCourseMaxScore(course_sel);break;
                    default:
                        break;
                    }
                }
                break;
            case 3:
                {
                    //自己实现,写几个函数操作vstu即可
                }
                break;
            case 4:add_stu_score();break;
            default:
                break;
            }
        }
    }
    catch(char *e)
    {
        vstu.clear();
        cout<<e<<endl;
        system("pause");
        exit(-1);
    }
    vstu.clear();
    return 0;
}

努力改变一点点!!
2012-06-15 16:37
a33445321
Rank: 2
等 级:论坛游民
帖 子:10
专家分:12
注 册:2012-3-9
收藏
得分:5 
兰交大的??
2012-06-16 21:17
快速回复:大家帮个忙?看下这个c++程序题题怎么做?万分感谢!!!!!
数据加载中...
 
   



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

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