0% found this document useful (0 votes)
33 views3 pages

Homework 4

This C++ code is calculating student averages from quiz scores stored in a data file. It reads in student IDs and scores, tracks the highest and lowest score for each student, calculates the average after removing the high and low scores, and outputs the student IDs and averages to a separate output file. It uses if/else statements to handle different cases for scoring and averaging as it loops through reading the input file.

Uploaded by

api-329343291
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Homework 4

This C++ code is calculating student averages from quiz scores stored in a data file. It reads in student IDs and scores, tracks the highest and lowest score for each student, calculates the average after removing the high and low scores, and outputs the student IDs and averages to a separate output file. It uses if/else statements to handle different cases for scoring and averaging as it loops through reading the input file.

Uploaded by

api-329343291
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//Chloe Sebring

//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;

fin >> ID >> score;

}
aveg = aveg / count;
fout << setw(15) << student << setw(15) << aveg << endl;
}

You might also like