My main.cpp
Code:
#include <vector>
#include "misc.h"
#include "person.h"
using namespace std;
int main (void) {
vector<Lecturer> vecLec;
vector<Student> vecStd;
insertData (vecLec, vecStd);
return 0;
};
My misc .cpp
Code:
//************************************
// misc.cpp
//************************************
#include "misc.h"
string rmLeadSpc (string in) {
string temp = in;
size_t idx = temp.find_first_not_of (" \t\n\r");
if (idx != string::npos) {
temp = temp.substr (idx);
} else {
temp = string("");
};
return temp;
};
string rmTrailSpc (string in) {
string temp = in;
size_t idx = temp.find_last_not_of (" \t\n\r");
if (idx != string::npos) {
temp = temp.substr (0, idx + 1);
};
return temp;
};
vector<string> tokenise (string in, string delim) {
// delimeter cannot be empty
if (delim.empty()) delim = ",";
vector<string> tokens;
string::size_type i = 0, j = 0;
while (i != string::npos) {
j = in.find_first_of (delim, i);
string token = rmLeadSpc(rmTrailSpc(in.substr (i, j - i)));
if (!token.empty()) tokens.push_back (token);
if (j == string::npos) break;
i = j + 1;
}
return tokens;
};
misc.h
Code:
//************************************
// misc.h
//************************************
#ifndef MISC_H
#define MISC_H
#include <string>
#include <vector>
using namespace std;
enum PersonType {
LECTURER,
STUDENT
};
class Date {
private:
int year;
int month;
int day;
public:
void setYear (int inYear) {year = inYear;};
void setMonth (int inMonth) {month = inMonth;};
void setDay (int inDay) {day = inDay;};
int getYear (void) {return year;};
int getMonth (void) {return month;};
int getDay (void) {return day;};
};
string rmLeadSpc (string in);
string rmTrailSpc (string in);
vector<string> tokenise (string in, string delim = ",");
#endif
My Person.cpp
Code:
#include <iostream>
#include <string>
#include "Person.h"
#include "misc.h"
using namespace std;
Person::Person(PersonType inPType, string inName, string inNric)
{
type = inPType;
name = inName;
nric = inNric;
}
void Person:: setDob (int inYear, int inMonth, int inDay)
{
dob.setYear(inYear);
dob.setMonth(inMonth);
dob.setDay(inDay);
}
PersonType Person::getType (void)
{
//PersonType.Lecturer;
//PersonTypw.Student;
}
string Person::getName(void)
{
return name;
}
string Person::getNric(void)
{
return nric;
}
int Person::getDobYear(void)
{
return inYear;
}
int Person::getDobMonth(void)
{
return inMonth;
}
int Person::getDobDay(void)
{
return inDay;
}
Lecturer::Lecturer(string inName, string inNric, string inRoom, int inSal)
:Person(PersonType inPType, string inName, string inNric)
{
room = inRoom;
salary = inSal;
}
void Lecturer::increment(int pct)
{
pct = salary * 0.1 + salary;
}
int Lecturer::getCount (void)
{
}
string Lecturer::getRoom(void)
{
return room;
}
int Lecturer::getSalary(void)
{
return salary;
}
Student::Student(string inName, string inNric, string inAdminNo, string inDiploma)
:Person(PersonType inPType, string inName, string inNric)
{
adminNo = inAdminNo;
diploma = inDiploma;
}
int Student::avgScores(void)
{
}
Person.h
Code:
//************************************
// person.h
//************************************
#ifndef PERSON_H
#define PERSON_H
#include <string>
#include <vector>
#include "misc.h"
using namespace std;
class Person {
private:
PersonType type;
string name;
string nric;
Date dob;
public:
Person (PersonType inPType, string inName, string inNric);
void setDob (int inYear, int inMonth, int inDay);
PersonType getType (void);
string getName (void);
string getNric (void);
int getDobYear (void);
int getDobMonth (void);
int getDobDay (void);
};
class Lecturer : public Person {
private:
string room;
int salary;
static int count;
public:
Lecturer (string inName, string inNric, string inRoom, int inSal);
void increment (int pct);
static int getCount (void);
string getRoom (void);
int getSalary (void);
};
class Student : public Person {
private:
string adminNo;
string diploma;
static int count;
int scores[3];
string grades[3];
public:
Student (string inName, string inNric, string inAdminNo, string inDiploma);
static int getCount (void) {return count;};
int getScores (int module) {return scores[module];};
string getGrades (int module) {return grades[module];};
string getAdminNo (void) {return adminNo;};
string getDiploma (void) {return diploma;};
int avgScores (void);
};
void insertLec (vector<Lecturer> & vecLec, vector<string> parts);
int avgSal (vector<Lecturer> & vecLec);
void insertStd (vector<Student> & vecStd, vector<string> parts);
int avgScore (vector<Student> & vecStd, int module);
int getCount (vector<Student> & vecStd, string diploma);
void insertData (vector<Lecturer> & vecLec, vector<Student> & vecStd);
#endif
Seriously, this is the most difficult part in my college lesson and the assignment that I had to be done. All my basic Person.cpp is the part where I think I had wrongly declared, especially the part where the enum with STUDENT and LECTURER and the function getType with PersonTYpe declared instead of void or int. How do I write in Person.cpp code, i completely lost this part here. Another part is the part where I had done using composition. I think the Person.cpp for the code is completely wrong for the composition. Give me some advice please. Anyway, alll the other codes are written by my lecturer expect the Person.cpp which is wrote by me. So, all the files have no problem expect the Person.cpp