Hello!
This is kind of a file read/output problem.
This is a homework assignment, so I'm not looking for actual answers, I'm just looking for assistance on some of my small problems.
This is what is required of me:
Practice using loops and functions. Write a program to compute the GPA for a number of students. Student (last) names appear at the start of each line in the file. A student’s letter grades (no plus/minus grades allowed) appear after the name with spaces between. Students have taken different numbers of courses (but all courses carry same credit value). You may handle this problem the way we solved a similar problem (see page 285 example 5-22 and my sample data below). Output your heading, then a heading for the table, then a list of names and GPAs in tabular format. Use the iomanip header to properly format numerical output: GPAs should show 2 decimal places. After displaying names/gpas display name and gpa of students with highest average.
Use a function getValue which accepts a char argument and returns the numerical grade point value. It’s prototype would be
float getValue(char);
A sample file might look like this:
Jones A B B A X
Smith C C C C C X
Adams A A A X
With output (after your heading)
Name GPA
Jones 3.50
Smith 2.00
Adams 4.00
Highest GPA: Adams: 4.00
I have started coding this, but am not sure how to successfully use the prototype.
I attempted coding without it, but I do not know how to make the program display the names without displaying all of the grades with them.
Also when I use the while loop for the letter grades, I always get an error about using comparisons and I have no idea what that means.
Here is what I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <iostream>
#include <fstream>
using namespace std;
int main() {
cout<<"Zachary Knapp"<<endl;
cout<<"CSCI 116"<<endl;
cout<<"Project 5"<<endl;
cout<<"Due February 27, 2015"<<endl;
string name;
float gpa;
int grade, amount, sum;
char letter;
cout<<endl;
cout<<"Students' Grades"<<endl;
ifstream input;
input.open("grades.txt");
input>>name;
while (name!="xxx"){
cout<<name<<endl;
input>>name;
}
input>>letter;
while (letter!="Z"){
switch (letter){
case 'A':
gpa=4.0;
break;
case 'B':
gpa=3.0;
break;
case 'C':
gpa=2.0;
break;
case 'D':
gpa=1.0;
break;
default:
gpa=0;
}
input>>letter;
gpa=grade;
cout<<grade<<endl;
}
return 0;}
|