-2
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class student
{ int rno;
char name[20];
float total;
public:
void In();
void Out();
void search(student ob[50],int,int);
int retrno()
{ return rno; //returns the roll no of student
}
};
void student::search(student ob[],int n,int srno)
{ int flag=0;
for(int i=0;i<n;++i)
if(ob[i].retrno()==srno) //checking for rollno match
{ flag=1;
cout<<"Student found";
ob[i].Out(); //calling Out() when match is found
}
if(flag==0)
cout<<"No matching records";
}
void student::In()
{ cout<<"Enter rno:";
cin>>rno;
cout<<"Enter name:";
gets(name);
cout<<"Enter total:";
cin>>total;
}
void student::Out()
{ cout<<"rno:";
cout<<rno;
cout<<"Name:";
puts(name);
cout<<"Total:";
cout<<total;
}
void main()
{ student ob[50];
int n,srno;
cout<<"Enter no. of students:";
cin>>n;
for(int i=0;i<n;++i)
ob[i].In(); //In() is called n times
cout<<"Enter rno to be searched:";
cin>>srno;
ob.search(ob,n,srno);
}
在编译时,我得到2个错误。传递一系列搜索对象
11: Undefined structure 'student'
52: Structure required on left side of . or .*
我想看看有没有函数原型一个错误,但它看起来fine.I累原型没有数组的大小,并获得同样的错误。我也尝试过在全球范围内初始化班级,但得到同样的错误(我用完了想法)。 请帮我找出问题所在。
'ob.search(OB,N,srno);'你需要指定一个索引:'ob [42] .search(ob,n,srno);' –
没有解决你的问题,如果你有任何书推荐使用'iostream.h'或'conio.h',书可能是可怕的过时。混合IOStreams和stdio也不是一个好主意。获取更新的教程。 –
@πάνταῥεῖ我试过现在。第一个错误仍然存在。由于我在search()中运行for循环,会指定索引创建问题吗? – SMcCK