I have an assignment and am having a little trouble with it. Here is what I have
ID: 3763998 • Letter: I
Question
I have an assignment and am having a little trouble with it. Here is what I have so far. Please help!! I am new to this and am stuck.
#include #include using namespace std; int main() { int grade, kount, average, max_score, min_score; kount = 0; ifstream inFile; inFile.open("i:\programming\grades.txt"); inFile >> grade; while (!inFile.eof()) { if (grade >= 0 && grade 100) cout = 0 && grade = 60 && grade = 90 && grade > grade; } inFile.close(); cout << " Hit enter to continue..."; cin.get(); return 0; }
Here is the assignment and the constraints. I am new to this and am still having issues with it. If anyone can help and guide me in the right direction it would be much appreciated. Write a program to read in a collection of exam scores ranging in value from 0 to 100. Your program should sort the scores in ascending order and display on a separate row: each sorted score followed by text indicating its category count (quantity of scores entered) the quantity of outstanding scores (90 - 100) the quantity of satisfactory scores (60 - 89) the quantity of unsatisfactory scores (0 - 59) the quantity of invalid scores (less than 0 or greater than 100) the average score (with 2 decimal digits) the highest score the lowest score Do not include the invalid scores in the average, max, or min. You will need to create a data file named grades.txt. (Use notepad to enter the following data values and save them on your drive). 63 75 121 72 72 78 67 -9 80 63 75 90 89 43 59 93 82 -113 33 97 202 40 60 55 88 91 101 66 Your program should print output starting at the top of the screen with your name followed by some column headings to identify the output. Be sure to include remarks identifying the author, date written, and what the program does. CONSTRAINTS: NO GLOBAL VARIABLES ALLOWED. Read scores from an input file called grades.txt. Write results of output to the screen. Use functions to read in the scores from the file, to display the scores in the array, to find the min, max and average of the scores, and to sort the scores in the array.
Explanation / Answer
#include <iomanip>
#include<fstream>
using namespace std;
int main()
{
int grade, kount, average, max_score, min_score, sum=0, temp;
int a[100];
kount = 0;
ifstream inFile;
inFile.open("grades.txt");
inFile >> grade;
int i=0;
while (!inFile.eof()) {
if (grade >= 0 && grade <= 100)
{
kount += 1;
sum=sum+grade;
a[i]=grade;
i++;
}
cout << " " << setw(10) << grade;
if (grade < 0 || grade > 100)
cout << " Invalid ";
else if (grade >= 0 && grade <= 59)
cout << " Unsatisfactory ";
else if (grade >= 60 && grade <= 89)
cout << " Satisfactory ";
else if (grade >= 90 && grade <= 100)
cout << " Outstanding ";
else
cout << endl;
inFile >> grade;
}
for(int i=0;i<kount;i++)
{
for(int j=0;j<kount-i-1;j++)
{
if(a[j>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
average=sum/kount;
cout<<"Average : "<<average;
cout<<"Minmum : "<<a[0];
cout<<"Maximum : "<<a[kount];
inFile.close();
cout << " Hit enter to continue...";
cin.get();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.