发新话题
打印

帮忙看一到课程设计题~~谢谢啦~

帮忙看一到课程设计题~~谢谢啦~

恳请大家在此基础上完成一下查询模块~~谢谢大家啦~~

C/C++ code #include<iostream>#include<string>#include<fstream>
using
namespace std;#define MIN 5
class student{    long num;    string name;    char sex;    float math;    float english;    float sport;    float Cplus;    float sum;    float ave;public:    static
int total;public:    void Creat();    void Output();};int student::total=0;void student::Creat(){    cout<<"欢迎进入学生的信息建立系统!"<<endl;    cout<<"学号"<<"\t"<<"姓名"<<"\t"<<"性别"<<"\t"<<"高等数学"<<"\t"<<"英语"<<"\t"<<"大学体育"<<"\t"<<"C++面向程序设计"<<endl;    cin>>num>>name>>sex>>math>>english>>sport>>Cplus;    student::total++;}void student::Output(){    cout<<"学号"<<"\t"<<"姓名"<<"\t"<<"性别"<<"\t"<<"高等数学"<<"\t"<<"英语"<<"\t"<<"大学体育"<<"\t"<<"C++面向程序设计"<<endl;        cout<<num<<"\t"<<name<<"\t"<<sex<<"\t"<<math<<"\t"<<"\t"<<english<<"\t"<<sport<<"\t"<<"\t"<<Cplus<<endl;}//主菜单
void welcome(){    cout<<endl<<endl;    cout<<endl<<endl;    cout<<"\t         设计:  *******************           "<<endl;    cout<<"\t***************************************************"<<endl;    cout<<"\t*             欢迎进入学生成绩管理系统             *"<<endl;    cout<<"\t*                                                  *"<<endl;    cout<<"\t*    1:输入            2:输出            3:查询    *"<<endl;    cout<<"\t*    4:修改            5:增加            6:保存    *"<<endl;    cout<<"\t*    7:统计            8:读取            9:退出    *"<<endl;    cout<<"\t****************************************************"<<endl;    cout<<endl;    cout<<"请选择你需要的选项:";}   //函数
int main(){    student *stu=new student[MIN];    welcome();  int choic;  while(choic!=0)  {       cin>>choic;       switch(choic)     {             case
1:        int n;        cout<<"你想输入多少个学生的基本信息?"<<endl;        cin>>n;        int i;        for(i=0;i<n;i++)        {            if(student::total>MIN)            stu=(student *)realloc(stu,(student::total+1)*sizeof(stu));            stu[student::total].Creat();        }        break;              case
2:                for (i=0;i<student::total;i++)        stu.Output();        break; case
3:    //根据学号查询某个学生的基本信息    //查询指定学号的学生的基本信息

return
0;    break;case
4:    //根据学号修改某个学生的基本信息    //修改指定学号的学生的基本信息。

return
0;    break;case
5:    //增加某个学生的基本信息    //增加一个学生的基本信息。

return
0;    break;case
6:    //将所有的学生保存到文件stu.dat中    //将所有学生的信息保存到"stu.dat"文件中。

return
0;    break;case
7:    //统计平均成绩为优秀(大于等于85分)的学生并给出基本信息    //统计并显示平均成绩大于等于85分的学生的基本信息。

return
0;    break;case
8:    //从文件stu.dat中读取所有学生的基本信息    //从文件"stu.dat"读取所有学生的信息。

return
0;    break;case
9:    //退出当前程序

default :cout<<"您的输入有误,请重试!\n";    }  }  return
0;}

TOP

乱了~~再发一遍

#include<iostream>
#include<string>
#include<fstream>
using namespace std;
#define MIN 5

class student
{
        long num;
        string name;
        char sex;
        float math;
        float english;
        float sport;
        float Cplus;
        float sum;
        float ave;

public:
        static int total;
public:
        void Creat();
        void Output();
};

int student::total=0;
void student::Creat()
{
        cout<<"欢迎进入学生的信息建立系统!"<<endl;
        cout<<"学号"<<"\t"<<"姓名"<<"\t"<<"性别"<<"\t"<<"高等数学"<<"\t"<<"英语"<<"\t"<<"大学体育"<<"\t"<<"C++面向程序设计"<<endl;
        cin>>num>>name>>sex>>math>>english>>sport>>Cplus;
        student::total++;
}

