Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have been tasked to write a program that will calculate students\' grades ba

ID: 3574618 • Letter: Y

Question

You have been tasked to write a program that will calculate students' grades based on the STEM career field. In this problem, you will experience classes, structures, vectors, and file I/O.


NUMBER ONE:
Create a class Course that contains the following elements:

A public string named name

A public character named grade

NUMBER TWO:

The following code has been written for you.

Declare a new variable named mickey of type Student and give the constructor the string Mickey Mouse

Declare an input file stream named courseFile

NUMBER THREE:

InstructionThe following code has been written for you.

InstructionCode Block 3:

Using courseFile, open the file contained in the string variable filename

Do not do any error checking for this block

NUMBER FOUR:

InstructionThe following code has been written for you.

InstructionCode Block 4:

Read from courseFile a name and a grade

Using the Course class, create a new course with the name and grade you got from the file

Using mickey's member function, add the course to mickey (See the prototype to determine which member function to use

Repeat these steps until the file input is exhausted

NUMBER FIVE:

InstructionCode Block 5

Using the mickey instance object, print the major GPA using one of its member functions

Refer to the class prototype to determine which member function to call

NUMBER SIX:

InstructionThe following code has been written for you.

InstructionCode Block 6

Take note that you are below int main()

Write the member function definition for the Student constructor

The constructor simple sets the member variable name to the passed string

NUMBER SEVEN:

InstructionCode Block 7

Write the member function definition for addCourse

This function takes the passed course and pushes it to the back of the coursesTaken vector

NUMBER EIGHT:

InstructionCode Block 8
Write a statement that calls computeMajorGpa and assigns the result to gpa. Note that this statement is part of the printMajorGpa() member function for Student, whose code is both above and below this code block.

NUMBER NINE:

InstructionThe following code has been written for you.

InstructionCode Block 9
Write the computeMajorGpa member function for Student.

Return -1 if the student has not taken any CS or Math courses

Use the following gpa conversions: A = 4.0, B = 3.0, C = 2.0, D = 1.0, F = 0.0.

A switch statement might be useful for making the conversion.

Remember to use floating point arithmetic when computing the gpa.

Explanation / Answer

Here is the update for the first few tasks.

#include <iostream>
#include <vector>
#include <iomanip>
#include <fstream>

using namespace std;   

//NUMBER ONE:
//Create a class Course that contains the following elements:
class Course
{
//A public string named name
public:
string name;
//A public character named grade
char grade;
};
//NUMBER TWO:
//The following code has been written for you.

class Student {
string name;
vector<Course> coursesTaken;
double computeMajorGpa() const;
public:
Student(const string &n); // constructor-assigns n to name
void printMajorGpa() const; // prints student's CS and MATH gpa
void addCourse(const Course &c); // adds a course to coursesTaken

};   

int main() { // beginning of main   


//Declare a new variable named mickey of type Student and give the constructor the string Mickey Mouse
Student mickey ("Mickey Mouse");
//Declare an input file stream named courseFile
ifstream courseFile;

//NUMBER THREE:
//InstructionThe following code has been written for you.

string filename; // holds the file name input by the user

// get the file name from the user
cin >> filename;   


//InstructionCode Block 3:
//Using courseFile, open the file contained in the string variable filename
courseFile.open(filename);
//Do not do any error checking for this block

//NUMBER FOUR:
//InstructionThe following code has been written for you.

if (courseFile.fail()) {
perror(filename.c_str());
return -1;
}   

//InstructionCode Block 4:
//Read from courseFile a name and a grade
while(true)
{
string name;
char grade;
courseFile>>name>>grade;
//Using the Course class, create a new course with the name and grade you got from the file
Course course (name, grade);

//Using mickey's member function, add the course to mickey (See the prototype to determine which member function to use
mickey.addCourse(course);
//Repeat these steps until the file input is exhausted
if(courseFile.eof())
break;
}

//NUMBER FIVE:
//InstructionCode Block 5
//Using the mickey instance object, print the major GPA using one of its member functions
//Refer to the class prototype to determine which member function to call
mickey.printMajorGpa();



//NUMBER SIX:
//InstructionThe following code has been written for you.

return 0;
} // end of main   

InstructionCode Block 6
Take note that you are below int main()
Write the member function definition for the Student constructor
The constructor simple sets the member variable name to the passed string




//NUMBER SEVEN:
//InstructionCode Block 7
//Write the member function definition for addCourse
//This function takes the passed course and pushes it to the back of the coursesTaken vector
void Student::addCourse(const Course &c)
{
coursesTaken.push_back(c);
}


// The code to print a student's gpa in math and
// cs courses. We have provided all the code for
// this function, except for the statement that
// calls computeMajorGpa and assigns the result
// to the gpa variable.
void Student::printMajorGpa() const { // beginning of Student::printMajorGpa()
double gpa;


//NUMBER EIGHT:
//InstructionCode Block 8
//Write a statement that calls computeMajorGpa and assigns the result to gpa.
//Note that this statement is part of the printMajorGpa() member function for Student, whose code is both above and below this code block.

NUMBER NINE:
InstructionThe following code has been written for you.

cout << left << setw(20) << name;
if (gpa >= 0)
cout <<right << setw(5) << fixed << setprecision(1)
<< gpa << endl;
else
cout << "-----" << endl;
} // end of Student::printMajorGpa   

InstructionCode Block 9
Write the computeMajorGpa member function for Student.
Return -1 if the student has not taken any CS or Math courses
Use the following gpa conversions: A = 4.0, B = 3.0, C = 2.0, D = 1.0, F = 0.0.
A switch statement might be useful for making the conversion.
Remember to use floating point arithmetic when computing the gpa.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote