Question

In: Computer Science

in c++ you need to write a program that maintains the gradebook for a specific course....

in c++ you need to write a program that maintains the gradebook for a specific course. For each student registered in this course, the program keeps track of the student’s name, identification number (id), four exam grades, and final grade. The program performs several functionalities such as: enrolling a student in the course, dropping a student from the course, uploading student’s exam grades, displaying the grades of a specific student, displaying the grades of all students in the course, and printing grades summary information.
To do that, you need to create a structure, Student, that holds individual student’s details. The Student struct contains the following fields:
struct Student { string name; // student first and last name long id; // student identification number double grades[4]; // array holding four exam grades double finalGrade; // student final grade }
Then, in your main program, you need to:
- declare a vector of Student structs, named students, to hold the data for all the students enrolled in this course. - process a transaction file, “StudentsTrans.txt”. Each line in the file contains a specific command such as “enroll”, “display”, “drop”, “uploadGrades”, “searchByName”, and “printClassSummary”. The line also contains all necessary data to process the command. Each command must be implemented in a separate function. The commands are:

▪ Enroll StudentFirstName StudentLastName StudentID   

This command adds a new Student record (object) to the students’ vector. You should read the student details from the transaction file (StudentFirstName, StudentLastName, StudentID). Before creating a new object, you need to check for duplicate student entries (if an existing student has the same StudentID). If this student was not previously added to the students vector, you should add an entry for that student and its details at the end of the students’ vector. Make sure to concatenate StudentFirstName and StudentLastName into one student name and set all grades initially to zeros. You can simply use the push_back function to add a Student object to the end of the vector. You should also display a message that the student was successfully added to the vector. For example:

enroll Joe Garcia 432345673 Joe Garcia successfully added to students vector…

If this student already exists in the vector, you should not add the student again to the vector. You should also display an error message. For example:
enroll Amelia Perez 876007654 Student already enrolled in this class, can not enroll again

▪ Display

This command displays the details of all students registered in the course in a neat table format. Details include a student’s name, id, four individual exam grades, and the final grade. The final
grade is the average of the four exam scores. You should print decimal numbers with 2 digits of precision. A sample display is shown below:

Student    ID    Exam1 Exam2 Exam3 Exam4 Final Grade

-------------------------------------------------------------------------

Suzy Walter 876523067 87.50    85.00    88.00    81.00 85.38

Amelia Perez 876007654 62.00 70.00    71.50    80.00    70.88 …   
▪ SearchByName Keyword

This command searches and prints the records of all students whose first names, last names, or full names include or match Keyword. For example, if Keyword is “James”, you should display the following students:

searchByName James Student ID Exam1 Exam2 Exam3 Exam4 FinalGrade ------------------------------------------------------------------------ James Ducrest 123282345 62.00 67.00 63.00 70.00 66.25 James Didier 123456789 79.00 85.00 80.00 88.00 83.00

If no matching entry is found, you should display a message that this student is not enrolled in this course. For example:
searchByName Michel No such student exists

▪ Drop StudentID

This command drops a specific student (whose id is StudentID) from the course by removing its entry from the students’ vector. You should check if that student is enrolled in this class before trying to delete its entry. If so, pay attention that deleting could be from any entry in the vector and not necessarily the last record. You should also display a message that the student was successfully deleted from the vector. For example:

drop 982323146… Andrea Meyer successfully dropped from course
If no matching entry is found, you should display a message that this student does not exist. For example:
drop 012345634… No such student exists
▪ UploadGrades StudentID Grade1 Grade2 Grade3 Grade4

This command uploads the grades of a specific student to the corresponding entry in the students vector. The command specifies StudentID, which corresponds to the id of the student whose grades should be uploaded. The command also specifies the 4 individual exam grades for that student (Grade1 Grade2 Grade3 Grade4). You should search for the student whose id matches StudentID. If a match is found, you should update its grades array and display a message that the student’s grades were successfully uploaded. For example:   

uploadGrades 876523067 87.5 85 88 81 Suzy walter grades successfully uploaded

Otherwise, you should display a message that this student was not found. For example:

uploadGrades 999999999 60 90 70 80 no such student exists, grades can not be uploaded


▪ PrintClassSummary

This command prints summary information. This includes: the name of the student who took the highest final grade in this course, the name of the student who took the lowest final grade in this course, and the overall class average.
To test your code, you may create and process the following transaction file:
“StudentsTrans.txt”

enroll Joe Garcia 432345673

enroll Suzy Walter 876523067

enroll Amelia Perez 876007654

enroll James Ducrest 123282345

enroll Amelia Perez 876007654

enroll Suzy Walter 987667654

enroll James Didier 123456789

enroll Carolyn Johnson 456283409

enroll Andrea Meyer 982323146

enroll Edward Weber 787878123

display

drop 012345634

drop 982323146

drop 432345673

uploadGrades 432345673 98 98 99 93

uploadGrades 999999999 60 90 70 80

uploadGrades 876523067 87.5 85 88 81

uploadGrades 876007654 62 70 71.5 80

uploadGrades 123282345 62 70 63 70

uploadGrades 987667654 81 83 75 90

uploadGrades 123456789 79 85 80 88

uploadGrades 456283409 95 91 92 94

uploadGrades 787878123 99 98.5 95 94

searchByName James

searchByName John

searchByName Edward

searchByName Michel

searchByName Amelia Perez

display printClassSummary

Solutions

Expert Solution

Screenshot

------------------------------------------------------------------------------------

Program

//Header files
#include <iostream>
#include<string>
#include<vector>
#include<fstream>
#include<iomanip>
using namespace std;
//Create a student struct
struct Student {
   string name;
   long id;
   double grades[4];
   double finalGrade;
};
//function prototypes
void enroll(vector<Student>& course,string line);
void display(vector<Student> course);
void drop(vector<Student>& course, string line);
void upload(vector<Student>& course,string line);
void search(vector<Student>& course,string line);
void summary(vector<Student> course);
int main()
{
    //Vector for student's of a course
   vector<Student> course;
   //file open
   ifstream in("StudentsTrans.txt");
   //Error check
   if (!in) {
       cout << "File not found!!!" << endl;
       exit(0);
   }
   string line;
   while (getline(in,line)) {
       string cmd= line.substr(0,line.find(' '));
       if (cmd == "enroll") {
           enroll(course, line);
       }
       else if (cmd == "display" && cmd.length()==line.length()) {
           display(course);
       }
       else if (cmd == "drop") {
           drop(course,line);
       }
       else if (cmd == "uploadGrades") {
           upload(course, line);
       }
       else if (cmd == "searchByName") {
           search(course, line);
       }
       else if (cmd == "display") {
           summary(course);
       }
       cout << endl;
   }
}
//Function to read a student details and enrol him in the course
//Before enrolling check if already that student present or not
void enroll(vector<Student>& course,string line) {
   string delimiter = " ";
   string cmd = line.substr(0, line.find(delimiter));
   line.erase(0, line.find(delimiter) + delimiter.length());
   string fName= line.substr(0, line.find(delimiter));
   line.erase(0, line.find(delimiter) + delimiter.length());
   string lName = line.substr(0, line.find(delimiter));
   line.erase(0, line.find(delimiter) + delimiter.length());
   long id =stol(line);
   for (int i = 0; i < course.size(); i++) {
       if (course[i].id == id) {
           cout << cmd<<" " << fName << " " << lName << " " << id << " Student already enrolled in this class, can not enroll again" << endl;
           return;
       }
   }
   Student s;
   s.name = fName + " " + lName;
   s.id = id;
   s.grades[0] = 0;
   s.grades[1] = 0;
   s.grades[2] = 0;
   s.grades[3] = 0;
   s.finalGrade = (s.grades[0]+ s.grades[1]+ s.grades[2]+ s.grades[3])/4;
   course.push_back(s);
   cout <<cmd<< " " << fName << " " << lName << " " << id <<" "<<s.name<<" successfully added to students vector …"<< endl;
}
//Function to display students details
void display(vector<Student> course) {
   cout << fixed<<setprecision(2);
   cout << "      Student             ID                  Exam1            Exam2           Exam3           Exam4        Final Grade\n";
   cout << "------------------------------------------------------------------------------------------------------------------------\n";
   for (int i = 0; i < course.size(); i++) {
       cout << setw(17) << course[i].name << setw(15) << course[i].id <<"\t\t" << course[i].grades[0]
           << "\t\t" << course[i].grades[1] << "\t\t" << course[i].grades[2] << "\t\t"
           << course[i].grades[3] << "\t\t" << course[i].finalGrade << endl;
   }
}
//Function to drop a student from the course if matches the id
void drop(vector<Student>& course,string line) {
   string delimiter = " ";
   string cmd = line.substr(0, line.find(delimiter));
   line.erase(0, line.find(delimiter) + delimiter.length());
   long id = stol(line);
   for (int i = 0; i < course.size(); i++) {
       if (course[i].id == id) {
           cout <<cmd<<" " << id << "... " << course[i].name << " successfully dropped from course" << endl;
           course.erase((course.begin() + i));
           return;
       }
   }
   cout << cmd << " " << id << "… No such student exists" << endl;
}
//Functio read data from file and match with id to updates grade details of a student
void upload(vector<Student>& course,string line) {
   string delimiter = " ";
   string cmd = line.substr(0, line.find(delimiter));
   line.erase(0, line.find(delimiter) + delimiter.length());
   long id = stol(line.substr(0, line.find(delimiter)));
   line.erase(0, line.find(delimiter) + delimiter.length());
   double m1 =stod( line.substr(0, line.find(delimiter)));
   line.erase(0, line.find(delimiter) + delimiter.length());
   double m2 = stod(line.substr(0, line.find(delimiter)));
   line.erase(0, line.find(delimiter) + delimiter.length());
   double m3 = stod(line.substr(0, line.find(delimiter)));
   line.erase(0, line.find(delimiter) + delimiter.length());
   double m4 = stod(line);
   cout << fixed << setprecision(2);
   for (int i = 0; i < course.size(); i++) {
       if (course[i].id == id) {
           course[i].grades[0] = m1;
           course[i].grades[1] = m2;
           course[i].grades[2] = m3;
           course[i].grades[3] = m4;
           course[i].finalGrade= (m1+m2+m3+m4)/4;
           cout << "uploadGrades " << id << " " << m1 << " " << m2 << " " << m3 << " " << m4 << " "
               << course[i].name << " grades successfully uploaded" << endl;
           return;
       }
   }
   cout << "uploadGrades " << id << " " << m1 << " " << m2 << " " << m3 << " " << m4 << " "
       <<"no such student exists, grades can not be uploaded"<< endl;
}
//Function to search a student by his name
void search(vector<Student>& course,string line) {
   string delimiter = " ";
   string cmd = line.substr(0, line.find(delimiter));
   line.erase(0, line.find(delimiter) + delimiter.length());
   string name = line;
   int j = 0;
   bool check = false;
   cout << "searchByName " << name << endl;
   for (int i = 0; i < course.size(); i++) {
       if (course[i].name.find(name) != std::string::npos) {
           check = true;
           if (j == 0) {
               cout << "      Student             ID                  Exam1            Exam2           Exam3           Exam4        Final Grade\n";
               cout << "------------------------------------------------------------------------------------------------------------------------\n";
               cout << setw(17) << course[i].name << setw(15) << course[i].id << "\t\t" << course[i].grades[0]
                   << "\t\t" << course[i].grades[1] << "\t\t" << course[i].grades[2] << "\t\t"
                   << course[i].grades[3] << "\t\t" << course[i].finalGrade << endl;
               j++;
           }
           else {
               cout << setw(17) << course[i].name << setw(15) << course[i].id << "\t\t" << course[i].grades[0]
                   << "\t\t" << course[i].grades[1] << "\t\t" << course[i].grades[2] << "\t\t"
                   << course[i].grades[3] << "\t\t" << course[i].finalGrade << endl;
           }
       }
   }
   if (!check) {
       cout << "No such student exists" << endl;
   }
}
//Function to generate summary
void summary(vector<Student> course) {
   cout << fixed << setprecision(2);
   cout << "Summary of the class:-" << endl;
   Student highest = course[0], lowest = course[0];
   double avg = 0;
   for (int i = 0; i < course.size(); i++) {
       avg += course[i].finalGrade;
       if (highest.finalGrade < course[i].finalGrade) {
           highest = course[i];
       }
       if (lowest.finalGrade > course[i].finalGrade) {
           lowest = course[i];
       }
   }
   cout << "Highest scored student in the course:-" << endl;
   cout << "      Student             ID                  Exam1            Exam2           Exam3           Exam4        Final Grade\n";
   cout << "------------------------------------------------------------------------------------------------------------------------\n";
   cout << setw(17) << highest.name << setw(15) << highest.id << "\t\t" << highest.grades[0]
       << "\t\t" << highest.grades[1] << "\t\t" << highest.grades[2] << "\t\t"
       << highest.grades[3] << "\t\t" << highest.finalGrade << endl;
   cout << "\nLowest scored student in the course:-" << endl;
   cout << "      Student             ID                  Exam1            Exam2           Exam3           Exam4        Final Grade\n";
   cout << "------------------------------------------------------------------------------------------------------------------------\n";
   cout << setw(17) << lowest.name << setw(15) << lowest.id << "\t\t" << lowest.grades[0]
       << "\t\t" << lowest.grades[1] << "\t\t" << lowest.grades[2] << "\t\t"
       << lowest.grades[3] << "\t\t" << lowest.finalGrade << endl;
   cout << "\nAverage of the class = " << (avg / course.size()) << endl;
}

--------------------------------------------------------------------------------

output

enroll Joe Garcia 432345673 Joe Garcia successfully added to students vector à

enroll Suzy Walter 876523067 Suzy Walter successfully added to students vector à

enroll Amelia Perez 876007654 Amelia Perez successfully added to students vector à

enroll James Ducrest 123282345 James Ducrest successfully added to students vector à

enroll Amelia Perez 876007654 Student already enrolled in this class, can not enroll again

enroll Suzy Walter 987667654 Suzy Walter successfully added to students vector à

enroll James Didier 123456789 James Didier successfully added to students vector à

enroll Carolyn Johnson 456283409 Carolyn Johnson successfully added to students vector à

enroll Andrea Meyer 982323146 Andrea Meyer successfully added to students vector à

enroll Edward Weber 787878123 Edward Weber successfully added to students vector à