void student::Output()
{
        cout<<"学号"<<"\t"<<"姓名"<<"\t"<<"性别"<<"\t"<<"高等数学"<<"\t"<<"英语"<<"\t"<<"大学体育"<<"\t"<<"C++面向程序设计"<<endl;
                cout<<num<<"\t"<<name<<"\t"<<sex<<"\t"<<math<<"\t"<<"\t"<<english<<"\t"<<sport<<"\t"<<"\t"<<Cplus<<endl;
}

//主菜单
void welcome()
{
        cout<<endl<<endl;
        cout<<endl<<endl;
        cout<<"\t             设计:  *******************           "<<endl;
        cout<<"\t***************************************************"<<endl;
        cout<<"\t*             欢迎进入学生成绩管理系统             *"<<endl;
        cout<<"\t*                                                  *"<<endl;
        cout<<"\t*    1:输入            2:输出            3:查询    *"<<endl;
        cout<<"\t*    4:修改            5:增加            6:保存    *"<<endl;
        cout<<"\t*    7:统计            8:读取            9:退出    *"<<endl;
    cout<<"\t****************************************************"<<endl;
        cout<<endl;
        cout<<"请选择你需要的选项:";
}
   


//主函数
int main()
{
    student *stu=new student[MIN];
        welcome();
  int choic;
  while(choic!=0)
  {
           cin>>choic;
       switch(choic)
        {             
        case 1:
                int n;
                cout<<"你想输入多少个学生的基本信息?"<<endl;
                cin>>n;
                int i;
                for(i=0;i<n;i++)
                {
                        if(student::total>MIN)
                        stu=(student *)realloc(stu,(student::total+1)*sizeof(stu));
                        stu[student::total].Creat();
                }
                break;      
           case 2:
               
                for (i=0;i<student::total;i++)
                stu.Output();
                break;
case 3:
        //根据学号查询某个学生的基本信息
        //查询指定学号的学生的基本信息
        return 0;
        break;
case 4:
        //根据学号修改某个学生的基本信息
        //修改指定学号的学生的基本信息。
        return 0;
        break;
case 5:
        //增加某个学生的基本信息
        //增加一个学生的基本信息。
        return 0;
        break;
case 6:
        //将所有的学生保存到文件stu.dat中
        //将所有学生的信息保存到"stu.dat"文件中。
        return 0;
        break;
case 7:
        //统计平均成绩为优秀(大于等于85分)的学生并给出基本信息
        //统计并显示平均成绩大于等于85分的学生的基本信息。
        return 0;
        break;
case 8:
        //从文件stu.dat中读取所有学生的基本信息
        //从文件"stu.dat"读取所有学生的信息。
        return 0;
        break;
case 9:
        //退出当前程序
        default :cout<<"您的输入有误,请重试!\n";
        }
  }
  return 0;
}

TOP

复制内容到剪贴板
代码:

case 3:
cout<<"please input the number of the student you want to find:"<<endl;
int num;
cin>>num;
for (i=0;i<stu->total;i++)
{
  if (stu[i]->num==num)
  {
   cout<<"Here's the student's information:"<<endl;
   cout<<"学号"<<"\t"<<"姓名"<<"\t"<<"性别"<< "\t"<<"高等数学"<<"\t"<<"英语"<<"\t"<<"大学体育"< <"\t"<<"C++面向程序设计"<<endl;
                cout<<stu->num<<"\t"<<stu->name<<"\t"<<stu->sex<<"\t"<<stu->math<<"\t"
     <<"\t"<<stu->english<<"\t"<<stu->sport<<"\t"<<"\t"<<stu->Cplus<<endl;
  }
}

TOP

怎么不能编译啊???

怎么不能编译啊???

TOP

是啊
好象有问题呀?

TOP

case 2语句中,stu是指针对象,不能像一般对象用“.”调用函数,而要用“->”  stu->Output();

TOP

不知道楼主为什么没有调试到那个错误,我一调试就指示那里有错啊。根据错误提示error C2228: left of '.Output' must have class/struct/union type
Error executing cl.exe.很容易知道是函数调用的错误

TOP

是应该用“->”访问的。
悟空,其实当年我很想留在女儿国的。。。吾悔不听八戒之言呐!

TOP

帮帮忙~~~

怎么该啊?写出来行吗??谢谢啦~~

TOP

帮帮看看

我写出来的是可以编译的~~只是加了二楼写的就不能编译啦~~帮帮看看

TOP

发新话题