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
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...
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>...
Please write it in c# program please and if possible no arrays only loops Loop Introduction...
Please write it in c# program please and if possible no arrays only loops Loop Introduction Assignment Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3. Your program will contain three functions: Function #1: Will ask the user for their weight in pounds and their height in inches.   Your function will convert the weight and height into Body Mass Index (BMI). The formula for converting weight into...
In this lab, you complete a partially prewritten C++ program that uses an array. The program...
In this lab, you complete a partially prewritten C++ program that uses an array. The program prompts the user to interactively enter eight batting averages, which the program stores in an array. The program should then find the minimum and maximum batting average stored in the array as well as the average of the eight batting averages. The data file provided for this lab includes the input statement and some variable declarations. Comments are included in the file to help...
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...
You are to write a program that will process students and their grades. For each student...
You are to write a program that will process students and their grades. For each student the program will read in a student’s name. It should also read in 10 test scores for the student and calculate his or her average. You must read the scores using a loop. The program should output the student’s name, average and letter grade. The average should be displayed accurate to 1 decimal digit. Letter grades are assigned based on the scale: 90-100    A...
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...
Write a program in C++ that inputs an unknown number of test scores (assume that there...
Write a program in C++ that inputs an unknown number of test scores (assume that there is a maximum of 150 scores). Ask the user how many scores that they will be entering. The program should have at least 3 functions. Make sure the functions perform the following: Calculate the average score Find the highest score Find the lowest score Sort the list from highest to lowest Output the number of scores, the average, the sorted list, the highest, and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT