These are my two classes that hold my data: Base Class holding basic person data:
#ifndef H_personType
#define H_personType
#include <string>
using namespace std;
class person
{
public:
//get functions
string getName() const;
string getId() const;
string getAge() const;
string getGender() const;
string getPhone() const;
string getEmPhone() const;
string getAddress() const;
string getEmail() const;
string getEmContact() const;
//set functions
void setName(string, string, string);
void setId(string);
void setAge(string);
void setGender(string);
void setPhone(string);
void setEmPhone(string);
void setAddress(string, string);
void setEmail(string);
void setEmContact(string, string);
//constructors
person();
person(string, string, string,
string, string, string, string,
string, string, string,
string, string, string,
string, string);
private:
string firstName;
string lastName;
string middleName;
string id;
string age;
string phone;
string address;
string streetNumber;
string streetName;
string gender;
string email;
string emergency_phone;
string emergencyFirstName;
string emergencyLastName;
string emergency_contact;
};
Derived Class student that holds member functions to modify data and private members specific for a student.
#ifndef H_studentType
#define H_studentType
#include "personType.h"
#include <vector>
using namespace std;
class student: public person
{
public:
//void sortRecords();
friend int checkSize();
void addRecords();
void input(istream&, int);
void print(ostream&) const;
void printRecords(ostream&);
void loadData();
void displayOnScreen();
void searchID(string, int);
student();
student(string, string, string,
string, string, string, string, string, string,
string, string, string, string, string, string,
string, string, string, string);
protected:
vector<string> tempVec[11];
private:
string gpa;
string hobbies;
string major;
string honors;
vector<student> students;
};
#endif
Those two classes are what hold my data. I use an input function to read a simple text input file that holds rows of data for a student, think name, age etc.. the input function fills the vector of type student.
Input function:
void student::input(istream& inF, int size)
{
//local variables
student stud;
string first, middle, last, addressNum, addressStreet,
phone, gender, email, emContactFirst, emContactLast,
ph, emPhone,ID, age;
while (!inF.eof())
{
for (int index = 0; index < size; index++){
inF >> first >> last >> middle;
stud.setName(first, last, middle);
inF >> ID;
stud.setId(ID);
inF >> age;
stud.setAge(age);
inF >> phone;
stud.setPhone(phone);
inF >> addressNum >> addressStreet;
stud.setAddress(addressNum, addressStreet);
inF >> gender;
stud.setGender(gender);
inF >> email;
stud.setEmail(email);
inF >> emPhone;
stud.setEmPhone(emPhone);
inF >> emContactFirst >> emContactLast;
stud.setEmContact(emContactFirst, emContactLast);
inF >> stud.gpa >> stud.hobbies >> stud.major;
students.push_back(stud);
}
}
}
After this all my data from my input file is stored in the vector of type student, basically a vector of classes that hold my data. In order to perform manipulation on this data (search by studentID, delete record by studentID, modify record by student ID) I want to load it from the vector of classes into an array of string vectors. This is where my mind is melting and I've been stuck for a long time. Here is my load data function and displayOnScreen that simply won't cooperate. The display on screen function is simply for debugging purposes so I can see my filled array printed out.
void student::loadData()
{
int i = 0;
for (vector<student>::iterator it = students.begin(); it != students.end(); it++)
{
for (i = 0; i < 11; i++)
{
cout << "ID = " << it->getId();
tempVec[i].push_back(it->getName());
tempVec[i].push_back(it->getId());
tempVec[i].push_back(it->getAge());
tempVec[i].push_back(it->getPhone());
tempVec[i].push_back(it->getAddress());
tempVec[i].push_back(it->getEmail());
tempVec[i].push_back(it->getEmPhone());
tempVec[i].push_back(it->getEmContact());
tempVec[i].push_back(it->gpa);
tempVec[i].push_back(it->honors);
tempVec[i].push_back(it->major);
}
if (i = 10)
break;
}
}
void student::displayOnScreen()
{
for (vector<string>::iterator it = tempVec[1].begin(); it != tempVec[1].end(); it++){
for (int u = 0; u < 11; u++)
{
cout << tempVec[1].at(u) << " ";
}
cout << endl;
}
}
Please, I know this is a huge question and any assistance is much appreciated.