-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