It works now.( see following posts). It still has the set function not as streamlined or accurate as it should be though (and a constructor that does nothing...) thanks.
H file
Code:
#ifndef lab0_h
#define lab0_h
#include<string>
#include <iostream>
using namespace std;
class Student
{
string name,userid;
public:
Student();
void setData();
string getId();
string getName();
};
#endif
imp file
Code:
#include "lab0.h"
using namespace std;
Student::Student ()
{
name;
userid;
}
void Student::setData()
{
cout<< "Please enter Student name:";
getline(cin, name);
cout<< "Please enter Student ID:";
cin>> userid;
cin.ignore();
}
string Student::getId()
{
return userid ;
}
string Student::getName()
{
return name;
}
Code:
#include <iostream>
#include "lab0.h"
using namespace std;
int main()
{
string search;
Student roster[3];
for (int i=0 ;i<3;i++)
{
roster[i].setData();
}
while ( search != "exit")
{
cout << "enter an ID or Name to search for type exit to quit: ";
getline(cin, search);
bool found = false;
for (int j=0;j<3;j++)
{
if (roster[j].getName() == search)
{
cout << roster[j].getId() << endl;
found = true;
}
else if (roster[j].getId() == search)
{
cout<< roster[j].getName()<< endl;
found = true;
}
}
if (search == "exit" )
break;
if (!found)
cout << "no match "<< endl;
}
system("PAUSE");
return 0;
}