This program is from the collopy book. I just had to type it in and create a text file so it would compile correctly for a class assignment which I did. But the very last record will not be shown when i compile.
This is what is in the txt file:
Kelly Antonetz 70 50 98 80 65 85
Robert Cain 97 82 79 73 94 62
Karen Dehvae 81 87 94 85 93 89
Barry Harmo 76 77 80 81 75 92
Katrina Long 99 93 89 83 94 90
Amanda Mohr 65 67 71 84 88 96
Mike Revell 90 87 78 52 76 89
Woody Synder 76 76 83 85 77 81
//--------------GRADE REPORT--------------------------------
// Read a file, compute the six-week grade average, and
// print a six-week grade report.
//
// PROGRAM-ID:CHAP7A
// PROGRAMMER:David M. Collopy
// RUN DATE: 08/04/09
//***********************************************************
//-------------PREPROCESSING DIRECTIVES----------------------
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
//-------------FUNCTION PROTOTYPES----------------------------
void OpenFile(void); // open the grade file
void PrnHeadings(void); // print headings
void ProcessLoop(void); // processing loop
void InputRecord(void); // input grade record
void ComputeAvr(void); // compute grade average
void PrnDetail(void); // print detail line
//--------------PROGRAM SETUP----------------------------------
//** H E A D I N G L I N E S
char PT1[] = "\n S I X W E E K G R A D E R E P O R T";
char HL1[]= "Student T e s t S c o r e s Average";
char HL2[] = "---------------------------------------------------";
//** I N P U T G R A D E R E C O R D
ifstream gradeFile; // file object name
char student[16]; // student name
int grade1; // 1st week grade
int grade2; // 2nd week grade
int grade3; // 3rd week grade
int grade4; // 4th week grade
int grade5; // 5th week grade
int grade6; // 6th week grade
//** P R O G R A M V A R I A B L E S
float gradeTotal; // grade total
float gradeAvr; // grade average
//--------------------------------------------------------------
// MAINLINE CONTROL
//--------------------------------------------------------------
int main()
{
OpenFile();
if (!gradeFile.fail())
{
PrnHeadings(); // print headings
ProcessLoop(); // processing loop
gradeFile.close(); // close grade file
}
cout << "\n-----<E N D O F R U N>-----\n";
return 0;
}
//----------------------------------------------------------------
// OPEN GRADE FILE
//----------------------------------------------------------------
void OpenFile(void)
{
gradeFile.open("c://grades.txt");
if (gradeFile.fail())
cout << "Grade file open failed\n";
return;
}
//----------------------------------------------------------------
// PRINT HEADINGS
//-----------------------------------------------------------------
void PrnHeadings(void)
{
cout << PT1 << endl; // print page title 1
cout << endl << endl; // triple space
cout << HL1 << endl; // print heading line 1
cout << HL2 << endl; // print heading line 2
return;
}
//----------------------------------------------------------------
// PROCESSING LOOP
//----------------------------------------------------------------
void ProcessLoop(void)
{
InputRecord(); // input grade record
while (!gradeFile.eof())
{
ComputeAvr(); // compute average grade
PrnDetail(); // print detail line
InputRecord(); // input grade record
}
return;
}
//----------------------------------------------------------------
// INPUT GRADE RECORD
//----------------------------------------------------------------
void InputRecord(void)
{
gradeFile.get(student, 16)
>> grade1 >> grade2 >> grade3
>> grade4 >> grade5 >> grade6;
gradeFile.get(); // clear input file buffer
return;
}
//---------------------------------------------------------------
// COMPUTE GRADE AVERAGE
//---------------------------------------------------------------
void ComputeAvr(void)
{
gradeTotal = grade1 + grade2 + grade3 + grade4 + grade5 + grade6;
gradeAvr = gradeTotal/6;
return;
}
//----------------------------------------------------------------
// PRINT DETAIL LINE
//----------------------------------------------------------------
void PrnDetail(void)
{
cout << setw(15) << student << setw(4) << grade1;
cout << setw(4) << grade2 << setw(4) << grade3;
cout << setw(4) << grade4 << setw(4) << grade5;
cout << setw(4) << grade6 << setiosflags(ios::fixed);
cout << setiosflags (ios::showpoint);
cout << setw(10) << setprecision(2) << gradeAvr << endl;
return;
}
How can I get the last record to be outputted? any help would be great!
When I compile in in visual c++ it only shows up to Mike revell and his test grades and average