Here is my assignment and the code I have written so far. Please tell me what else needs to be done. Also, I do not understand sentinal controlled loops.
CSCI 1010 Programming Assignment 7
Purpose:
Write a C++ program that uses strings, reference parameters from Chapter 9 and while loop from Chapter 7 with a sentinel value (see pages 163-165).
Due Date: The program is due by 8 p.m. on Monday 11/6/06.
Assignment:
White a C++ program that will input a student’s name and 3 test grades. It will compute the average grade for the student, write out the student’s name, three test scores, and average grade. The program must use the following 3 functions in addition to the main function:
1. a void function to read in the student’s name as a string and pass it back as a reference parameter.
2. a double function that reads in the three test scores ,computes the average and passes back the 3 test scores via reference parameters and the average as the value of the double function.
3. a void function that displays the output data (student’s name, 3 test grades and average grade) with appropriate labels.
The program must use a sentinel controlled loop. The program should continue processing students until and uppercase DONE is entered for the student’s name. When DONE is entered, no test scores are to be read or processed. The program is to end.
D. Sample Run where the bold data was entered by the user
Enter student’s name or DONE to quit: John Smith
Enter 3 test scores: 85 90 77
Student: John Smith
Three test scores: 85 90 77
Average grade: 84.00
Enter student’s name or DONE to quit: Jim Mirth
Enter 3 test scores: 95 90 79
Student: Jim Mirth
Three test scores: 95 90 79
Average grade: 88.00
Enter student’s name or DONE to quit: DONE
Code:
#include <iostream>
using namespace std;
void name (string & student);
//Void function to read name and pass back as ref.
double avg (double & gradea, double & gradeb, double & gradec);
//Function 2 - computes average and passes back scores via reference par.
void displaystuff (string student, double gradea, double gradeb, double gradec, double averagex);
//Function 3 - Display the Information.
int main ()
{//int main open
string name;
double gradeone, gradetwo, gradethree, average;
cout << "Enter Student Name or DONE to Quit:" << endl;
cin. ignore (80, '\n');
getline (cin, name);
while (name != DONE)
{//while loop open
cout << "Enter 3 Test Scores:" << endl;
cin >> gradeone >> gradetwo >> gradethree;
average = avg (gradeone, gradetwo, gradethree);
displaystuff (name, gradeone, gradetwo, gradethree, average);
cout << "Enter Student Name or DONE to Quit:" << endl;
cin. ignore (80, '\n');
getline (cin, name);
}//while loop close
}//int main close
void name (string & student)
double avg (double & gradea, double & gradeb, double & gradec)
{//function open
double averaged, added;
added = gradea + gradeb + gradec;
averaged = added/3;
return averaged;
}//function closed
void displaystuff (string student, double gradea, double gradeb, double gradec, double averagex)
{//void function open
cout << "Student: " << student << endl;
cout << "Three Test Scores: " << gradea << " " << gradeb << " " << gradec << endl;
cout << setiosflags (ios::fixed|ios::showpoint) << setprecision (2);
cout << "Average Grade: " << averagex << endl;
}//void function close