Question

In: Computer Science

C++ Programming Chapter 7 Assignment: Assignment #4 – Student Ranking : In this assignment you are...

C++ Programming Chapter 7 Assignment:

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

Solutions

Expert Solution

All the explanations is given in the comments of the code itself.

Code--

#include<bits/stdc++.h>
using namespace std;
int main()
{
   int i,j,size,t;
   //prompt the user to enter the number of students
   cout<<"Enter the number of students: ";
   cin>>size;
  
   string name[size],temp;
   int scores[size][3];
   double average[size];
   //prompt the user to enter the name of students
   cout<<"Enter name of students:"<<endl;
   getline(cin,temp);
   for(i=0;i<size;i++)
   {
       getline(cin,name[i]);
   }
   //prompt the user to enter three test scores
   cout<<"Enter 3 test scores for students mentioned:\n";
   for(i=0;i<size;i++)
   {
       cout<<setw(30)<<name[i]<<": ";
       cin>>scores[i][0]>>scores[i][1]>>scores[i][2];
   }
   //calculate average and display it
   cout<<endl<<setw(30)<<left<<"Name"<<"Average"<<endl;
   for(i=0;i<size;i++)
   {
       //calculate average
       average[i]=double(scores[i][0]+scores[i][1]+scores[i][2])/3.0;
       cout<<setw(30)<<left<<name[i];
       cout<<setprecision(2)<<fixed<<average[i];
       cout<<endl;
   }
   //sort the averages and names
   for(i=0;i<size-1;i++)
   {
       for(j=0;j<size-i-1;j++)
       {
           if(average[j]<average[j+1])
           {
               //swap averages
               t=average[j];
               average[j]=average[j+1];
               average[j+1]=t;
               //swap names
               temp=name[j];
               name[j]=name[j+1];
               name[j+1]=temp;
           }
       }
   }
   //displat after sorting
   cout<<endl<<left<<setw(30)<<"Name"<<"Average"<<endl;
   for(i=0;i<size;i++)
   {
       cout<<left<<setw(30)<<name[i];
       cout<<setprecision(2)<<fixed<<average[i];
       cout<<endl;
   }
}
Code Screenshot--


Output Screenshot--

Note--

Please upvote if you like the effort.


Related Solutions

Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write...
Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write a C++ program that overloads the arithmetic operators for a pre-defined Vector object. When completing this assignment, the student should demonstrate mastery of the following concepts: · Object-oriented Paradigm · Operator Overloading - Internal · Operator Overloading - External · Mathematical Modeling Assignment In this assignment, the student will implement the overloaded operators on a pre-defined object that represents a Vector. Use the following...
c++ Programming Assignment 1: Game of Life The objective of this programming assignment is to design...
c++ Programming Assignment 1: Game of Life The objective of this programming assignment is to design and implement what is known as the “Game of Life”, conceptualized by the British mathematician John Horton Conway in 1970 to simulate the evolution patterns in a population of living organisms.   The game board is seeded with an initial population pattern, and then evolves based on the set of rules defining when a cell dies or is born into life. A cell’s life cycle...
C Programming Game Scores Assignment Outcome: Student will demonstrate the ability to design a menu driven...
C Programming Game Scores Assignment Outcome: Student will demonstrate the ability to design a menu driven program. Student will demonstrate the ability to create and use a 2D array on the stack. Student will demonstrate the use of functions. Student will demonstrate good programming style. Program Specifications: *********************************************** ** MAIN MENU ** *********************************************** A) Enter game results B) Current Record (# of wins and # of losses and # of ties) C) Display ALL results from all games WON D)...
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a...
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing input, using control structures, and bitwise operations. The input for your program will be a text file containing a large amount of English. Your program must extract the “secret message” from the input file. The message is hidden inside the file using the following scheme. The message is hidden in binary notation, as a sequence of 0’s and 1’s. Each block of 8-bits is...
Programming II: C++ - Programming Assignment Fraction Object with Operator Overloads Overview In this assignment, the...
Programming II: C++ - Programming Assignment Fraction Object with Operator Overloads Overview In this assignment, the student will write a C++ program that implements a “fraction” object. When writing the object, the student will demonstrate mastery of implementing overloaded operators in a meaningful way for the object. When completing this assignment, the student should demonstrate mastery of the following concepts: · Mathematical Modeling - Fractions · Operator Overloading – Binary Operators (Internal Overload) · Operator Overloading – Binary Operator (External...
Programming assignment 4 : C++ Write a program to do the following: 1.Define a structure to...
Programming assignment 4 : C++ Write a program to do the following: 1.Define a structure to store a date, which includes day(int), month(int), and year(int). 2.Define a structure to store an address, which includes address(house number and street)(string), city(string), state(string), zip code (string). 3.Define a class to store the following information about a student. It should include private member variables: name(string), ID (int), date of birth (the first structure), address (the second structure), total credit earned (int), and GPA (double)....
In this programming assignment, you will write C code that performs recursion. For the purpose of...
In this programming assignment, you will write C code that performs recursion. For the purpose of this assignment, you will keep all functions in a single source file main.c. Your main job is to write a recursive function that generates and prints all possible password combinations using characters in an array. In your main() function you will first parse the command line arguments. You can assume that the arguments will always be provided in the correct format. Remember that the...
Code in C Instructions For this programming assignment you are going to implement a simulation of...
Code in C Instructions For this programming assignment you are going to implement a simulation of Dijkstra’s solution to the Dining Philosophers problem using threads, locks, and condition variables. Dijkstra’s Solution Edsgar Dijkstra’s original solution to the Dining Philosophers problem used semaphores, but it can be adapted to use similar mechanisms: • Each philosopher is in one of three states: THINKING, HUNGRY, or EATING. • Every philosopher starts out in the THINKING state. • When a philosopher is ready to...
In this programming assignment, you will write C code that performs recursion. For the purpose of...
In this programming assignment, you will write C code that performs recursion. For the purpose of this assignment, you will keep all functions in a single source file main.c. Your main job is to write a recursive function that generates and prints all possible password combinations using characters in an array. In your main() function you will first parse the command line arguments. You can assume that the arguments will always be provided in the correct format. Remember that the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT