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

Structs file name: lab2.cpp 1. (3 points) Define a struct, named FullName, that

ID: 3541553 • Letter: S

Question


Structs
file name: lab2.cpp


1. (3 points)
Define a struct, named FullName, that contains the following fields:
lastname - a string
firstname - a string
midInitial - a char


2. (4 points)
Define a struct, named Student, that contains the following fields:
name - a FullName (the structure from section a)
tests - an array for storing 3 floats
average - a float
lettergrade - a char


3. (2 points)
In a main() function, declare a variable, named roster, that is an array (size 24) of your new Student structure type.


4. (2 points)
Write a function with the following prototype:
float DetermineAverage(const float[3]);
The function should accept an array of 3 floats as a parameter and then should return the average of the three numbers.


5. (2 points)
Write a function with the following prototype:
char DetermineLetterGrade(float);
The function should accept a float(test grade) as a parameter and should return the corresponding letter grade based on the following grading scale:
90% - 100%: A
80% - 89%: B
70% - 79%: C
60% - 69%: D
Below 60%: F


6. (6 points)
Write a function with the following prototype:
Student GetData();
The function will prompt the user to enter her/his name and three test scores. In the function, call DetermineAverage() to find the Student

Explanation / Answer

1. (3 points)
Define a struct, named FullName, that contains the following fields:
lastname - a string
firstname - a string
midInitial - a char

struct FullName
{
string lastname;
string firstname;
char midInitial;
};

2. (4 points)
Define a struct, named Student, that contains the following fields:
name - a FullName (the structure from section a)
tests - an array for storing 3 floats
average - a float
lettergrade - a char

struct Student
{
struct FullName name;
float tests[3];
float average;
char lettergrade;
};

3. (2 points)
In a main() function, declare a variable, named roster, that is an array (size 24) of your new Student structure type.

struct Student roster[24];

4. (2 points)
Write a function with the following prototype:
float DetermineAverage(const float[3]);
The function should accept an array of 3 floats as a parameter and then should return the average of the three numbers.

float DetermineAverage(const float test[3])
{
return (test[0]+test[1]+test[2])/3.0;
}

5. (2 points)
Write a function with the following prototype:
char DetermineLetterGrade(float);
The function should accept a float(test grade) as a parameter and should return the corresponding letter grade based on the following grading scale:
90% - 100%: A
80% - 89%: B
70% - 79%: C
60% - 69%: D
Below 60%: F

char DetermineLetterGrade(float avg)
{
if(avg>=90 && avg <=100) return 'A';
else if(avg>=80 && avg <=89) return 'B';
else if(avg>=70 && avg <=79) return 'C';
else if(avg>=60 && avg <=69) return 'D';
return 'F';
}


6. (6 points)
Write a function with the following prototype:
Student GetData();
The function will prompt the user to enter her/his name and three test scores.
In the function, call DetermineAverage() to find the Student