Question

In: Computer Science

Write a program that uses the defined structure and all the above functions. Suppose that the...

Write a program that uses the defined structure and all the above functions. Suppose that the class has 20 students. Use an array of 20 components of type studentType. Other than declaring the variables and opening the input and output files, the function main should only be a collection of function calls. The program should output each student’s name followed by the test scores and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________


// Ch9_Ex2Data.txt

Duckey Donald 85
Goof Goofy 89
Brave Balto 93
Snow Smitn 93
Alice Wonderful 89
Samina Akthar 85
Simba Green 95
Donald Egger 90
Brown Deer 86
Johny Jackson 95
Greg Gupta 75
Samuel Happy 80
Danny Arora 80
Sleepy June 70
Amy Cheng 83
Shelly Malik 95
Chelsea Tomek 95
Angela Clodfelter 95
Allison Nields 95
Lance Norman 88

_______________________________

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;

const int NO_OR_STUDENTS = 20;
// declare studentType struct
struct studentType
{
// variables
string studentFName;
string studentLName;
int testScore;
char grade;
};
// part a
inline void getData(ifstream& inFile, studentType sList[], int listSize)
{
// function code
string fname, lname;
int score;
int i = 0;
// Reading data from file
while (i < listSize)
{
inFile >> fname >> lname >> score;
sList[i].studentFName = fname;
sList[i].studentLName = lname;
sList[i].testScore = score;
i++;
}
inFile.close();
}
// part b
inline void calculateGrade(studentType sList[], int listSize)
{
// function code
for (int i = 0; i < listSize; i++)
{
if (sList[i].testScore >= 90)
sList[i].grade = 'A';
else if (sList[i].testScore >= 80 && sList[i].testScore < 90)
sList[i].grade = 'B';
else if (sList[i].testScore >= 70 && sList[i].testScore < 80)
sList[i].grade = 'C';
else if (sList[i].testScore >= 60 && sList[i].testScore < 70)
sList[i].grade = 'D';
else if (sList[i].testScore < 60)
sList[i].grade = 'F';
}
}
// part c
inline int highestScore(const studentType sList[], int listSize)
{
// function code
int max = sList[0].testScore;
for (int i = 0; i < listSize; i++)
{
if (max < sList[i].testScore)
{
max = sList[i].testScore;
}
}
return max;
}
// part d
inline void printResult(ofstream& outFile, const studentType sList[], int listSize)
{
  
// function code
for (int i = 0; i < listSize; i++)
{
outFile << sList[i].studentLName << ", " << sList[i].studentFName << " "
<< sList[i].testScore << " " << sList[i].grade << endl;
}
  
int max = highestScore(sList, listSize);
outFile<<"\nThe Highest Test Score :"<<max<<endl;
outFile<<"\nStudents Who got highest score:"<<endl;
// Writing data to the output file
for (int i = 0; i < listSize; i++)
{
if (max == sList[i].testScore)
outFile << sList[i].studentLName << ", " << sList[i].studentFName << " "
<< sList[i].testScore << " " << sList[i].grade << endl;
}
}


int main()
{
ifstream inData;
ofstream outData;
studentType studentList[NO_OR_STUDENTS];
inData.open("Ch9_Ex2Data.txt");
if (!inData)
{
cout << "The input file does not exist. Program terminates!"
<< endl;
return 1;
}
outData.open("out.txt");
if (!outData)
{
cout << "Cannot open the output file. Program terminates!"
<< endl;
return 1;
}
getData(inData,studentList,NO_OR_STUDENTS);
// call calculateGrade
calculateGrade(studentList,NO_OR_STUDENTS);
// call printResult
printResult(outData,studentList,NO_OR_STUDENTS);

return 0;
}

_________________________

Output:

_______________Could you plz rate me well.Thank You


Related Solutions

In C++ prototype functions above "main" and define them below "main"; Write a program that uses...
In C++ prototype functions above "main" and define them below "main"; Write a program that uses two identical arrays of at least 20 integers. It should call a function that uses the bubble sort algorithm to sort one of the arrays in ascending order. The function should keep count of the number of exchanges it makes. The program then should call a function that uses the selection sort algorithm to sort the other arrays. It should also keep count of...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
c++ Write a program that displays the status of an order. a) Program uses 2 functions...
c++ Write a program that displays the status of an order. a) Program uses 2 functions (in addition to main ()). b) The first function asks the user for the data below and stores the input values in reference parameters. c) Input data from user: # of spools ordered, # of spools in stock, any special shipping & handling charges over and above the $10 rate. d) The second function receives as arguments any values needed to compute and display...
Overview For this assignment, write a program that uses functions to simulate a game of Craps....
Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7 or 11, the...
For this assignment, write a program that uses functions to simulate a game of Craps. Craps...
For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7 or 11, the player...
Write and test a user-defined class (requiring conditions). Write an application (client) program that uses an...
Write and test a user-defined class (requiring conditions). Write an application (client) program that uses an instance(s) of a user-defined class. The federal income tax that a person pays is a function of the person's taxable income. The following table contains formulas for computing a single person's tax. Bracket Taxable Income Tax Paid 1 $22,100 or less 15% 2 More than $22,100 but $53,500 or less $3,315 plus 28% of the taxable income over $22,100 3 More than $53,500 but...
Write a C++ program that uses all the relational operators.
Write a C++ program that uses all the relational operators.
Write a program that uses a structure to store the following weather data for a particular...
Write a program that uses a structure to store the following weather data for a particular month: Total Rainfall High Temperature Low Temperature Average Temperature. The program should have an array of 12 structures to hold weather data for an entire year. When the program runs, it should ask the user to enter data for each month. (The average temperature should be calculated.) Once the data are entered for all the months, the program should calculate and display the average...
In C++ Prototype your functions above "main" and define them below "main"; Write a program that...
In C++ Prototype your functions above "main" and define them below "main"; Write a program that uses two identical arrays of at least 20 integers. It should call a function that uses the bubble sort algorithm to sort one of the arrays in ascending order. The function should keep count of the number of exchanges it makes. The program then should call a function that uses the selection sort algorithm to sort the other arrays. It should also keep count...
PYTHON: Write a script that imports the functions in the module below and uses all of...
PYTHON: Write a script that imports the functions in the module below and uses all of the functions. import math def _main():     print("#" * 28, "\n", "Testing...1, 2, 3...testing!\n", "#" * 28, "\n", sep="")     f = -200     print("{:.2f} F is {:.2f} C".format(f, f2c(f)))     f = 125     print("{:.2f} F is {:.2f} C".format(f, f2c(f)))     c = 0     print("{:.2f} C is {:.2f} F".format(c, c2f(c)))     c = -200     print("{:.2f} C is {:.2f} F".format(c, c2f(c))) def f2c(temp):     #Converts Fahrenheit tempature to Celcius     if temp <...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT