hey ..
please i need tutorial 4 vector .. because i'm tring to convert this code from array to vector .. but i failed .. so i think my way is wrong .. :(
#include<iostream>
using namespace std;
#include<string>
#include<vector>
class student_recored{
vector<int> ex;
string name;
long ID;
public:
void set_name(string n)
{
name=n;
}
void set_id(long id)
{
ID=id;
}
string getname()
{
return name;
}
long getid()
{
return ID;
}
void SearchId(vector<int> &ex, int num , long studentid){
for ( int j=0; j < num; j++ ){
if ( studentid == ex[j].getid() ){
cout<< "student is found .. student name is : "<< ex[j].getname()<< endl;
break;}
else
cout<< "student is not found " << endl;}
}
};
int main()
{
vector<int> ex;
int num=0,choose,i;
string n;
long id;
cout<<" *******************\n";
cout<<".... Welcome To Student Program ...\n";
cout<<"Choose one of the following :- \n";
cout<<"1- Add students.\n";
cout<<"2- search for student .\n";
cout<<"3- Exit ...\n";
cout<<" ********************\n";
cout<<"Please Enter your choose : ";
cin>>choose;
while ( choose != 3 ){
switch (choose)
{
case 1 :
cout<< "\nplease enter how many students do you want to add : ";
cin>>num;
for (i=0; i<ex.size(); i++)
{
cout<<"\nplease enter the name for student ["<<i<<"] : ";
cin>>n;
cout<<"\nplease enter the id for student ["<<i<<"] : ";
cin>>id;
ex[i].set_name(n);
ex[i].set_id(id);
}
break;
case 2 :
long studentid;
cout<<"please enter id number to search on it : ";
cin>>studentid;
ex[i].SearchId(ex,num ,studentid);
break;
case 3 :
cout<<"Exist ..\n";
break;
default : cout<<"wrong choose number\n";
break;
}
cout<<"\nEnter your choose : ";
cin>>choose;
}
return 0;
}
thanx .. :)