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;
}
|