This assignment is to practice function definitions and func

This assignment is to practice function definitions and function calls that accept arrays as arguments. Also, to practice with objects by object instantiation and accessing member variables. In this lab you will define a structure definition called Student, which will contain a cstring for the student\'s name, and an integer array of size 3 called tests that will hold the values of that particular student\'s test scores.
You will write a user controlled looping program that will instantiate a Student object, prompt the user for the student\'s name, and enter the student\'s three test scores. The program will then display the student\'s name, followed by the three test scores, the average of the tests up to 1 decimal point, and the corresponding letter grade.

Then ask the user to type in the full word \"yes\" if the user wishes to enter another student (then repeat), otherwise end the loop and let the program close.

Define and use the following functions within your program:

Student getStudent(); - This function will create a temporary Student object, prompt the user for the student\'s name and input in the the object\'s member variable. Then prompt for three test scores and enter into the object\'s integer array tests for each score, validating that the score is withing 0..100. Then return the temporary object.

void displayStudent(Student s); - This function will access and print out the passed student\'s name and then call displayStudentDetails.

void displayStudentDetails(const int[], const int); - This function will pass the student\'s tests array and the amount of tests the student has taken. This function will traverse the passed array, keeping a running total for each test score value and outputting each test score. This function will then call calcAverage passing the accumulated total and the number of tests the student has taken, assigning the returned value to a local double variable called avg. Display the avg up to 1 decimal point. Finally, call the function displayStudentLetterGrade passing the returned value avg.

double calcAverage(int total,int count); - This function will calculate and return the quotient of the total / count. (hint: remember to typecast as a double in order to return a double)

void displayStudentLetterGrade(double avg); - This function will display the corresponding letter grade value given the passed avg. If the avg is >= 90 then print to the screen \"A\" ... and so on.

int main() is in the following:

Solution

#include<bits/stdc++.h>// cin cout

#include<cstring> // strlen strcpy strcat strcmp

#include<iomanip> // setprecision fixed showpoint setw

using namespace std;

#define MAX 32

#define MAX_TEST 3

// Student Structure Defintion

struct Student{ // Access member var -- obj.memberVariable

char name[MAX]; // member variable

int tests[MAX_TEST]; // member variable

};

Student getStudent()

{

fflush(stdin);

Student stemp;

cout<<\"Enter student name\ \";

cin>>stemp.name;

cout<<\"Enter test score of\"<<stemp.name<<\"\ \";

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

{

cin>>stemp.tests[i];

}

return stemp;

}

double calcAverage(int total,int count)

{

return (double)total/count;

}

void displayStudentLetterGrade(double avg)

{

if(avg>=90.0)

cout<<\"Grade is A\"<<endl;

else if(85<avg<90)

cout<<\"Grade is B\"<<endl;

else if(75<avg<80)

cout<<\"Grade is C\"<<endl;

}

void displayStudentDetails(const int tests[], const int max)

{

int total=0;

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

{

cout<<\"Score of Test \"<<i+1<<\" \"<<tests[i]<<endl;

total+=tests[i];

}

double avg=calcAverage(total,max);

cout<<\"Average is \"<<avg<<endl;

displayStudentLetterGrade(avg);

}

void displayStudent(Student s)

{

cout<<\"Student name is \"<<s.name<<endl;

displayStudentDetails(s.tests,3);

}

int main() {

char response[MAX];

char ch[3];

Student stud;

do{

stud = getStudent();

displayStudent(stud);

cout << \"Enter another student? \\\"Y/N\\\": \";

fflush(stdin);

cin.getline(response,MAX);

cin>>ch;

}while(strcmp(response,\"NO\"));

cout << endl;

return(0);

}

This assignment is to practice function definitions and function calls that accept arrays as arguments. Also, to practice with objects by object instantiation a
This assignment is to practice function definitions and function calls that accept arrays as arguments. Also, to practice with objects by object instantiation a
This assignment is to practice function definitions and function calls that accept arrays as arguments. Also, to practice with objects by object instantiation a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site