Question

Assignment #4 – Student Ranking : In this assignment you are going to write a program...

Assignment #4 – Student Ranking :

In this assignment you are going to write a program that ask 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. 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.
  2. 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.
  3. 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
  4. 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.)
  5. Define constants as global constants. Do not use any literal in the program, use their identifiers.
  6. Write function prototypes.
  7. Keep variable definitions local.
  8. 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.
  9. Ask for number of the students to user.
  10. Array of students, test scores, and averages are parallel arrays. This means they store related data in the same subscript.
  11. The array of test scores is a two-dimensional array. First subscript holds number of students and second subscript holds number of test scores.
  12. 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.
  13. 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.
  14. Call findAverage function.
  15. Call displayList function.
  16. Call sort function.
  17. Call displayList function.
  18. Use comment lines to describe block of code statements in the program.

Rubric

  • Complete and working program with correct calculations and no errors. (5 points)
  • Code readability with indentations, spaces when necessary (4 points)
  • Comment lines for description (4 points)
  • Local variable definitions in the appropriate function. (5 points)
  • Global constants definition and using the named constant in the program (5 points)
  • Array definitions (2D and parallel arrays) (10 points)
  • Input Validation. (10 points)
  • Recording user inputs in arrays in a nested for loop(10 points)
  • Working with parallel arrays (4points)
  • Sorting function prototype, definition, and call (15 points)

Homework Answers

Answer #1
#include <iostream>
#include<string>
using namespace std;
#define MAX 100   // or use const int MAX=100;
//const int MAX=100;
#define init 0
#define TS 3


void findAverage(const string [MAX],const float [MAX][TS],float [MAX],int );//prototypes
void displayList(const string [MAX],const float [MAX],int );
void sort(string [MAX],float [MAX],int );


int main()
{
    float grades[MAX][TS],avg[MAX];
    string name[MAX];
    int i,n;
    cout<<"User can enter 3 test scores and any number of students limited to 100."<<endl;
    while(1)    //check validity of input
    {
    cout<<" Enter number of the students ";
    cin>>n;
    if(n>=1 && n<=MAX)
       break;
    else
       cout<<"Invalid::valid  number of students 1-100"<<endl;
    }
    for(i=init;i<n;i++)    //to enter student details
    {
        cout<<"enter the name of sudent["<<i+1<<"]::";
        cin.ignore();
        getline(cin,name[i]);
        for(int j=init;j<TS;j++)
        {
             cout<<"enter score["<<j+1<<"]the name of sudent["<<i+1<<"]::";
             cin>>grades[i][j];
        }
    }
    
    findAverage(name,grades,avg,n);   //function calls
    cout<<"before sorting"<<endl;
    displayList(name,avg,n);
    sort(name,avg,n);
    cout<<"after sorting"<<endl;
    displayList(name,avg,n);
    return 0;
}



void findAverage(const string name[MAX],const float grades[MAX][TS],float avg[MAX],int n)
{
 for(int i=init;i<n;i++)        //find average
    {
        float sum=init;
        for(int j=init;j<TS;j++)
        {
           sum=sum+grades[i][j]; 
        }
        avg[i]=sum/TS;
    }   
}

void displayList(const string name[MAX],const float avg[MAX],int n)
{
  cout<<"Student Details"<<endl;
  for(int i=init;i<n;i++)
    {
        cout<<"student["<<i+1<<"]:: name:"<<name[i]<<"\t"<<"average::"<<avg[i]<<endl;
    }
}

void sort(string name[MAX],float avg[MAX],int n)
{
   for(int i=init;i<n-1;i++)     //selection sort
   {
       for(int j=i+1;j<n;j++)
       {
           if(avg[i]<avg[j])
           {
               float t1=avg[i];
               avg[i]=avg[j];
               avg[j]=t1;
               string t2=name[i];
               name[i]=name[j];
               name[j]=t2;
           }
       }
   }
}
Know the answer?
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
Similar Questions
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
write a program that automates the process of generating the final student report for DC faculty...
write a program that automates the process of generating the final student report for DC faculty considering the following restrictions. Consider declaring three arrays for processing the student data: studID studName studGrade The student ID is a random number generated by the 5-digit system in the range of (10000 - 99999). Create a function to assign the student ID generated in an array of numbers. Consider the following to generate the random number: Add the libraries: #include <stdlib.h> #include <ctime>...
C++ //StudentDataStructure.txt //Student records are stored in a parallel-array Data Structure. Here is the code to...
C++ //StudentDataStructure.txt //Student records are stored in a parallel-array Data Structure. Here is the code to generate and populate Parallel-Array Data Structure: const int NG = 4; //Number of Grades string names[] = {"Amy Adams", "Bob Barr", "Carla Carr", "Dan Dobbs", "Elena Evans" }; int exams[][NG]= { {98,87,93,88}, {78,86,82,91}, {66,71,85,94}, {72,63,77,69}, {91,83,76,60} };    --------------------------------------------------------------------------------- 1 A) Create and Populate a Parallel-Array Data Structure using the code described in "StudentDataStructure.txt". B) Define a Record Data Structure for student records. It...
Coffee Order Structure Assignment Write a program that uses a structure for a coffee order. A...
Coffee Order Structure Assignment Write a program that uses a structure for a coffee order. A coffee order consists of a double price, a string for flavor, and characters for cream (Y/N), sugar (Y/N), and coffee size (S/M/L). Your main() function will call an order function that will ask the user for the flavor, size and whether or not they want cream or sugar. Your main() function will then create a coffee order structure and assign all of the values...
Q: Design a program that lets the user enter the total rainfall for each of 12...
Q: Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts. Create parallel arrays for the month names and rainfall amounts for each month. Use month names (i.e. January, February, March, etc.) when printing out the months with the highest and lowest amounts. Include a modular...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics relating to data supplied by the user. The program will ask the user to enter the number of items making up the data. It will then ask the user to enter data items one by one. It will store the data items in a double array. Then it will perform a number of statistical operations on the data. Finally, it will display a report...
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
Write a program that allows two players to play a game of tic-tac-toe. Use a twodimensional...
Write a program that allows two players to play a game of tic-tac-toe. Use a twodimensional char array with three rows and three columns as the game board. Each element in the array should be initialized with an asterisk (*). The program should run a loop that: • Displays the contents of the board array. • Allows player 1 to select a location on the board for an X. The program should ask the user to enter the row and...
Programing lanugaue is C++ Plan and code a menu-driven modular program utilizing an array An input...
Programing lanugaue is C++ Plan and code a menu-driven modular program utilizing an array An input file has an unknown number of numeric values(could be empty too).Read the numbers from the input fileand store even numbers in one arrayand odd numbers in another array.Create menu options to Display count of even numbers, count of odd numbersand the sum values in each array Determine the average of each array Determine the median of each array Sort each array in ascending order(use...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT