Question: Need help in c++, code is having issues with the output and getting random numbers main.cpp ---------------------------------------------------------------- #include University.h int main() { University csusm; csusm.ProcessTransactionFile(TransactionFile.txt);

Need help in c++, code is having issues with the output and getting random numbers
main.cpp
----------------------------------------------------------------
#include "University.h"
int main()
{
University csusm;
csusm.ProcessTransactionFile("TransactionFile.txt");
}
----------------------------------------------------------------------------------------------
Course.cpp
----------------------------------------------------------------
#include "Course.h"
long Course::nextCRN = 200;
Course::Course()
{
CRN = nextCRN++;
name = "SPACE";
maxAvaliableSeats = departId = assignedSeats = isTaughtBy = 0;
}
Course::Course(string theName, long theDepartId, long taughtBy, int theMaxAvaliableSeats)
{
CRN = nextCRN++;
maxAvaliableSeats = theMaxAvaliableSeats;
name = theName;
departId = theDepartId;
isTaughtBy = taughtBy;
}
void Course::Print()
{
cout << "CRN: " << CRN << endl;
cout << "Name: " << name << endl;
}
---------------------------------------------------------------------------------------------
Course.h
---------------------------------------------------------
#ifndef COURSE_H
#define COURSE_H
#include
#include
#include
using namespace std;
class Course
{
friend class University;
protected:
long CRN;
int maxAvaliableSeats;
string name;
long departId;
long assignedSeats;
long isTaughtBy;
static long nextCRN;
public:
Course();
Course(string theName, long theDepartId, long taughtBy, int theMaxAvaliableSeats);
void Print();
};
#endif
--------------------------------------------------------------------------------------------------------
Department.cpp
------------------------------------------------
#include "Department.h"
long Department::nextDepartId = 100;
Department::Department()
{
id = nextDepartId++;
name = location = "SPACE";
chairId = 0;
}
Department::Department(string theName, string theLocation, long theChairId)
{
id = nextDepartId++;
name = theName;
location = theLocation;
chairId = theChairId;
}
void Department::Print()
{
cout << "ID: " << id << endl;
cout << "Name: " << name << endl;
}
---------------------------------------------------------------------------------------------------------
Department.h
---------------------------------------------------
#ifndef DEPARTMENT_H
#define DEPARTMENT_H
#include
#include
#include
using namespace std;
class Department
{
friend class University;
protected:
long id;
string name;
string location;
long chairId;
static long nextDepartId;
public:
Department();
Department(string theName, string theLocation, long theChairId);
void Print();
};
#endif
-----------------------------------------------------------------------------------------------------------
Faculty.cpp
------------------------------------------------
#include "Faculty.h"
long Faculty::nextFacultyId = 600;
Faculty::Faculty():Person()
{
id = nextFacultyId++;
salary = yearOfExp = deparId = 0;
}
Faculty::Faculty(string theName, string theEmail, string theAddress, string theDateOfBirth, string theGender, float theSalary, int theYearOfExp, long theDeparId):Person(theName, theEmail, theAddress, theDateOfBirth, theGender)
{
id = nextFacultyId++;
salary = theSalary;
yearOfExp = theYearOfExp;
deparId = theDeparId;
}
void Faculty::Print()
{
cout << "ID: " << id << endl;
cout << "Name: " << name << endl;
}
------------------------------------------------------------------------------------------------------------
Faculty.h
-------------------------------------------------
#ifndef FACULTY_H
#define FACULTY_H
#include
#include
#include
#include "Person.h"
using namespace std;
class Faculty:public Person
{
friend class University;
protected:
long id;
float salary;
int yearOfExp;
long deparId;
static long nextFacultyId;
public:
Faculty();
Faculty(string theName, string theEmail, string theAddress, string theDateOfBirth, string theGender, float theSalary, int theYearOfExp, long theDeparId);
void Print();
};
#endif
---------------------------------------------------------------------------------------------------------
Person.cpp
---------------------------------------
#include "Person.h"
Person::Person()
{
name = email = address = dateOfBirth = gender = "SPACE";
}
Person::Person(string theName, string theEmail, string theAddress, string theDateOfBirth, string theGender)
{
name = theName;
email = theEmail;
address = theAddress;
dateOfBirth = theDateOfBirth;
gender = theGender;
}
-------------------------------------------------------------------------------------------------------
Person.h
----------------------------------------------
#ifndef PERSON_H
#define PERSON_H
#include
#include
#include
using namespace std;
class Person
{
protected:
string name;
string email;
string address;
string dateOfBirth;
string gender;
public:
Person();
Person(string theName, string theEmail, string theAddress, string theDateOfBirth, string theGender);
};
#endif
------------------------------------------------------------------------------------------------------------
Student.cpp
---------------------------------------------------------
#include "Student.h"
long Student::nextStId = 500;
Student::Student():Person()
{
id = nextStId++;
yearOfStudy = advisorId = 00000;
major = "SPACE";
}
Student::Student(string theName, string theEmail, string theAddress, string theDateOfBirth, string theGender, int theYearOfStudy, string theMajor, long theAdvisorId):Person(theName, theEmail, theAddress, theDateOfBirth, theGender)
{
id = nextStId++;
yearOfStudy = theYearOfStudy;
advisorId = theAdvisorId;
major = theMajor;
}
void Student::Print()
{
cout << "ID: " << id << endl;
cout << "Name: " << name << endl;
}
-----------------------------------------------------------------------------------------------------
Student.h
-----------------------------------------------------------
#ifndef STUDENT_H
#define STUDENT_H
#include
#include
#include
#include "Person.h"
#include "Course.h"
using namespace std;
class Student:public Person
{
friend class University;
protected:
long id;
int yearOfStudy;
string major;
long advisorId;
vector coursesTaken;
static long nextStId;
public:
Student();
Student(string theName, string theEmail, string theAddress, string theDateOfBirth, string theGender, int theYearOfStudy, string theMajor, long theAdvisorId);
void Print();
};
#endif
-----------------------------------------------------------------------------------------------------
University.cpp
---------------------------------------------
#include "University.h"
bool University::failure = false;
bool University::success = true;
University::University()
{
}
University::~University()
{
}
*/
bool University::CreateNewDepartment(string depName, string depLoc, long depChairId)
{
if ((depChairId != 0) && (!FacultyExist(depChairId)))
{
cout << "The chair with id: " << depChairId << " does not exist" << endl << endl;
return failure;
}
Department D(depName, depLoc, depChairId);
Departments.push_back(D);
return success;
}
/* This rutine checks the vector of Faculties for an object matching the passed id*/
bool University::FacultyExist(long FacId)
{
for (int i = 0; i < Faculties.size(); i++)
{
if (Faculties[i].id == FacId)
return success;
}
return failure;
}
bool University::CreateNewStudent(string sName, string sEmail, string sAddress, string sDateOfBirth, string sGender,int sYearOfStudy, string sMajor, long sAdvisorId)
{
if ((sMajor != "0") && (!DepartmentExist(sMajor)))
{
cout << "The major: " << sMajor << " does not exist" << endl << endl;
return failure;
}
else if ((sAdvisorId != 0) && (!FacultyExist(sAdvisorId)))
{
cout << "The student advisor id: " << sAdvisorId << " does not exist" << endl << endl;
return failure;
}
Student S(sName, sEmail, sAddress, sDateOfBirth, sGender, sYearOfStudy, sMajor, sAdvisorId);
Students.push_back(S);
return success;
}
/* This rutine checks the vector of Departments for an object matching the passed department name*/
bool University::DepartmentExist(string DepName)
{ for (int i = 0; i < Departments.size(); i++)
{
if (Departments[i].name == DepName)
return success;
}
return failure;
}
bool University::CreateNewCourse(string cName, long cDepId, long cTaughtBy, int cMaxSeat)
{
if ((cTaughtBy != 0) && (! FacultyExist(cTaughtBy)))
{
cout << "The faculty id: " << cTaughtBy << " does not exist" << endl << endl;
return failure;
}
else if (! DepIdExist(cDepId))
{
cout << "The department id: " << cDepId << " does not exist" << endl << endl;
return failure;
}
Course C(cName, cDepId, cTaughtBy, cMaxSeat);
Courses.push_back(C);
return success;
}
/* This rutine checks the vector of Departments for an object matching the passed id*/
bool University::DepIdExist(long DepId)
{
for (int i = 0; i < Departments.size(); i++)
{
if (Departments[i].id == DepId)
return success;
}
return failure;
}
bool University::CreateNewFaculty(string fName, string fEmail, string fAddress, string fDateOfBirth, string fGender,float fSalary, int fYearOfExp, long fDepId)
{
if (!DepIdExist(fDepId))
{
cout << "The department id: " << fDepId << " does not exist" << endl << endl;
return failure;
}
Faculty F(fName, fEmail, fAddress, fDateOfBirth, fGender, fSalary, fYearOfExp, fDepId);
Faculties.push_back(F);
return success;
}
bool University::ListCoursesTaughtByFaculty(long facultyId)
{
if (!FacultyExist(facultyId))
{
cout << "The faculty id: " << facultyId << " does not exist" << endl << endl;
return failure;
}
cout << "COURSES TAUGHT BY FACULTY WITH ID: " << facultyId << endl;
for(int i = 0; i < Courses.size(); i++)
{
if (Courses[i].isTaughtBy == facultyId)
Courses[i].Print();
cout << endl;
}
return success;
}
bool University::ListCoursesTakenByStudent(long studentId)
{
if (!stuExist(studentId))
{
cout << "The student id: " << studentId << " does not exist" << endl << endl;
return failure;
}
cout << "COURSES TAKEN BY STUDENT WITH ID: " << studentId << endl;
for(int i = 0; i < Students.size(); i++)
{
if (Students[i].id == studentId)
{
for (int j = 0; j < Courses.size(); j++)
{
Students[i].coursesTaken[j].Print();
cout << endl;
}
}
}
return success;
}
/* This rutine checks the vector of Students for an object matching the passed id*/
bool University::stuExist(long stuId)
{
for (int i = 0; i < Students.size(); i++)
{
if (Students[i].id == stuId)
return success;
}
return failure;
}
/* This rutine checks the vector of Courses for an object matching the passed id*/
bool University::CourExist(long courID)
{
for (int i = 0; i < Courses.size(); i++)
{
if (Courses[i].CRN == courID)
return success;
}
return failure;
}
bool University::ListFacultiesInDepartment (long departId)
{
if (!DepIdExist(departId))
{
cout << "The department id: " << departId << " does not exist" << endl << endl;
return failure;
}
cout << "FACULTIES OF DEPARTMENT WITH ID: " << departId << endl;
for(int i = 0; i < Faculties.size(); i++)
{
if (Faculties[i].deparId == departId)
Faculties[i].Print();
cout << endl;
}
return success;
}
bool University::ListStudentsOfAFaculty(long facultyId)
{
if (!FacultyExist(facultyId))
{
cout << "The faculty id: " << facultyId << " does not exist" << endl << endl;
return failure;
}
cout << "STUDENTS OF FACULTY WITH ID: " << facultyId << endl;
for(int i = 0; i < Students.size(); i++)
{
if (Students[i].advisorId == facultyId)
Students[i].Print();
cout << endl;
}
return success;
}
bool University::ListCoursesOfADepartment(long deparId)
{
if (!DepIdExist(deparId))
{
cout << "The department id: " << deparId << " does not exist" << endl << endl;
return failure;
}
cout << "COURSES OF DEPARTMENT WITH ID: " << deparId << endl;
for(int i = 0; i < Courses.size(); i++)
{
if (Courses[i].departId == deparId)
Courses[i].Print();
cout << endl;
}
return success;
}
bool University::AddACourseForAStudent(long courseId, long stId)
{
if (!stuExist(stId))
{
cout << "The student id: " << stId << " does not exist" << endl << endl;
return failure;
}
if(!CourExist(courseId))
{
cout << "The course id: " << courseId << " does not exist" << endl << endl;
return failure;
}
for(int i = 0; i < Students.size(); i++)
{
if (Students[i].id == stId)
{
if (Courses[i].maxAvaliableSeats == Courses[i].assignedSeats)
{
return failure;
cout << "Course with number: " << courseId << " is full" << endl << endl;
}
for(int j = 1; j < Courses.size(); j++)
{
if (Courses[j].CRN == courseId)
{
Students[i].coursesTaken.push_back(Courses[j]);
Courses[j].assignedSeats++;
}
}
}
}
return success;
}
bool University::AssignDepartmentChair(long facultyId, long departId)
{
if(!FacultyExist(facultyId))
{
cout << "The faculty id: " << facultyId << " does not exist" << endl << endl;
return failure;
}
if(!DepIdExist(departId))
{
cout << "The department id: " << departId << " does not exist" << endl << endl;
return failure;
}
for(int i = 0; i < Departments.size(); i++)
{
if (Departments[i].id == departId)
{
Departments[i].chairId = facultyId;
return success;
}
}
}
bool University::AssignInstructorToCourse (long facultyId, long courseId)
{
if(!FacultyExist(facultyId))
{
cout << "The faculty id: " << facultyId << " does not exist" << endl << endl;
return failure;
}
if(!CourExist(courseId))
{
cout << "The course id: " << courseId << " does not exist" << endl << endl;
return failure;
}
for(int i = 0; i < Courses.size(); i++)
{
if (Courses[i].CRN == courseId)
{
Courses[i].isTaughtBy = facultyId;
return success;
}
}
}
bool University::ListDepartments()
{
cout << "DEPARTMENTS" << endl;
for(int i = 0; i < Departments.size(); i++)
{
Departments[i].Print();
cout << endl;
}
}
bool University::ListStudents()
{
cout << "STUDENTS" << endl;
for(int i = 0; i < Students.size(); i++)
{
Students[i].Print();
cout << endl;
}
}
bool University::ListCourses()
{
cout << "COURSES" << endl;
for(int i = 0; i < Courses.size(); i++)
{
Courses[i].Print();
cout << endl;
}
}
bool University::ListFaculties()
{
cout << "FACULTIES" << endl;
for(int i = 0; i < Faculties.size(); i++)
{
Faculties[i].Print();
cout << endl;
}
}
bool University::ProcessTransactionFile(string fileName)
{
fstream fin;
string comand;
string word1;
string word2;
string word3;
string word4;
string word5;
string word6;
int num;
long id;
long id2;
float salary;
fin.open(fileName.data());
if (!fin)
cout << "Could not open file, file might not exist." << endl;
while (fin >> comand)
{
if (comand == "CreateNewDepartment")
{
fin >> word1;
fin >> word2;
fin >> id;
CreateNewDepartment(word1, word2, id);
}
if (comand == "ListDepartments")
{
ListDepartments();
}
if (comand == "CreateNewFaculty")
{
fin >> word1;
fin >> word2;
fin >> word3;
fin >> word4;
fin >> word5;
fin >> salary;
fin >> num;
fin >> id;
CreateNewFaculty(word1, word2, word3, word4, word5, salary, num, id);
}
if (comand == "ListFaculties")
{
ListFaculties();
}
if (comand == "ListFacultiesInDepartment")
{
fin >> id;
ListFacultiesInDepartment(id);
}
if (comand == "CreateNewStudent")
{
fin >> word1;
fin >> word2;
fin >> word3;
fin >> word4;
fin >> word5;
fin >> num;
fin >> word6;
fin >> id;
CreateNewStudent(word1, word2, word3, word4, word5, num, word6, id);
}
if (comand == "ListStudents")
{
ListStudents();
}
if (comand == "ListStudentsOfAFaculty")
{
fin >> id;
ListStudentsOfAFaculty(id);
}
if (comand == "CreateNewCourse")
{
fin >> word1;
fin >> id;
fin >> id2;
fin >> num;
CreateNewCourse(word1, id, id2, num);
}
if (comand == "ListCourses")
{
ListCourses();
}
if (comand == "ListCoursesTaughtByFaculty")
{
fin >> id;
ListCoursesTaughtByFaculty(id);
}
if (comand == "ListCoursesOfADepartment")
{
fin >> id;
ListCoursesOfADepartment(id);
}
if (comand == "AddACourseForAStudent")
{
fin >> id;
fin >> id2;
AddACourseForAStudent(id, id2);
}
if (comand == "ListCoursesTakenByStudent")
{
fin >> id;
ListCoursesTakenByStudent(id);
}
if (comand == "AssignDepartmentChair")
{
fin >> id;
fin >> id2;
AssignDepartmentChair(id, id2);
}
if (comand == "AssignInstructorToCourse")
{
fin >> id;
fin >> id2;
AssignInstructorToCourse(id, id2);
}
}
fin.close();
}
--------------------------------------------------------------------------------------
University.h
--------------------------------------------------------
#ifndef UNIVERSITY_H
#define UNIVERSITY_H
#include
#include
#include
#include
#include "Department.h"
#include "Course.h"
#include "Student.h"
#include "Faculty.h"
#include "Student.h"
using namespace std;
class University
{
protected:
vector Departments;
vector Students;
vector Courses;
vector Faculties;
static bool failure;
static bool success;
public:
University();
~University();
bool CreateNewDepartment(string depName, string depLoc, long depChairId);
bool FacultyExist(long FacId);
bool CreateNewStudent(string sName, string sEmail, string sAddress, string sDateOfBirth,
string sGender, int sYearOfStudy, string sMajor, long sAdvisorId);
bool DepartmentExist(string DepName);
bool CreateNewCourse(string cName, long cDepId, long cTaughtBy, int cMaxSeat);
bool TaughtByExist(long cTaughtBy);
bool DepIdExist(long DepId);
bool CourExist(long courID);
bool CreateNewFaculty(string fName, string fEmail, string fAddress, string fDateOfBirth,
string fGender, float fSalary, int fYearOfExp, long fDepId);
bool ListCoursesTaughtByFaculty(long facultyId);
bool ListCoursesTakenByStudent(long studentId);
bool stuExist(long stuId);
bool ListFacultiesInDepartment(long departId);
bool ListStudentsOfAFaculty(long facultyId);
bool ListCoursesOfADepartment(long departId);
bool AddACourseForAStudent(long courseId, long stId);
bool AssignDepartmentChair(long facultyId, long departId);
bool AssignInstructorToCourse(long facultyId, long courseId);
bool ListDepartments();
bool ListStudents();
bool ListCourses();
bool ListFaculties();
bool ProcessTransactionFile(string fileName);
};
#endif
//======================================
//transactionFile.txt
CreateNewDepartment ComputerScience Science-2 0
CreateNewDepartment Education Science-1 0
CreateNewDepartment Business Craven-Hall 0
CreateNewDepartment Engineering Machray-Hall 0
CreateNewDepartment Biology Science2 110
ListDepartments
CreateNewFaculty John_Smith jsmith@csusm.edu 99_Broadway_Street 10/19/1960
Male 60000 5 100
CreateNewFaculty Bob_Anderson banderson@csusm.edu 130_San_Marcos_Avenue09/21/1958
Male 70000 8 100
CreateNewFaculty Sue_Clark sclark@csusm.edu 113_Santa_Fe_Road 02/05/1970
Female 50000 2 100
CreateNewFaculty Abu_Talib atalib@csusm.edu 311_Twin_Oaks_Road 03/03/1970
Male 55000 5 101
CreateNewFaculty Nancy_Bank nbank@csusm.edu 300_El_Camino_Real 04/07/1975
Female 59000 6 101
CreateNewFaculty Susan_Brown sbrown@csusm.edu 123_Winner_Avenue 07/14/1976
Female 62000 4 101
CreateNewFaculty Ahmad_Saleh asaleh@csusm.edu 211_Mirmar_Ave 12/12/1968
Male 75000 12 102
CreateNewFaculty Beth_Card bcard@csusm.edu 111_Land_Road 11/15/1971
Female 63000 7 102
CreateNewFaculty Joe_Abraham jabraham@csusm.edu 100_Star_Street 02/01/1959
Male 82000 14 102
CreateNewFaculty Andy_Chan achan@csusm.edu 777_Plant_Avenue 12/07/1950
Male 93000 24 130
ListFaculties
ListFacultiesInDepartment 100
ListFacultiesInDepartment 101
ListFacultiesInDepartment 102
ListFacultiesInDepartment 130
CreateNewStudent Kathy_Chen kchen001@csusm.edu 999_Morning_Street 01/02/1982
Female 1 ComputerScience 600
CreateNewStudent Kelly_Wong kwong001@csusm.edu 999_Palace_Avenue 02/12/1980
Male 2 ComputerScience 600
CreateNewStudent Layla_Esmail lesmail001@csusm.edu 999_Perry_Cresesnt 11/12/1980
Female 2 ComputerScience 910
ListStudents
ListStudentsOfAFaculty 600
ListStudentsOfAFaculty 650
CreateNewCourse CS111 100 600 60
CreateNewCourse CS211 100 600 60
CreateNewCourse CS311 100 0 30
CreateNewCourse Ed100 101 603 45
CreateNewCourse Ed200 101 603 45
CreateNewCourse Ed300 101 0 30
CreateNewCourse Bus101 102 606 40
CreateNewCourse Bus102 102 606 40
CreateNewCourse Bus103 102 607 40
CreateNewCourse Bio103 102 706 40
ListCourses
ListCoursesTaughtByFaculty 606
ListCoursesTaughtByFaculty 706
ListCoursesOfADepartment 100
ListCoursesOfADepartment 101
ListCoursesOfADepartment 102
ListCoursesOfADepartment 130
AddACourseForAStudent 200 500
AddACourseForAStudent 201 500
AddACourseForAStudent 202 500
AddACourseForAStudent 230 500
ListCoursesTakenByStudent 500
ListCoursesTakenByStudent 520
ListCoursesTakenByStudent 500
AssignDepartmentChair 600 100
AssignDepartmentChair 610 101
AssignDepartmentChair 601 110
AssignInstructorToCourse 600 202
ListCoursesTaughtByFaculty 600

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!