Write a program which takes input of 10 students data data i
Solution
main.cpp
#include<iostream>
#include \"class.h\"
#include \"functions.cpp\"
#include<string>
using namespace std;
int main()
{
int totalStd=2;
student k[totalStd];
int i;
for(i=0;i<totalStd;i++)
{
cout<<\"\ Enter Student \"<<i+1<<\" data\ \";
k[i].inputData();
}
while(1)
{
int choice;
cout<<\"\ 1.Search\ 2.Exit\ \";
cin>>choice;
if(choice==1)
student::searchData(k,totalStd);
if(choice==2)
break;
}
return 0;
}
class.h
#include<string>
using namespace std;
class student
{
private:
string reg_no;
string first_name;
string middle_name;
string last_name;
string contact_number;
public:
void inputData();
void printData();
void static searchData(student *arr,int length);
};
functions.cpp
void student::inputData()
{
cout<<\"Enter Registration Number\ \";
cin>>reg_no;
cout<<\"Enter First Name\ \";
cin>>first_name;
cout<<\"Enter Middle Name\ \";
cin>>middle_name;
cout<<\"Enter Last Name\ \";
cin>>last_name;
cout<<\"Enter Contact Number\ \";
cin>>contact_number;
}
void student::printData()
{
cout<<\"\ Registration Number->\";
cout<<reg_no;
cout<<\"\ First Name->\";
cout<<first_name;
cout<<\"\ Middle Name->\";
cout<<middle_name;
cout<<\"\ Last Name->\";
cout<<last_name;
cout<<\"\ Contact Number->\";
cout<<contact_number;
}
void student::searchData(student *arr,int length)
{
int k=1;
do
{
cout<<\"\ Search with \ 1.Registration Number\ 2.First Name\ 3.Middle Name\ 4.Contact Number\ \";
cin>>k;
}
while(k<1||k>4);
int i;
if(k==1)
{
cout<<\"Enter Registration Number\ \";
string regNo;
cin>>regNo;
for(i=0;i<length;i++)
{
if(regNo==arr[i].reg_no)
{
arr[i].printData();
}
}
}
if(k==2)
{
cout<<\"Enter First Name\ \";
string fName;
cin>>fName;
for(i=0;i<length;i++)
{
if(fName==arr[i].first_name)
{
arr[i].printData();
}
}
}
if(k==3)
{
cout<<\"Enter Middle Name\ \";
string mName;
cin>>mName;
for(i=0;i<length;i++)
{
if(mName==arr[i].middle_name)
{
arr[i].printData();
}
}
}
if(k==4)
{
cout<<\"Enter Contact Number\ \";
string cNo;
cin>>cNo;
for(i=0;i<length;i++)
{
if(cNo==arr[i].contact_number)
{
arr[i].printData();
}
}
}
}
Sample Run
Enter Student 1 data
Enter Registration Number
1
Enter First Name
Ajay
Enter Middle Name
Kumar
Enter Last Name
Verma
Enter Contact Number
7894561230
Enter Student 2 data
Enter Registration Number
2
Enter First Name
Vinay
Enter Middle Name
Kumar
Enter Last Name
Chauhan
Enter Contact Number
9638527410
1.Search
2.Exit
1
Search with
1.Registration Number
2.First Name
3.Middle Name
4.Contact Number
1
Enter Registration Number
2
Registration Number->2
First Name->Vinay
Middle Name->Kumar
Last Name->Chauhan
Contact Number->9638527410
1.Search
2.Exit



