Write your question here.Hi guys i am having trouble outputing data from a file.I usually dont ask others to help me with coding but i have been really stuck on this problem for a while and i really need help.so i would really appreciate if anyone from you can help.Ok before i post my code here is the information about the assignment:
[b]Write a program that reads students’ names followed by their test scores from a file. The program should output each student’s name followed by their test scores, the average test score, and the relevant grade. It should also find and print the highest test score and the name of the students having the highest test score.
Student data should be stored in a struct variable of type StudentType, which has four components: name of type string; scores, an array of type int (score is between 0 and 100), average of type float, and grade of type char. Suppose that the class has 20 students and further suppose there are five tests. Use an array of 20 components of type StudentType. Input comes from a file and you must get the name of the file from the user.
The input file will be in the following format:
FirstName I. LastName
t1 t2 t3 t4 t5
FirstName LastName
t1 t2 t3 t4 t5
The file alternates between student name and test scores. Note: There may be additional 'text' in the file after the test scores of the 20th student. Your program should NOT read this extra text.
Your program must contain at least the following functions:
A function to read the students’ data into the array.
A function to convert the name into the format: "LastName, FirstName I." or "LastName, FirstName" if no middle initial present.
A function to assign the relevant grade to each student.
A function to find the highest average.
A function to output all student info in a formatted table
A function to print the names of the students having the highest average.
ok below is the input file i made and the code i have written so far..i am having trouble reading and outputting the scores from the below input file. how do i output scores?Dont worry about average and grades and convert and all those things..i just want to know how do i output the below scores?
The input file is as follows:
ron weasley
20 15 18 19 12
ron dublin
12 13 21 23 32
bill hiley
12 23 23 24 23
phill rad
34 34 32 100 23
john narc
78 87 76 65 78
sophie dier
56 67 66 67 56
ron nickle
67 67 65 45 76
pat fill
56 77 89 87 77
alex mark
56 67 66 67 56
jeff horn
98 76 67 66 65
max patty
65 56 65 57 45
riley robinson
45 54 54 34 35
ron worn
35 78 79 67 67
johnathan bake
67 67 56 89 68
mariah gomez
65 65 57 76 67
sandra mat
76 78 67 76 78
jesse daun
78 78 67 88 78
robin davidson
57 78 89 76 78
matt jenner
78 78 56 99 45
danny solia
67 65 67 56 56
how do i cout scores for each person ?
heres my code so far
Thanks
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 50 51 52 53 54 55 56 57
|
#include <iostream>
#include <fstream>
#include <string>
#include <climits>
#include <iomanip>
using namespace std;
const int num_students=20;
const int num_scores=5;
struct StudentType{
string name;
int scores [num_scores];
char grade;
float average;
};
void openfile (fstream &f);
void getdata (fstream &f,string name);
int main()
{
StudentType student[num_students];
string name;
fstream f;
openfile(f);
getdata(f,name);
return 0;
}
void openfile(fstream &f)
{
string filename;
cout<<"Enter filename:";
cin>>filename;
f.open(filename.c_str());
}
void getdata(fstream &f,string name)
{
int score;
for(int i=0;i<num_students;i++)
{
getline(f,name);
cout<<name<<endl;
for (int j=0;j<num_scores;j++)
{
f>>[i][j]; //How do i output scores?
}
}
}
|