This homework is intended to test your understanding on classes and file I-O, pl
ID: 3850947 • Letter: T
Question
This homework is intended to test your understanding on classes and file I-O, plus an overall software design ability for storing students’ information.
Create a class named Student that has several private member variables as below:
• (string) name - A string that stores the name of the student
• (int) numCourses - An integer that tracks how many courses the student is currently enrolled in
• (string*) courseList - A dynamic array of strings used to store the names of the courses that the student is enrolled in
• (double*) gradeList - A dynamic array of double used to store the grade for each courses that the students is enrolled in
• (int) numStudents - A static member variable that counts the number of students created
For member functions, you should have
• Default constructor and argument constructor - public constructors to initialize and create an object from class -Student( ) (5 points)
-Student(string name, int numCourses) (5 points)
-Student(const Student& others) (10 points)
• Appropriate and necessary mutators and accessors for private members (what to be defined would depend on specific purpose in your task )(20 points)
• A public function that prints the student’s name, all courses in courseList and all grades in gradeList (10 points)
• A public function that calculates and print this student’s GPA (4.0-based) (10 points)
. • A function that resets the numCourses to 0 and the courseList and gradeList to an empty list (10 points)
• A destructor that releases all memory that has been allocated (5 points)
Read file name from command line, e.g., ./solution input1.txt, to get Student object information.
The input1.txt format is (contents are just for example) /*********************************/
5 //student number
Brandon Routh //student name
4 //course numbers
Visualization, Computer Architecture, Operating System, Artificial Intelligence //course list
A, B, F, C //grade list
Miles Teller
5
NLP, Operating System, Software Design, Computer Graphics, Machine Learning
A, A-, D+, C-, B
Lebron James
5
2007 Final, 2011 Final, 2014 Final, 2015 Final, 2017 Final
F, C+, C-, D, B+
Anonymous Student
3
C++ Programming, Java Programming, Python Programming C,
D+, F
New Graduate
10
A, B, C, D, E, F, G, H, I, J A, A-, B+, B, B-, C+, C, C-, D+, D
/********************************/
General operations should be
• Read file name from command line. Should judge argument number is 2 or not
• Define a dynamic array of Student objects to store all information from the file operation (15 points)
• Print courses, grades and averaged GPA for each student by calling member functions (10 points)
• Necessary memory release for dynamic array
• Total score is 110 with 10 bonus on your overall structure designed in your program
• Must be compiled and tested on server
• Any program that has segmentation fault or compilation failure would result in grade not more than 40
• Would test on various files with the same format
• Suggestion for file operation: use getline to read whole line from file, and use C++ stringstream to split string by comma
Explanation / Answer
class Student{
public:
Student();
Student(String sname,int SnumCOurses);
Student(String* SCourseList,Double* SgradeList,int snumStudents);
~Student();
//Accessors and mutators for all the member variables
String getName();
int getnumCorses();
int getsnumStudents();
String* getSCourseList();
Double* getSgradeList();
void setName(String);
void setNumCourses(int);
void setNumStudents(int);
void setScourseList(String*);
void setgradeList(Double*);
void printNameAndCourseAndGrade(Student array*);
void calculateAndPrintStudentGPA(Student array*);
void resetnumcoursesgradelist();
private:
String name;
int numCourses;
String* CourseList;
Double* gradeList;
int num Students;
Student:: Student()
{
}
Student:: Student(String sname,int snumCourses){
name=sname;
numCourses=snumCourses;
}
Student::Student(String * sCourseList,Double * sgradeList,int snumStudents)
{
courselist=new String[];
gradeList=new Double[];
numStudents=snumStudents;
void printNameAndCourseAndGrade(Student array*){
cout<<"the student name is"<<array.name<<endl;
cout<<"the student courseis"<<array.courseList<<endl;
cout<<"the student grade is"<<array.gradeList<<endl;
}
};
int main(int argc,char*argv[])
{
Student student=new Student();
Student *array=new Student[2];
delete[] array;
String name;
int numCourses;
String* CourseList;
Double* gradeList;
int num Students;
int snumber=array.number;
String sname=array.name;
int snumberCourses=array.numCourses;
Double[] gradeList=array.gradeList;
String[] CourseList=array.CourseList;
if(argc>=2)
{
Cout<<"argument count is greater than 2"<<endl;
}
ifstream ifile;
ifile.open(input1.txt);
while(getLine(ifile,lineName){
if(lineName=="Student Number")
array.number=getLine(ifile);
if(lineName=="Student Name")
array.name=getLine(iflile);
if(lineName=="gradeList")
array.gradeList=getLine(ifile);
student.printNameAndCourseAndGrade(array);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.