Question

Write a C++ program that asks user number of students in a class and their names....

Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking.

Follow the Steps Below

  1. Save the project as A4_StudentRanking_yourname.
  2. Use functions to divide your program into manageable pieces. Define three functions: displayList, findAverage, and sort.
    1. Write function prototypes at the top and define the functions after the main function.
  3. findAverage function:
    1. This function will get 4 parameters: array of student names, 2D array of grades from 3 tests of each student, array of averages to fill in, number of students as the arrays size.
    2. You need nested for loop to calculate average of 3 test scores for each student and record it to the array of averages. (You may define array of names and 2D array of grades as constants in the parameter list since you don’t need to make any changes.)
    3. No return value needed; changes will apply on the original array of averages.
  4. displayList function:
    1. This function has 3 parameters: array of student names, array average scores, and the size of the arrays.
    2. The function doesn’t make any changes on the arrays, so define them as constants in the parameter list.
    3. Call the function twice in your program
      1. When averages are calculated
      2. When averages are sorted
  5. sort function:
    1. This function gets 3 parameters: array of students, array of averages, and number of students as the size of the arrays.
    2. Use selection sort algorithm. Sort both arrays based on the average scores in descending order. (You will apply the sort on the array of averages by comparing the scores, but apply the swapping on both arrays. They are parallel arrays. This means they use the same index numbers.)
  6. Define constants as global constants. Do not use any literal in the program, use their identifiers.
  7. Write function prototypes.
  8. Keep variable definitions local.
  9. At the beginning of the program inform user about the program. Display a message stating that they can enter 3 test scores and any number of students limited to 100.
  10. Ask for number of the students to user.
  11. Array of students, test scores, and averages are parallel arrays. This means they store related data in the same subscript.
  12. The array of test scores is a two-dimensional array. First subscript holds number of students and second subscript holds number of test scores.
  13. Validate user input with a while or do-while loop. They shouldn’t exceed the maximum number; also, it can’t be less than 1.
  14. Ask for the student names and their test scores. Use getline function to get the students’ full names. You must use cin.ignore() before using the getline function since you also use cin object.
  15. Call findAverage function.
  16. Call displayList function.
  17. Call sort function.
  18. Call displayList function.
  19. Use comment lines to describe block of code statements in the program.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Hope this answer helps you

// If u still facee any doubt feel free to ask it in the comments

// We will be very happy to solve them

#include<bits/stdc++.h>
using namespace std;
void findAverage(string names[],int grades[][3],double averages[],int n)
{
    for(int i=0;i<n;i++)
    {
        int sum=0;
        for(int j=0;j<3;j++)
        {
            sum+=grades[i][j];
        }
        averages[i]=sum/3.0;
    }
}
void displayList(const string names[],const double averages[],const int n)
{
    for(int i=0;i<n;i++)
    {
        cout<<names[i]<<"  "<<averages[i]<<endl;
    }
}
void sortAverages(string names[],double averages[],int n)
{
    // sorting using selection sort
    int i, j, min_idx;
    for (i = 0; i < n-1; i++)
    {
        min_idx = i;
        for (j = i+1; j < n; j++)
        if (averages[j] < averages[min_idx])
            min_idx = j;
        swap(averages[min_idx], averages[i]);
        swap(names[min_idx],names[i]);// swapping names parallely with averages
    }
}
int main()
{
    int n;
    // Input size of the class or number of total students
    cout<<"Enter the number of students between 1 and 100:\n";
    cin>>n;
    int grades[n][3];// this 2d array will hold grades of each student
    double averages[n];// This array will contain the average of the marks
    string names[n];// This will contain the names  of the students
    cout<<"Enter the name and 3 test scores for each of the student:\n";
    for(int i=0;i<n;i++)
    {
        cout<<"Enter the name of the student:\n";
        cin>>names[i];
        cout<<"Enter the marks of "<<names[i]<<":\n";
        for(int j=0;j<3;j++)
        {
            cin>>grades[i][j];
        }
    }
    // calling find average function
    findAverage(names,grades,averages,n);
    cout<<"Student's name with their averages before sorting are:\n";
    displayList(names,averages,n);// This will print average and names before sorting
    sortAverages(names,averages,n);
    cout<<"Student's name with their averages after sorting are:\n";
    displayList(names,averages,n);// This will print after sorting of averages
    return 0;
}

SCREENSHOTS:

#include<bits/stdc++.h> using namespace std; void findAverage (string names[], int grades[] [3], double averages[], int n) AC

void sortAverages (string names[], double averages[], int n) // sorting using selection sort int i, j, min_idx; for (i = 0; icout<<Enter the name and 3 test scores for each of the student:\n; for(int i=0;i<n;i++) { cout<<Enter the name of the studEnter the number of students between 1 and 100: 4 Enter the name and 3 test scores for each of the student: Enter the name of

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that asks user number of students in a class and their names....
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
  • 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...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • 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...

  • (JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...

    (JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students identified by rows and test scores identified by columns. Ask the user for the number of students and for the number of tests (which will be the size of the two-dimensional array). Populate the array with user input (with numbers in {0, 100} for test scores). Assume that a score >= 60 is a pass for the below. Then, write methods for: Computing the...

  • Write a console-based program ( C # ) that asks a user to enter a number...

    Write a console-based program ( C # ) that asks a user to enter a number between 1 and 10. Check if the number is between the range and if not ask the user to enter again or quit. Store the values entered in an array. Write two methods. Method1 called displayByVal should have a parameter defined where you pass the value of an array element into the method and display it. Method2 called displayByRef should have a parameter defined...

  • You are to write a program IN C++ that asks the user to enter an item's...

    You are to write a program IN C++ that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: if the an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00 If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50 Program design specs. You should have 5...

  • Question: - write a C++ program that asks user to enter students' quiz scores, calculate the...

    Question: - write a C++ program that asks user to enter students' quiz scores, calculate the total score for each students and average for all. Note: - number of students: 1 through 5. That is, at least one student and up to 5. - number of quizes: 8 through 10. That is, at least 8 quizes and up to 10. - quiz score range: 0 through 100. - when entering quiz scores, if user enters -1, that means the user...

  • Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the...

    Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the user to enter a number and based on the entered number it allocates the array size. Then based on that number it asks the user that many times to enter student’s names. What you need to do:  Add another array of doubles to store the gpa of each student as you enter them  You need to display both the student’s name and...

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