-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