Question: C++ : Please provide a detailed pseudocode as a multi lined comment for the source code below. Also please include any commenting you would include

C++ : Please provide a detailed pseudocode as a multi lined comment for the source code below. Also please include any commenting you would include next to the statements.

#include

using namespace std;

void GetGrades(double* scores, string* students, int size)

{

int i;

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

{

cout<<"Enter name : ";

// read complete line

cin>>*( students + i );

cout<<"Enter score : ";

cin>>*(scores + i);

// loop untill valid data is entered

while( *(scores + i) < 0 )

{

cout<<"Error!Entered data can't be negative ... ";

cout<<"Enter score : ";

cin>>*(scores + i);

}

cout<<endl;

}

}

void DisplayGrades(double* scores, string* students, int size, double avg)

{

cout<<"Student Score ";

int i;

// display the data

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

cout<<*(students + i)<<" "<<*(scores + i)<<endl;

cout<<"Class average is: "<<avg<<endl;

}

void Sort(double* scores, string* students, int size)

{

int i, j;

for (i = 0; i < size - 1; i++)

{

// the previous i elements are placed

for (j = 0; j < size - i - 1; j++)

{

// swap the two elements

if (*(scores + j) > *(scores + j + 1))

{

double temp = *(scores + j);

*(scores + j) = *(scores + j + 1);

*(scores + j + 1) = temp;

string temp1 = *(students + j);

*(students + j) = *(students + j + 1);

*(students + j + 1) = temp1;

}

}

}

}

double Average(double* scores, int size)

{

double sum = 0;

int i;

// get the sum oof all elements of scores

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

sum += *(scores + i);

// calculate average and return it

return sum / (double)size;

}

int main()

{

int size;

cout<<"Enter number of students : ";

cin>>size;

while( size < 0 )

{

cout<<"Error!Entered data can't be negative ... ";

cout<<"Enter score : ";

cin>>size;

}

cout<<endl;

double *scores = new double[size];

string *students = new string[size];

GetGrades( scores , students , size );

cout<<endl;

// sort the data

Sort( scores , students , size );

// calculate average

double avg = Average( scores , size );

DisplayGrades( scores, students, size, avg);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!