No ,doc file needed, please include screenshot when asked with the code if possi
ID: 3558521 • Letter: N
Question
No ,doc file needed, please include screenshot when asked with the code if possible, Thank you!
Strings as Arrays of Characters This lab lets students experiment with strings. Copy and paste the code below in a filename LastFirst_lab72.cpp (e.g. DoeJoe_lab72.cpp) and save it in Lab 7 folder, Bring in the LastFirst_lab72.cpp program from the Lab 7 folder, Complete the program by filling in the code. (Areas in bold) Run the program with 3 grades per student using the sample data below. Mary Brown 100 90 90 George Smith 90 30 50 Dale Barnes 80 78 82 Sally Dolittle 70 65 80 Conrad Bailer 60 58 71 Take a screen shot of the output. Save it in a filename LastFirst_lab72.doc (e.g. DoeJoeJab72.doc) Submit both the revised LastFirst_lab72.cpp and LastFirst_lab72.doc by uploading them here. The following is the code to be used:Explanation / Answer
#include <iostream>
using namespace std;
const int MAXGRADE = 25; // maximum number of grades per student
const int MAXCHAR = 30; // maximum characters used in a name
typedef char StringType30[MAXCHAR + 1];// character array data type used for names
// having 30 characters or less.
typedef float GradeType[MAXGRADE]; // one dimensional integer array data type
float findGradeAvg(GradeType, int); // finds grade average by taking array of
// grades and number of grades as parameters
char findLetterGrade(float); // finds letter grade from average given
// to it as a parameter
int main()
{
StringType30 firstname, lastname; // two arrays of characters defined
int numOfGrades; // holds the number of grades
GradeType grades; // grades is defined as a one dimensional array
float average; // holds the average of a student's grade
char moreinput; // determines if there is more input
int grade;
// Input the number of grades for each student
cout << "Please input the number of grades each student will receive." << endl
<< "This number must be a number between 1 and " << MAXGRADE << " inclusive" << endl;
cin >> numOfGrades;
while (numOfGrades > MAXGRADE || numOfGrades < 1)
{
cout << "Please input the number of grades for each student." << endl
<< "This number must be a number between 1 and " << MAXGRADE << " inclusive" << endl;
cin >> numOfGrades;
}
// Input names and grades for each student
cout << "Please input a y if you want to input more students"
<< " any other character will stop the input" << endl;
cin >> moreinput;
while ( moreinput == 'y' || moreinput == 'Y')
{
cout << "Please input the first name of the student" << endl;
cin >> firstname;
cout << endl << "Please input the last name of the student" << endl;
cin >> lastname;
for (int count = 0; count < numOfGrades; count++)
{
cout << endl << "Please input a grade" << endl;
cin >> grades[count];
// Fill in the input statement to place grade in the array
}
cout << firstname << ' ' << lastname << " has an average of ";
findGradeAvg(grades, numOfGrades);
average = findGradeAvg(grades, numOfGrades);
cout << average << " ";
findLetterGrade(average);
// Fill in call to get and print letter grade of student to screen
cout << endl << endl << endl;
cout << "Please input a y if you want to input more students"
<< " any other character will stop the input" << endl;
cin >> moreinput;
}
return 0;
}
//***********************************************************************
// findGradeAvg
//
// task: This function finds the average of the
// numbers stored in an array.
//
// data in: an array of integer numbers
// data returned: the average of all numbers in the array
//
//***********************************************************************
float findGradeAvg(GradeType array, int numgrades)
{
int count;
int sum;
for(count = 0; count < numgrades; count++)
{
sum = sum + array[count];
}
return (sum / numgrades);
}
//***********************************************************************
// findLetterGrade
//
// task: This function finds the letter grade for the number
// passed to it by the calling function
//
// data in: a floating point number
// data returned: the grade (based on a 10 point spread) of the number
// passed to the function
//
//***********************************************************************
char findLetterGrade(float numgrade)
{
if(numgrade < 60)
{
return 'F';
}
else if(numgrade < 70)
{
return 'D';
}
else if(numgrade < 80)
{
return 'C';
}
else if(numgrade < 90)
{
return 'B';
}
else if(numgrade <= 100)
{
return 'A';
}
// Fill in the code for this function
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.