Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Task: Write a C++ program to process student scores using functions, array o

ID: 3573068 • Letter: C

Question

C++

Task: Write a C++ program to process student scores using functions, array of structures, pass-by-Reference, const keyword, and random number generator.

Each array element is a structure which contains the following data for a student:

a student’s ID (sid, int value to an ID between 1 and 4999),

three scores for mid-term tests (m_score, int value between 15 and 30)),

a score for the final exam (f_score, int value between 21 and 40)),

a composite score (c_score, int value) which will be calculated by the program,

a grade (grade, char value) to be assigned based on a grading algorithm.

The composite score (c_score) for each student is derived as follows:

c_score = (sum of two higher m_scores) + f_score

Note that the lowest m_score is not used for grading.

The grade is assigned as: A: 90 and up; B: 80-89; C: 70-79; D: 60-69; F: 59 and below

Requirements:

Must use an array of structures to store student’s scores data. For this assignment, let’s assume we want to process data for five students. Hence an array of five structure elements should be defined.

Use random number generator to generate ID and all scores.

The main function should be short and concise. Its primary tasks, besides defining an array of structures to store scores data, is to call other functions to do the score processing works such as:

set proper values for the structures in the array;

process scores data and assign grades;

display the scores and grades data that are stored in the array.

Implement a function (e.g. setData or setScores) which receives an array of structures as parameter and set up values for the structure members in the array.

Implement a function (e.g. proessData or processScores) which receives an array of structures as parameter and use its contents to calculate composite scores and assign grades for all students.

Implement a function (e.g. displayData or displayScores) which receives an array of structures as parameter and print scoring information (id, scores and grade) for all students. Make sure that this function is not allowed to modify the array it received.

Functions in items 4, 5 and 6 must receive array parameter using either Pass-by-Reference or the conventional C-style parameter passing method, They can also call other functions to perform subtasks such as computing composite score, assigning grade, formatting output, and so on.

The program output should display each student’s data (ID, 4 scores, composite score, and grade), row-by-row, well aligned. Note that the student ID should be displayed with 4 digits with leading zeros if necessary.

Here is a sample output:

8. Ille output should display each student's data (ID, 4 scores, co row-by-row, well aligned. Note that the student ID should be displayed zeros if necessary. Here is a sample output SID MS 1 MS2 MS3 FIN COMP Grade 0123 25 22 38 91 4321 18 27 23 31 81 9. Turn in the source code and output screen for grading;

Explanation / Answer

PROGRAM CODE:

/*

* main.cpp

*

* Created on: 29-Nov-2016

* Author: kasturi

*/

#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;
struct student

{

int sid;

int m_score[3];

int f_score;

int c_score;

char grade;

};

void setData(struct student stud[], int size);

void processData(struct student stud[], int size);

void displayData(struct student stud[], int size);

int generateRandom(int min, int mx);

//main function to create a struct array and then call the functions
int main()

{

struct student students[5];
setData(students, 5);
processData(students, 5);
displayData(students, 5);

return 0;

}

//function to insert values into the struct array
void setData(struct student stud[], int size)

{

for(int i=0; i<size; i++)

{

stud[i].sid = generateRandom(0001,4999);

stud[i].m_score[0] = generateRandom(15, 30);

stud[i].m_score[1] = generateRandom(15,30);

stud[i].m_score[2] = generateRandom(15,30);

stud[i].f_score = generateRandom(21,40);

}

}

//function to generate randome number between a range
int generateRandom(int min, int max)

{

return rand() % (max-min+1) + min;

}

//function to calculate composite and grade
void processData(struct student stud[], int size)

{
   //using for loop to loop through the pointer array
for(int i=0; i<size; i++)

{

//checking which two of the three is the highest value in m_score
if(stud[i].m_score[0] < stud[i].m_score[1] && stud[i].m_score[0] < stud[i].m_score[2])

stud[i].c_score = (stud[i].m_score[1] + stud[i].m_score[2]) + stud[i].f_score;

else if(stud[i].m_score[1] < stud[i].m_score[0] && stud[i].m_score[1] < stud[i].m_score[2])

stud[i].c_score = (stud[i].m_score[0] + stud[i].m_score[2]) + stud[i].f_score;

else if(stud[i].m_score[2] < stud[i].m_score[0] && stud[i].m_score[2] < stud[i].m_score[1])

stud[i].c_score = (stud[i].m_score[0] + stud[i].m_score[1]) + stud[i].f_score;

//determining the grade
if(stud[i].c_score >= 90)

stud[i].grade = 'A';

else if(stud[i].c_score >= 80 && stud[i].c_score <90)

stud[i].grade = 'B';

else if(stud[i].c_score >= 70 && stud[i].c_score <80)

stud[i].grade = 'C';

else if(stud[i].c_score >= 60 && stud[i].c_score <70)

stud[i].grade = 'D';

else if(stud[i].c_score <60)

stud[i].grade = 'F';

}

}

//displaying the student records
void displayData(struct student stud[], int size)
{
   //heading for the student score table
   cout<<" SID"<<" MS1"<<" MS2"<<" MS3"<<" FIN"<<" COMP"<<" Grade ";
   cout<<" --- --- --- --- --- --- --- ";
  
   //using for loop to print from the pointer
   for(int i=0; i<size; i++)
{
//adding zeros when the random id is less than 4 digits
    string id = to_string(stud[i].sid);
   int len = id.length();
   if(len<4)
   {
       id = "";
       while(len != 4)
       {
           id += "0";
           len++;
       }
       id+=to_string(stud[i].sid);
   }
   //printing out all the scores and grade along with id
    cout<<" "<<id<<" "<<to_string(stud[i].m_score[0])<<" "<<to_string(stud[i].m_score[1])<<" ";
    cout<<to_string(stud[i].m_score[2])<<" "<<to_string(stud[i].f_score)<<" "<<to_string(stud[i].c_score)<<" "<<stud[i].grade<<" ";
}
}

OUTPUT:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote