Sunteți pe pagina 1din 3

// Name/CLID: Nguyen Duong Minh/mdn4709

// Course/Section: CMPS 150 -- Section 4

// Assignment: pa6

// Date Assigned: Tuesday, October 28, 2008

// Date/Time Due: Tuesday, November 4, 2008 –- 10:00 pm

//

// Description: Write a program with an EOF-control loop. The program will calculate the
average of each student,

// then the average of the whole class and print everything out on to the screen.

// Certification of Authenticity:

// I certify that this assignment is entirely my own work.

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

int main()

// declare variable

ifstream inFile;

int counter=0, sum=0, test1=0, test2=0, test3=0;

string name;

double average, classAverage;


// open file and check whether the file can be opened.

inFile.open("pa6.in");

if (inFile.fail())

cout << "The program specified cannot be found.";

return 0;

// output header

cout << fixed << showpoint << setprecision(1);

cout << setw(15) << "Name " << setw(10) << "Scores" << setw(16) << "Average" << endl;

cout << "-------------------------------------------------------------" << endl;

// read file and perform tasks

inFile >> name >> test1 >> test2 >> test3;

while (inFile.eof() != true)

counter = counter + 3;

sum = sum + test1 + test2 + test3;

average = double(test1 + test2 + test3)/3;

cout << setfill(' ');

cout << setw(15) << name << setw(5) << test1 << setw(5) << test2 << setw(5) << test3 <<
setw(8) << average << endl;

inFile >> name >> test1 >> test2 >> test3;

classAverage = sum/counter;

cout << "-------------------------------------------------------------" << endl;


cout << "Class average: " << classAverage;

return 0;

S-ar putea să vă placă și