      Student             ID                  Exam1            Exam2           Exam3           Exam4        Final Grade
------------------------------------------------------------------------------------------------------------------------
       Joe Garcia      432345673                0.00            0.00            0.00            0.00            0.00
      Suzy Walter      876523067                0.00            0.00            0.00            0.00            0.00
     Amelia Perez      876007654                0.00            0.00            0.00            0.00            0.00
    James Ducrest      123282345                0.00            0.00            0.00            0.00            0.00
      Suzy Walter      987667654                0.00            0.00            0.00            0.00            0.00
     James Didier      123456789                0.00            0.00            0.00            0.00            0.00
Carolyn Johnson      456283409                0.00            0.00            0.00            0.00            0.00
     Andrea Meyer      982323146                0.00            0.00            0.00            0.00            0.00
     Edward Weber      787878123                0.00            0.00            0.00            0.00            0.00

drop 12345634à No such student exists

drop 982323146... Andrea Meyer successfully dropped from course

drop 432345673... Joe Garcia successfully dropped from course

uploadGrades 432345673 98.00 98.00 99.00 93.00 no such student exists, grades can not be uploaded

uploadGrades 999999999 60.00 90.00 70.00 80.00 no such student exists, grades can not be uploaded

uploadGrades 876523067 87.50 85.00 88.00 81.00 Suzy Walter grades successfully uploaded

uploadGrades 876007654 62.00 70.00 71.50 80.00 Amelia Perez grades successfully uploaded

uploadGrades 123282345 62.00 70.00 63.00 70.00 James Ducrest grades successfully uploaded

uploadGrades 987667654 81.00 83.00 75.00 90.00 Suzy Walter grades successfully uploaded

uploadGrades 123456789 79.00 85.00 80.00 88.00 James Didier grades successfully uploaded

uploadGrades 456283409 95.00 91.00 92.00 94.00 Carolyn Johnson grades successfully uploaded

uploadGrades 787878123 99.00 98.50 95.00 94.00 Edward Weber grades successfully uploaded

searchByName James
      Student             ID                  Exam1            Exam2           Exam3           Exam4        Final Grade
------------------------------------------------------------------------------------------------------------------------
    James Ducrest      123282345                62.00           70.00           63.00           70.00           66.25
     James Didier      123456789                79.00           85.00           80.00           88.00           83.00

searchByName John
      Student             ID                  Exam1            Exam2           Exam3           Exam4        Final Grade
------------------------------------------------------------------------------------------------------------------------
Carolyn Johnson      456283409                95.00           91.00           92.00           94.00           93.00

searchByName Edward
      Student             ID                  Exam1            Exam2           Exam3           Exam4        Final Grade
------------------------------------------------------------------------------------------------------------------------
     Edward Weber      787878123                99.00           98.50           95.00           94.00           96.63

searchByName Michel
No such student exists

searchByName Amelia Perez
      Student             ID                  Exam1            Exam2           Exam3           Exam4        Final Grade
------------------------------------------------------------------------------------------------------------------------
     Amelia Perez      876007654                62.00           70.00           71.50           80.00           70.88

Summary of the class:-
Highest scored student in the course:-
      Student             ID                  Exam1            Exam2           Exam3           Exam4        Final Grade
------------------------------------------------------------------------------------------------------------------------
     Edward Weber      787878123                99.00           98.50           95.00           94.00           96.63

Lowest scored student in the course:-
      Student             ID                  Exam1            Exam2           Exam3           Exam4        Final Grade
------------------------------------------------------------------------------------------------------------------------
    James Ducrest      123282345                62.00           70.00           63.00           70.00           66.25

Average of the class = 82.48


Related Solutions

I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
Write a C++ die roller program. We need you to write a program that will roll...
Write a C++ die roller program. We need you to write a program that will roll dice for them, but not just six-sided dice. Your program needs to be able to take an input in for form nDx or ndx where the d is the letter d or D. n may or not be present. If it is, it represents the number of dice. If not, assume it is a 1. x may or may not be present. If it...
Coding in C++: For this verse, you need to write a program that asks the user...
Coding in C++: For this verse, you need to write a program that asks the user to input the inventory id number (integer) and the price (float) for 5 inventory items. Once the 5 inventory items are input from the user, output the results to the screen. Please ensure you use meaningful names for your variables. If your variables are not named meaningfully, points will be deducted.
Write a C or C++ program using the fork() system call function. You will need to...
Write a C or C++ program using the fork() system call function. You will need to create 3 processes – each process will perform a simple task. Firstly, create an integer "counter" initialized to a random value between 1 and 100. Print this number to the console. This can be done by: Including the stdio.h and stdlib.h libraries Using the rand() function to generate your randomly generated number The main thread consists of the parent process. Your job is to...
C++ exercise ! Change the WEEK‐4 program to work through the GradeBook class. This program has...
C++ exercise ! Change the WEEK‐4 program to work through the GradeBook class. This program has some functionality that you can use with the Gradebook class. So, please revise Gradebook class so that the class can use sort() and display() functions of WEEK4 program . week-4 program : #include #include using namespace std; void sort(char nm[][10]); void display(char name[][10]); int main() { char names[10][10]; int i; for (i=0; i<10; i++) { cout << "Enter name of the student : ";...
Write a program in c++ that maintains a telephone directory. The Telephone directory keeps records of...
Write a program in c++ that maintains a telephone directory. The Telephone directory keeps records of people’s names and the corresponding phone numbers. The program should read a transaction file and report the result into an output file. The transaction file can include commands such as “Add”, “Delete”, “Display”, and “Update”, and “Search”. Each command is written in one line with a few other information. The “Display” Command should simply display everyone in the directory on the screen The “Add”...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute an approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is:...
C# language Question: You need to write a program for students who receive bursaries in the...
C# language Question: You need to write a program for students who receive bursaries in the department, managing the free hours they have to do. For each recipient you store the recipient’s name and the number of hours outstanding. All recipients start with 90 hours. Implement class Recipients which has the private attributes Name and Hours. In addition to the constructor, the class has the following methods: public String getName() // Returns the name of the recipient public int getHours()...
*Need in C language also need full documentation/explanation of each line* Thank you! Write a program...
*Need in C language also need full documentation/explanation of each line* Thank you! Write a program that records high-score data from a simulated FIFA soccer game available online. The program will ask the user to enter the number of scores, create two dynamic arrays sized accordingly, ask the user to enter the indicated number of names and scores, and then print the names and scores sorted by score in descending order. The output from your program should look exactly like...
Assignment Description: Write a C++ program for keeping a course list for each student in a...
Assignment Description: Write a C++ program for keeping a course list for each student in a college. Information about each student should be kept in an object that contains the student id (four digit integer), name (string), and a list of courses completed by the student. The course taken by a student are stored as a linked list in which each node contain course name (string such as CS41, MATH10), course unit (1 to 4) and the course grade (A,B,C,D,F)....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT