回 帖 发 新 帖 刷新版面

主题:c语言:设计一程序,统计一个班的学生成绩,要求能实现如下五个功能

(1)由键盘输入每个学生的学号、姓名和五门课程的成绩。
(2)计算每个学生的平均分和部分。
(3)按总分高到低排出名次,并按名次输出每个学生的情况,包括:学号、姓名、各科成绩、平均分和部分。
(4)根据用户要求输出某门课程(由键盘输入课程号)成绩在90分以上(含
90分)且总分在前五名的学生情况,包括:学号、姓名、各科成绩、平均分和总分。
(5)根据用户的要求输入某个学生的学号,查找并显示出该学生的情况,包括学号、姓名、各科成绩、平均分和总分。如学号不存在,给出相应的提示。

回复列表 (共6个回复)

沙发

你找到答案了吗?
我也有这么一道题,你能告诉我答案吗??
我的是实训题,如果没过明年就要补考了。
请帮帮我啊!

板凳

用C++里面的类可能简单一点,,或者用C里面的结构体应该也可以.

3 楼

我那一道题是实现四个功能,题目要求如下;
(1)由键盘输入每个学生的学号和四门课程的成绩。
(2)计算每个学生的平均分和总分。
(3)按总分高到低排出名次,并按名次输出每个学生的情况,包括:学号、姓名、各科成绩、平均分和总分。
(4)根据用户要求输出某门课程(由键盘输入课程号)成绩在90分以上(含
90分)且总分在前五名的学生情况,包括:学号、姓名、各科成绩、平均分和总分。
请问你能给出答案吗?
可以告诉我吗?

4 楼

#include "stdafx.h"

struct Student
{
    long Number;
    string Name;
    string Sex;
    int DataStruct;
    int OperaterSystem;
    int DataBase;
    int ComputerConsistute;
    int Compiler;
    Student* Next;
    Student(long,string,string,int,int,
            int,int,int,Student* Next=NULL);
};

class Operater
{
public:
    Operater();
    void Insert();
    void Delete();
    void Print();
    void Search();
    void Sort();
    int  Size()const;
    Student* Set_position(int);
private:
    int      Count;
    Student* Head;
};

Student::Student(long Number,string Name,string Sex,int DataStruct,
                 int OperaterSystem,int DataBase,int ComputerConsistute,
                 int Compiler,Student* Next)
{
    this->Number=Number;
    this->Name=Name;
    this->Sex=Sex;
    this->DataBase=DataBase;
    this->OperaterSystem=OperaterSystem;
    this->DataStruct=DataStruct;
    this->ComputerConsistute=ComputerConsistute;
    this->Compiler=Compiler;
    this->Next=Next;
}
Operater::Operater()
{
    Count=0;
    Head=NULL;
}
Student* Operater::Set_position(int Position)
{
    Student* Q=Head;
    for(int i=0;i<Position;i++)
        Q=Q->Next;
    return Q;
}
void Operater::Insert()
{
    int Position;
    cout<<"请输入插入的位置"<<endl;
    cin>>Position;
    while(Position<0||Position>Count)
    {
        cout<<"您插入的位置不正确"<<endl;
        cout<<"请重新输入"<<endl;
        cin>>Position;
    }
    cout<<"请输入插入的学号"<<endl;
    long Number;
    cin>>Number;
    cout<<"请输入插入的姓名"<<endl;
    string Name;
    cin>>Name;
    cout<<"请输入插入的性别"<<endl;
    string Sex;
    cin>>Sex;
    cout<<"请输入数据结构成绩"<<endl;
    int DataStruct;
    cin>>DataStruct;
    cout<<"请输入操作系统成绩"<<endl;
    int OperaterSystem;
    cin>>OperaterSystem;
    cout<<"请输入数据库成绩"<<endl;
    int DataBase;
    cin>>DataBase;
    cout<<"请输入计算机组成原理成绩"<<endl;
    int ComputerConsistute;
    cin>>ComputerConsistute;
    cout<<"请输入编译原理成绩"<<endl;
    int Compiler;
    cin>>Compiler;
    Student *Privous,*Following,*New_student;
    if(Position>0)
    {
      Privous=Set_position(Position-1);
      Following=Privous->Next;
    }
    else
        Following=Head;
    New_student=new Student(Number,Name,Sex,DataBase,OperaterSystem,DataStruct,
                              ComputerConsistute,Compiler,Following);
    if(New_student==NULL)
        return;
    if(Position==0)
        Head=New_student;
    else
        Privous->Next=New_student;
    Count++;
}

