Grade entry and calculator

Hey guys, this should be a simple program, but I'm having issues. The problem is as follows:


Write a program to complete the following tasks and record the outputs to a data file named “EGR126-Final.dat”. All the list should includes header, student ID, name and grade.

1. Read the class roster from “ClassRoster.dat” (posted on Blackboard in Course Documents). (5 points)

2. Write a module to generate random grade for each student. Print the class roster (with students’ grades) to the data file. (10 points)

• Failing rate is 20%.
• Passing grade is between 60 and 100.
• Failing grade is between 0 and 59.99.
• srand() should be used.


3. Using module to determine the average grade of the class and list the students with greater-than-average grades. (10 points)

4. Sort the list by student’s name and print the sorted list.

The "data file" looks like this:
1
2
3
4
5
6
7
8
9
10
11
    ID      NAME
    20100	Tom
    35722	Mary
    78565	David
    37421	John
    55399	Kathy
    92167	Sue
    82367	Kim
    88391	Daniel
    99383	Ray
    25796	William


And this is what I have so far, It'll compile once you take out the getline part, what I tried to do there was get the data from each column and put it into an array, I failed :(

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// 11-13-10
// Assignment 4

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <cstdlib>
using namespace std;

double rand_float(double a, double b);

int main()
{
	unsigned int seed;
	const int NROWS=10;
	const int NCOLS=3;
	int size=0,i,grades=0,z,y,g,j,Highkids=0;
	double w=rand_float(100,0),mean;
	double grade=0;
    double power[NROWS][NCOLS],col_sum;
	string STRING,ID,NAME,id,S1,S2,S3;

    ifstream infile;
	infile.open("ClassRoster.dat");	
	while(!infile.eof)
        {
	        getline(infile,ID[10]); 
	        getline(inflie,NAME[10]);
			cout<<STRING<<setw(5)<<NAME;			
        }
	infile.close();
	
	
	ofstream EGR126Final;
	EGR126Final.open("EGR126Final.dat");
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(3);

	cout<<"Student grade generator:"<<endl<<endl;

	//Table with 2D array of values.
	
	cout<<"Enter a seed value for the grade generator: "<<endl;
	cin>>seed;
	srand(seed);

	cout<<endl;
	cout<<setw(4)<<"ID"<<setw(5)<<"NAME"<<setw(5)<<"GRADE"<<setw(5)<<"PASS/FAIL"<<endl;
	cout<<"-------------------------------------------------"<<endl;

	cout<<setw(4)<<id<<setw(5)<<name<<endl;

	for (z=0;z<NROWS;z++)
	{
		if (z<11)
		{
			cout<<endl;
			cout<<id<<'\t';
		}
		else
		{
			cout<<endl;
			cout<<id<<'\t';
		}

		 w=rand_float(0,100);
         if (w<=20)
         {
             for (k=0;k<60;k=k)
             {
                 grade=rand_float(100,0);
                 grade<<setw(4)<<setw(10)<<"Fail"<<endl; // Write data to file.
                 cout<<setw(4)<<setw(10)<<grade<<"Fail"<<endl; // Outputs the information to the screen
             }
         }
         else 
             {
             u=rand_float(100,0);
             grade<<setw(4)<<setw(10)<<endl; // Write data to file.
             cout<<setw(4)<<t<<setw(10)<<grade<<endl; // Outputs the information to the screen
             }     
  }
		
		}
	}
	cout<<endl;

	//Average power calculation & output
	col_sum=0;

	for (int j=0;j<NROWS;j++)
	{
		for (int g=0;g<NCOLS;g++)
		{
			col_sum +=power[j][g];
		}
	}
	mean=col_sum/(NCOLS*NROWS);
	cout<<endl<<"AVERAGE GRADE: "<<mean<<setw(5)<<"."<<endl<<endl;

	//Days with higher output:

	cout<<"STUDENTS WITH ABOVE-AVEARAGE GRADES: "<<endl<<endl;
	
	for (int j=0;j<NROWS;j++)
	{
		for (int k=0;k<NCOLS;k++)
		{
			if (mean<power[j][k])
			{
				Highkids++;
				cout<<left<<"ID "<<j+1<<" Name "<<k+1<<": "<<power[j][k]<<endl;
			}
		}
	}

	//Students with above-average grades.


	cout<<endl<<endl;
	
	//Number of days with higher output:
	cout<<"***There are "<<Highkids<<" total students with higher than average grades."<<endl<<endl;

	EGR126Final.close();
	system("pause");
	return 0;
}

double rand_float (double a, double b)
{
return ((double) rand() / RAND_MAX ) * (b - a) + a;
}


Any help, as always, would be immensely appreciated!


Last edited on
Topic archived. No new replies allowed.