Question

Using the following parallel array and array of vectors: // may be declared outside the main...

Using the following parallel array and array of vectors:

// may be declared outside the main function
const int NUM_STUDENTS =3; 
// may only be declared within the main function

string Students[NUM_STUDENTS] = {"Tom","Jane","Jo"};
vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}};

Write a C++ program to run a menu-driven program with the following choices:

1) Display the grades
2) Add grade
3) Remove grade for all students for a selected assignment
4) Display Average for each student
5) Display the name of the student with the lowest grade for each assignment
6) Display a sorted list of the average scores of students
7) Quit

Make sure your program conforms to the following requirements:

1. Write a function called getValidGrade that allows a user to enter in an integer and loops until a valid number that is>= 0 and <= 100 is entered. It returns the valid value.

2. Write a function called getValidAssignmentNumber that takes in as a parameter the max number of assignments and allows a user to enter in an integer and loops until a valid number that is>= 1 and <= the max number of assignments. It returns the valid value.

3. Write a function called displayGrades that takes the student array and grade vector as parameters and displays the grades in the format in the sample run below.

4. Write a function called AddGrades that takes the student array and grade vector as parameters, it loops through each student, allows the user to enter in a valid grade for that student and stores the grade under the appropriate student in the grades vector.

5. Write a function called RemoveGrades that takes the student array and grade vector as parameters, it asks the user for a valid assignment number, loops through each student, and removes the selected assignment from each student's grades vector.

6. Write a function called displayAverageForEachStudent that takes the student array and grades vector as parameters, computes the average grade for each student, and displays the grades in the format in the sample run below.

7. Write a function called displayStudentNameLowestScoreEachAssign that takes the student array and grades vector as parameters, loops through each assignment and displays the name of the student with the lowest grade on that assignment in the format in the sample run below.

8. Write a function called displaySortedAverageForEachStudent the student array and grades vector as parameters, it creates a local copy of the student array and a new array of float values that stores the average for each student, it then sorts these two parallel arrays by the average and displays a list containing the names of the students and their averages in ascending order

9. Add comments wherever necessary.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

OUTPUT FORMAT IS NOT MENTIONED

C++ Code:

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
//Number of Students
const int NUM_STUDENTS=3;
//Number of Assignments
const int max_number=2;
//this function will return a valid grade
int getValidGrade(){
   int n;
   do{
       cout<<"Enter Valid Grade\n";
       cin>>n;
   }while(n>100 || n<0);
   return n;
}
//this function will return a valid assignemnt number
int getValidAssignmenNumber(int max_n){
   int n;
   do{
       cout<<"Enter Valid Assignment Number\n";
       cin>>n;
   }while(n>max_n||n<0);
   return n;
}
//This will display all grades of students
void displayGrades(vector<int> grade[],string student[]){
   cout<<"Student"<<"\t"<<"Grade"<<endl;
   for(int i=0;i<NUM_STUDENTS;i++){
       cout<<student[i]<<"\t"<<"Grades : ";
       for(int j=0;j<grade[i].size();j++){
           cout<<" "<<grade[i].at(j);
       }
       cout<<endl;
   }
}
//this will add grades to grade vector
void addGrades(vector<int> grade[],string student[]){
   for(int i=0;i<NUM_STUDENTS;i++){
       cout<<"Enter grade for "<<i+1<<" students:"<<endl;
       for(int j=0;j<max_number;j++){
           grade[i].push_back(getValidGrade());
       }
   }
  
}
//This will remove grades of specific assignment
void removeGrades(vector<int> grade[],string student[]){
   int r=getValidAssignmenNumber(max_number)-1;
   vector<int>::iterator it1;
   for(int i=0;i<NUM_STUDENTS;i++){
       int t=r;
       it1=grade[i].begin();
       while(t--){
           it1++;
       }
       grade[i].erase(it1);
   }
}
//this will display average of all grades of each students
void displayAverageForEachStudent(vector<int> grade[],string student[]){
   float sum=0.0;
   for(int i=0;i<NUM_STUDENTS;i++){
       for(int j=0;j<grade[i].size();j++){
           sum+=grade[i].at(j);
       }
       cout<<"Student Name :"<<student[i]<<" Average="<<(sum/grade[i].size())<<endl;
       sum=0.0;
   }
}
//This will show least scorer of each assignment
void displayStudentNameLowestScoreEachAssign(vector<int> grade[],string student[]){
   int low[max_number]={0};
   for(int i=1;i<NUM_STUDENTS;i++){
       for(int j=0;j<grade[i].size();j++){
           if(grade[i].at(j)<grade[low[j]].at(j))
               low[j]=i;
       }
   }
   for(int i=0;i<grade[i].size();i++){
       cout<<"Assignment number:"<<i+1<<"\t Student Name:"<<student[low[i]]<<endl;
   }
}
//This will show average marks of students in sorted manner
void displaySortedAverageForEachStudent(vector<int> grade[],string student[]){
   cout<<"Students"<<"\t"<<"Average Grades"<<endl;
   float sum=0.0;
   float averageSum[NUM_STUDENTS];
   for(int i=0;i<NUM_STUDENTS;i++){
       for(int j=0;j<grade[i].size();j++){
           sum+=grade[i].at(j);
       }
       averageSum[i]=(float)(sum/grade[i].size());//Average storing
       sum=0.0;
   }
   float min=0;
   int n=NUM_STUDENTS;
   //Sort logic
   for(int i=0;i<n-1;i++){
       for(int j=0;j<n-i-1;j++){
           if(averageSum[j]>averageSum[j+1]){
               float t=averageSum[j];
               averageSum[j]=averageSum[j+1];
               averageSum[j+1]=t;
               //also sort student array
               string temp=student[j];
               student[j]=student[j+1];
               student[j+1]=temp;
           }
       }
   }
   for(int i=0;i<n;i++){
       cout<<"Students: "<<student[i]<<"\t Avg Grades: "<<averageSum[i]<<endl;
   }
  
}
int main(){
   string Students[NUM_STUDENTS]={"Tom","Jane","Joe"};//Students array
   vector<int> grade[NUM_STUDENTS];//array of vectors
   int choice;
   cout<<"Enter Choice"<<endl;
   cout<<"1 for Display the grades\n2 for Add grade\n3 for Remove grade for all students for a selected assignment\n4 for Display Average for each student\n5 for Display the name of the student with the lowest grade for each assignment\n6 for Display a sorted list of the average scores of students\n7 for Quit\n";
   cin>>choice;
   //Menu driven Programme
   while(1){
       switch(choice){
           case 1:
               displayGrades(grade,Students);
               break;
           case 2:
               addGrades(grade,Students);
               break;
           case 3:
               removeGrades(grade,Students);
               break;
           case 4:
               displayAverageForEachStudent(grade,Students);
               break;
           case 5:
               displayStudentNameLowestScoreEachAssign(grade,Students);
               break;
           case 6:
               displaySortedAverageForEachStudent(grade,Students);
               break;
           case 7:
               choice=7;
               break;
       }
       //Breaking condition
       if(choice==7)
               break;
           else{
               cout<<"Enter Choice"<<endl;
               cout<<"1 for Display the grades\n2 for Add grade\n3 for Remove grade for all students for a selected assignment\n4 for Display Average for each student\n5 for Display the name of the student with the lowest grade for each assignment\n6 for Display a sorted list of the average scores of students\n7 for Quit\n";
               cin>>choice;
           }      
   }
   return 0;  
}

