首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于C++中的主函数的定义函数有关问题,新手,大家来帮帮,多谢了

2012-04-20 
关于C++中的主函数的定义函数问题,新手求助,在线等,大家来帮帮,谢谢了C/C++ code#includeiostreamusing

关于C++中的主函数的定义函数问题,新手求助,在线等,大家来帮帮,谢谢了

C/C++ code
#include<iostream>using namespace std;#include<string>class Student{public:    void input();    void output();private:    int num;    string name;    float cplusplus,math,English;};void Student::input(){    cout <<"学生学号为:";    cin >>num;    cout <<"学生名字为:";    cin >>name;    cout <<"学生cplusplus,数学,英语成绩分别为:";    cin >>cplusplus >>math >>English;};void Student::output(){    cout <<"   "<<num <<"   " << name <<"   " <<cplusplus <<"   " <<math <<"   " <<English <<endl;}void check(class Student stu,int i){    int m,n,h=1;    while(h==1)    {cout <<"需要查询的同学的学号:";     cin >>m;     m=m-1;     for(n=0;n<i;n++)     {        if(m==n)         {stu[m].output();        cout <<"good";         break;        };        if(n==i-1) cout <<"无该学生信息" <<endl;        if(m>i)         {cout<< "无该学生信息"<<endl;         break;        }     }      cout <<"1.继续查找 2.退出" <<endl;     cin >> h;    }}int main(){    int i,j;    //共有多少个学生    cout <<"How many students in total:";    cin >>i;    //定义学生的类       Student stu[60];    //输入信息    cout<<endl <<"输入学生信息"<<endl;     for(j=0;j<i;j++)    {        stu[j].input();        cout<<"下一个学生信息"<<endl;    };    //输出信息    cout <<"输入学生总体信息为:"<<endl;    cout <<"   "<<"学号" <<"   " <<"名字" <<"   " <<"cplusplus" <<"   " <<"math" <<"   " <<"English" <<endl;    for(j=0;j<i;j++)    {        stu[j].output();        cout<<endl;    }    //学生信息查询    check(stu,i);    return 0;}

void check(class Student stu,int i)中的stu[m].output();有错误,什么意思,新手求助,拍砖轻点哦,谢谢了
错误提示C++学生成绩有问题的.cpp
C:\Documents and Settings\Administrator\桌面\C++学生成绩有问题的.cpp(42) : error C2676: binary '[' : 'class Student' does not define this operator or a conversion to a type acceptable to the predefined operator
C:\Documents and Settings\Administrator\桌面\C++学生成绩有问题的.cpp(42) : error C2228: left of '.output' must have class/struct/union type
C:\Documents and Settings\Administrator\桌面\C++学生成绩有问题的.cpp(85) : error C2664: 'check' : cannot convert parameter 1 from 'class Student [60]' to 'class Student'
  No constructor could take the source type, or constructor overload resolution was ambiguous
执行 cl.exe 时出错.

[解决办法]
check函数传入的是对象,不是数组;

[解决办法]
void check(class Student stu,int i)
将该函数的第一个参数定义为数组或指针就可以了,因为你传递过来的实参是指针

修改如下:

void check(class Student stu[],int i)

[解决办法]
void check(class Student stu,int i)-->
void check(Student* stu,int i)

楼主多看书打好基础啊

[解决办法]
探讨
void check(class Student stu,int i)
将该函数的第一个参数定义为数组或指针就可以了,因为你传递过来的实参是指针

修改如下:

void check(class Student stu[],int i)

热点排行