5 楼

void Operater::Delete()
{
    cout<<"请选择删除的位置"<<endl;
    int Position;
    cin>>Position;
    if(Position<0||Position>Count)
        return;
    Student *Privous,*Following;
    if(Position>0)
    {
        Privous=Set_position(Position-1);
        Following=Privous->Next;
    }
    else
        Following=Head;
    if(Position==0)
        Head=Following->Next;
    else
        Privous->Next=Following->Next;

    delete Following;
    Count--;
}
void Operater::Print()
{
    cout<<"姓名  性别  数据结构 操作系统 数据库系统 编译原理 计算机组成原理"<<endl;
    Student* Q=Head;
    while(Q!=NULL)
    {
        cout<<Q->Name<<"   "<<Q->Sex<<"    "<<Q->Compiler<<"     "<<Q->ComputerConsistute
            <<"    "<<Q->DataBase<<"    "<<Q->DataStruct<<"     "<<Q->OperaterSystem<<endl;
        Q=Q->Next;
    }
}
void Operater::Search()
{
    cout<<"请您输入要查找的姓名"<<endl;
    string name;
    cin>>name;
    Student* Q=Head;
    while(Q!=NULL)
    {
        if(Q->Name==name)
        {
            cout<<Q->Name<<"   "<<Q->Sex<<"    "<<Q->Compiler<<"     "<<Q->ComputerConsistute
                <<"    "<<Q->DataBase<<"    "<<Q->DataStruct<<"     "<<Q->OperaterSystem<<endl;
            return;
        }
        Q=Q->Next;
    }
    cout<<"There is not exist the name!"<<endl;
}
void Operater::Sort()
{
    Student *First_unsorted,*Last_sorted,*Current,*Trailing;
    if(Head!=NULL)
    {
        Last_sorted=Head;
        while(Last_sorted->Next!=NULL)
        {
            First_unsorted=Last_sorted->Next;
            if(First_unsorted->Number<Head->Number)
            {
                Last_sorted->Next=First_unsorted->Next;
                First_unsorted->Next=Head;
                Head=First_unsorted;
            }
            else 
            {
                Trailing=Head;
                Current=Trailing->Next;
                while(First_unsorted->Number>Current->Number)
                {
                    Trailing=Current;
                    Current=Trailing->Next;
                }
                if(First_unsorted==Current)
                    Last_sorted=First_unsorted;
                else
                {
                    Last_sorted->Next=First_unsorted->Next;
                    First_unsorted->Next=Current;
                    Trailing->Next=First_unsorted;
                }
            }
        }
    }
}

6 楼

int Operater::Size()const
{
    return Count;
}
int _tmain(int argc, _TCHAR* argv[])
{
    Operater student;
    cout<<"请输入您的姓名"<<endl;
    string Name;
    cin>>Name;
    if(Name!="p")
    {
        cout<<"您的姓名不正确"<<endl;
        return 0;
    }
    cout<<"请输入您的密码"<<endl;
    int Pwd;
    cin>>Pwd;
    if(Pwd!=777)
    {
        cout<<"您的密码不正确"<<endl;
        return 0;
    }
    cout<<"恭喜您通过验证"<<endl;
    cout<<"请选择您的项目 0退出 1添加 2排序 3打印 4删除 5查询"<<endl;
    int Select;
    cin>>Select;
    while(Select!=0)
    {
        if(Select==1)
            student.Insert();
        else if(Select==2)
            student.Sort();
        else if(Select==3)
            student.Print();
        else if(Select==4)
            student.Delete();
        else 
            student.Search();
        cout<<"请选择您的项目 0退出 1添加 2排序 3打印 4删除 5查询"<<endl;
        cin>>Select;
    }
    return 0;
}

我来回复

您尚未登录,请登录后再回复。点此登录或注册