Question
I need help fixing the output of my code, when compiling using putty the ssn is not being read correctly and a fourth student is
I need help fixing the output of my code, when compiling using putty the ssn is not being read correctly and a fourth student is displayed when there shouldnt be. Below are my code, output and instructions needed.
Write a c++ program that makes a collection of students. Your data file contains a set of information about students. Your program should contain four classes: StudentCollection, StudentProfile, Person, Student, and Course. Student Collection is not a class but rather is a vector in this program.
StudentCollection has the following attributes:
vector
StudentProfile class has the following attributes:
Person PersonalInfo Student StdInfo
Person class has the following attributes:
long SSN string Fname string Lname int Age char Gender (M for Male and F for Female)
Student class has the following attributes:
long StNo Course Course1 Course Course2 Course Course3
Course Course4
Course Course5
Course class has the following attributes:
long CourseNum string CourseName
Notes:
Each class should have set and print functions
Note that you are NOT allowed to make the attributes public for this lab. All attributes must be privateand your methods should be public.
You must divide your files into .cpp and .h file.
TRansaction file contains the following information:
123456789
Mary
Anderson
20
F
9800300699
32451
CS211
23145
CS231
87690
Phy301
25677
Chem210
22213
Math210
633322789
Mike
Smith
22
M
9080022299
32251
CS111
11122
Math110
87969
Phy200
25627
Chem110
33313
Bio211
631322111
Michelle
Brown
25
F
611354321
11111
CS911
22222
Math912
33333
Phy913
44444
Chem914
55555
Bio915
// code
// course.h
#ifndef COURSE_H_
#define COURSE_H_
#include
using namespace std;
class Course{
private :
long courseNum;
string courseName;
public:
void setCourseNum(long courseNum);
void setCourseName(string courseName);
long getCourseNum();
string getCourseName();
void printCourse();
};
#endif /* COURSE_H_ */
//end of course.h
// course.cpp
#include "course.h"
void Course::setCourseNum(long courseNum)
{
this->courseNum = courseNum;
}
void Course::setCourseName(string courseName)
{
this->courseName = courseName;
}
long Course::getCourseNum()
{
return courseNum;
}
string Course::getCourseName()
{
return courseName;
}
void Course::printCourse()
{
cout
cout
}
//end of course.cpp
// person.h
#ifndef PERSON_H_
#define PERSON_H_
#include
using namespace std;
class Person
{
private:
long ssn;
string fname;
string lname;
int age;
char gender;
public:
void setSsn(long ssn);
void setFname(string fname);
void setLname(string lname);
void setAge(int age);
void setGender(char gender);
void printPerson();
long getSsn();
string getFname();
string getLname();
int getAge();
char getGender();
};
#endif /* PERSON_H_ */
//end of person.h
// person.cpp
#include "person.h"
void Person::setSsn(long ssn)
{
this->ssn = ssn;
}
void Person::setFname(string fname)
{
this->fname = fname;
}
void Person::setLname(string lname)
{
this->lname = lname;
}
void Person::setAge(int age)
{
this->age = age;
}
void Person::setGender(char gender)
{
this->gender = gender;
}
void Person::printPerson()
{
cout
cout
cout
cout
cout
}
long Person:: getSsn()
{
return ssn;
}
string Person:: getFname()
{
return fname;
}
string Person:: getLname()
{
return lname;
}
int Person:: getAge()
{
return age;
}
char Person:: getGender()
{
return gender;
}
//end of person.cpp
// student.h
#ifndef STUDENT_H_
#define STUDENT_H_
# include "course.h"
class Student{
private:
long stno;
Course course1;
Course course2;
Course course3;
Course course4;
Course course5;
public:
void setStNo(long stno);
void setCourse1(Course course1);
void setCourse2(Course course2);
void setCourse3(Course course3);
void setCourse4(Course course4);
void setCourse5(Course course5);
void printStudent();
long getStNo();
Course getCourse1();
Course getCourse2();
Course getCourse3();
Course getCourse4();
Course getCourse5();
};
#endif /* STUDENT_H_ */
//end of student.h
// student.cpp
#include "student.h"
void Student ::setStNo(long stno)
{
this->stno = stno;
}
void Student::setCourse1(Course course1)
{
this->course1.setCourseNum(course1.getCourseNum());
this->course1.setCourseName(course1.getCourseName());
}
void Student::setCourse2(Course course2)
{
this->course2.setCourseNum(course2.getCourseNum());
this->course2.setCourseName(course2.getCourseName());
}
void Student::setCourse3(Course course3)
{
this->course3.setCourseNum(course3.getCourseNum());
this->course3.setCourseName(course3.getCourseName());
}
void Student::setCourse4(Course course4)
{
this->course4.setCourseNum(course4.getCourseNum());
this->course4.setCourseName(course4.getCourseName());
}
void Student::setCourse5(Course course5)
{
this->course5.setCourseNum(course5.getCourseNum());
this->course5.setCourseName(course5.getCourseName());
}
void Student::printStudent()
{
cout
cout
course1.printCourse();
cout
course2.printCourse();
cout
course3.printCourse();
cout
course4.printCourse();
cout
course5.printCourse();
}
long Student:: getStNo()
{
return stno;
}
Course Student::getCourse1()
{
return course1;
}
Course Student::getCourse2()
{
return course2;
}
Course Student::getCourse3()
{
return course3;
}
Course Student::getCourse4()
{
return course4;
}
Course Student::getCourse5()
{
return course5;
}
//end of student.cpp
// studentProfile.h
#ifndef STUDENTPROFILE_H_
#define STUDENTPROFILE_H_
#include "student.h"
#include "person.h"
class StudentProfile
{
private:
Person PersonalInfo;
Student StdInfo;
public:
void setPerson(Person personalInfo);
void setStdInfo(Student stdInfo);
void printStudentProfile();
};
#endif /* STUDENTPROFILE_H_ */
//end of studentProfile.h
//studentProfile.cpp
# include "studentProfile.h"
void StudentProfile::setPerson(Person personalInfo)
{
PersonalInfo.setAge(personalInfo.getAge());
PersonalInfo.setFname(personalInfo.getFname());
PersonalInfo.setLname(personalInfo.getLname());
PersonalInfo.setAge(personalInfo.getAge());
PersonalInfo.setGender(personalInfo.getGender());
}
void StudentProfile::setStdInfo(Student stdInfo)
{
StdInfo.setStNo(stdInfo.getStNo());
StdInfo.setCourse1(stdInfo.getCourse1());
StdInfo.setCourse2(stdInfo.getCourse2());
StdInfo.setCourse3(stdInfo.getCourse3());
StdInfo.setCourse4(stdInfo.getCourse4());
StdInfo.setCourse5(stdInfo.getCourse5());
}
void StudentProfile::printStudentProfile()
{
cout
PersonalInfo.printPerson();
cout
StdInfo.printStudent();
}
//end of studentProfile.cpp
// main.cpp
# include
#include
#include
#include "studentProfile.h"
using namespace std;
int main()
{
vector
ifstream inFile("transaction.txt");//read contents from the file
if(!inFile)
{
cout
return 0;
}
StudentProfile temp_record;//creating a temporary object that stores student details
Person person;
Course course;
Student student;
long ssn,stno,courseNum;
string courseName,fname,lname;
int age;
char gender;
// loop to read till the end of file
while(!inFile.eof())
{
// read personal details
inFile>>ssn>>fname>>lname>>age>>gender;
// set attributes of person
person.setSsn(ssn);
person.setFname(fname);
person.setLname(lname);
person.setAge(age);
person.setGender(gender);
// set personal details of student profile
temp_record.setPerson(person);
// read student details
inFile>>stno;
student.setStNo(stno);
inFile>>courseNum>>courseName;
course.setCourseNum(courseNum);
course.setCourseName(courseName);
// set course1 details
student.setCourse1(course);
inFile>>courseNum>>courseName;
course.setCourseNum(courseNum);
course.setCourseName(courseName);
// set course2 details
student.setCourse2(course);
inFile>>courseNum>>courseName;
course.setCourseNum(courseNum);
course.setCourseName(courseName);
// set course3 details
student.setCourse3(course);
inFile>>courseNum>>courseName;
course.setCourseNum(courseNum);
course.setCourseName(courseName);
// set course4 details
student.setCourse4(course);
inFile>>courseNum>>courseName;
course.setCourseNum(courseNum);
course.setCourseName(courseName);
// set course5 details
student.setCourse5(course);
temp_record.setStdInfo(student);
StCollection.push_back(temp_record);//going to store the temporay object into the vector
}
for(int i = 0; i
{
StCollection[i].printStudentProfile();
cout
}
}
//end of main.cpp
SSN: 6315448 First Name: Mary Last Name:Anderson Age: 20 Gender: F Student info: Student Number: 9800300699 Course1: Course Number : 32451 Course Name: CS211 Course2: Course Number: 23145 CourseName:CS231 Course3: Course Number: 87690 Course Name Phy301 Course4: Course Number: 25677 Course Name: Chem210 Course5: Course Number: 22213 Course NameMath210 SSN: 6315448 First Name: Mike Last Name: Smith Age: 22 Gender: M Student infoStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started