Professional Documents
Culture Documents
Homework 4
Homework 4
//9/26/17
//Homework 4
#include <iostream>
#include <fstream>
#include <iomanip>
//compute each student's average with one copy of high and low thrown out.
//if student id == a, add grades, move on to next
/*ifstream fin;
ofstream fout;
fpit.set(ios::fixed);
fpit.setf(ios::showpoint);
fout.prescison(2);*/
using namespace std;
void main()
{
int ID;
int score;
int student;
int highest;
int lowest;
float aveg = 0;
int count = 0;
ifstream fin;
ofstream fout;
fout.open("Answers.dot");
fout << setw(20) << "Student ID" << setw(12) << "Average" << endl;
fout << "------------------------------------------" << endl;
fout.setf(ios::fixed);
fout.setf(ios::showpoint);
fout.precision(2);
fin.open("Quizzes.dat");
fin >> ID >> score;
highest = score;
lowest = score;
student= ID;
count = 0;
fin >> ID >> score;
while (!fin.eof())
{
if (ID == student)
{
if (lowest == highest)
{
if (score < lowest)
{
lowest = score;
}
if (score > highest)
{
highest = score;
}
if (score == highest && score == lowest)
{
aveg = score + aveg;
count++;
}
fin >> ID >> score;
}
if (score <= lowest)
{
aveg = aveg + lowest;
lowest = score;
count++;
}
if (score >= highest)
{
aveg = aveg + highest;
highest = score;
count++;
}
if (score < highest && score > lowest)
{
aveg = aveg + score;
count++;
}
}
if (ID != student)
{
aveg = aveg / count;
fout << setw(15) << student << setw(15) << aveg << endl;
aveg = 0;
highest = score;
lowest = score;
count = 0;
student = ID;
}
aveg = aveg / count;
fout << setw(15) << student << setw(15) << aveg << endl;
}