OUPUT:

PLEASE DO LIKE IF YOU LIKE AND DO COMMENT IF YOU ARE HAVING ANY DOUBTS

Add a comment
Know the answer?
Add Answer to:
Using the following parallel array and array of vectors: // may be declared outside the main...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For C++, This is part of a larger program but I only need help with writing...

    For C++, This is part of a larger program but I only need help with writing and calling this function. I am having trouble finding information on calling a 2d vector. Given : const int NUM_STUDENTS =3; string Students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; 4. Write a function called displayGrades that takes the student array and grade vector as parameters and displays the grades in the format in the sample run below. (15 points). Output: Name Assign. 1...

  • You are to write a program which will ask the user for number of students (dynamic...

    You are to write a program which will ask the user for number of students (dynamic array of class Student). For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student). **The program should give the student random grades from 0-100** Find the averages of each student and display the information. **Display name, grades, and average neatly in a function in the Student class called Display()** Sort the students...

  • You are to write a program which will ask the user for number of students (dynamic...

    You are to write a program which will ask the user for number of students (dynamic array of class Student). For each student, you will ask for first name and number of grades (dynamic array of grades as a variable in Student). **The program should give the student random grades from 0-100** Find the averages of each student and display the information. **Display name, grades, and average neatly in a function in the Student class called Display()** Sort the students...

  • using C# Write a program which calculates student grades for multiple assignments as well as the...

    using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...

  • Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student...

    Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student gradebook using a two-dimensional array. It should allow the user to enter the number of students and the number of assignments they wish to enter grades for. This input should be used in defining the two-dimensional array for your program. For example, if I say I want to enter grades for 4 students and 5 assignments, your program should define a 4 X 5...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

  • Consider the following program that reads students’ test scores into an array and prints the contents of the array. You will add more functions to the program. The instructions are given below.

    Consider the following program that reads students’ test scores into an array and prints the contents of the array.   You will add more functions to the program.  The instructions are given below.              For each of the following exercises, write a function and make the appropriate function call in main.Comments are to be added in the program. 1.       Write a void function to find the average test score for each student and store in an array studentAvgs. void AverageScores( const int scores[][MAX_TESTS],                       int...

  • C programming. 1.Create a program that does the following - Creates three pointers, a character pointer...

    C programming. 1.Create a program that does the following - Creates three pointers, a character pointer professor, and two integer pointers student_ids, grades - Using dynamic memory, use calloc to allocate 256 characters for the professor pointer - Prompts the professor for their name, and the number of students to mark. - Stores the professor’s name using the professor pointer and in an integer the number of students to mark. - Using dynamic memory, use malloc to allocate memory for...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and...

    Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and use a 2D array Student will demonstrate the ability to create and use a jagged array Student will demonstrate the ability to design a menu system Student will demonstrate the ability to think Program Specifications: Write a program that does the following: Uses a menu system Creates an array with less than 25 rows and greater than 5 rows and an unknown number of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT