Using c arrays I need help with this program write a program
Using c++ (arrays)
I need help with this program:
write a program to keep records and print statistical analysis for a class of students. There are three quizzes for each student during the term. Each student is identified by a four-digit student ID number. The number of students in the class is unknown. However; the last ID number is 0000(According with data given there are 22 students). The file pr2data.txt is included and contains the data. The program calculates the statistics for each student and for each quiz as shown in the sample output. The output goes to a file and is in the same order as the input.
This is the data given:
pr2data.txt
1234 52 70 75
2134 90 76 90
3124 90 95 98
4532 21 17 81
5678 20 22 45
6134 34 45 55
7874 60 99 56
8026 70 10 66
9893 34 09 77
2233 78 20 78
1947 45 40 88
3456 78 55 78
2877 55 50 95
3189 70 98 78
2132 77 97 80
4602 89 50 91
3445 78 60 78
5405 35 33 15
4556 78 20 18
6999 88 98 89
9898 48 78 68
2323 78 20 78
0000
AND this is an example of how should be the output:
Student Quiz 1 Quiz 2 Quiz 3 Average
1234 78 83 87 82.67
2134 67 77 84 76.00
3124 77 89 93 86.33
High score 78 89 93
Low score 67 77 84
Quiz Average 73.4 83.0 88.2
These are my codes:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
const int size = 20;
typedef int student[size];
typedef int quiz1[size];
typedef int quiz2[size];
typedef int quiz3[size];
typedef float stavg[size];
typedef float qzavg[size];
void getdata(ifstream &,student, quiz1, quiz2, quiz3);
void findstavg (quiz1, quiz2, quiz3, stavg/*, int*/);
/*void findhigh();
void findlow();
void findqzavg();*/
void printall(ofstream &, student, quiz1, quiz2, quiz3, stavg/*, int*/);
int main()
{ ifstream infile(\"pr2data.txt\");
ofstream outfile;
outfile.open(\"pr3output.txt\");
student id;
quiz1 q1;
quiz2 q2;
quiz3 q3;
stavg savg;
/*int n=0;*/
if(!infile)
{
cout<<\"Unable to open the file.\"< }
else
{
getdata(infile,id,q1,q2,q3);
findstavg(q1, q2, q3, savg/*, n*/);
/*findhigh();
findlow();
findqzavg();*/
printall(outfile, id, q1, q2, q3, savg/*, n*/);
}
return 0;
}
void findstavg(quiz1 q1, quiz2 q2, quiz3 q3, stavg savg/*, int n*/)
{
for(int i = 0; i < size; i++)
savg[i] = (q1[i] + q2[i] + q3[i]) / 3.0;
}
/*int findlow(int array[], int n)
{
int low = array[0];
for(int i = 1; i < n; i++)
if(array[i] < low)
low = array[i];
return low;
}
int findhigh(int array[], int n)
{
int high = array[0];
for(int i = 1; i < n; i++)
if(array[i] > high)
high = array[i];
return high;
}
double findqzavg(int quiz[], int n)
{
double sum = 0.0;
for(int i = 0; i < n; i++)
sum += quiz[i];
return sum / n;
}
*/
void getdata(ifstream &fin, student id, quiz1 q1, quiz2 q2, quiz3 q3)
{
for(int i = 0; i < size; i++)
{
fin>>id[i]>>q1[i]>>q2[i]>>q3[i];
}
}
void printall(ofstream &fout, student id, quiz1 q1, quiz2 q2, quiz3 q3, stavg savg/*, int n*/)
{
for(int i = 0; i < size; i++)
{
fout<<\"student\"<
}
}//< //fout<<\"Low Score : \"< //fout<<\"Quiz Average: \"< //}
AND MY OUTPUT IS:
pr3output.txt
student1234 quiz1 52 quiz2 70 quiz3 75 average 65.67
student2134 quiz1 90 quiz2 76 quiz3 90 average 85.33
student3124 quiz1 90 quiz2 95 quiz3 98 average 94.33
student4532 quiz1 21 quiz2 17 quiz3 81 average 39.67
student5678 quiz1 20 quiz2 22 quiz3 45 average 29.00
student6134 quiz1 34 quiz2 45 quiz3 55 average 44.67
student7874 quiz1 60 quiz2 99 quiz3 56 average 71.67
student8026 quiz1 70 quiz2 10 quiz3 66 average 48.67
student9893 quiz1 34 quiz2 9 quiz3 77 average 40.00
student2233 quiz1 78 quiz2 20 quiz3 78 average 58.67
student1947 quiz1 45 quiz2 40 quiz3 88 average 57.67
student3456 quiz1 78 quiz2 55 quiz3 78 average 70.33
student2877 quiz1 55 quiz2 50 quiz3 95 average 66.67
student3189 quiz1 70 quiz2 98 quiz3 78 average 82.00
student2132 quiz1 77 quiz2 97 quiz3 80 average 84.67
student4602 quiz1 89 quiz2 50 quiz3 91 average 76.67
student3445 quiz1 78 quiz2 60 quiz3 78 average 72.00
student5405 quiz1 35 quiz2 33 quiz3 15 average 27.67
student4556 quiz1 78 quiz2 20 quiz3 18 average 38.67
student6999 quiz1 88 quiz2 98 quiz3 89 average 91.67
However I NEED some help in the folowing funtions to get the highest, lowest and average quiz (please look above how has to to be the output):
function findhigh () returns the highest quiz.
findlow () returns the lowest quiz.
findqzavg () returns the quiz average.
Solution
Class 1
import java.io.*;
import java.util.StringTokenizer;
public class ReadSource
{
//Example references
//ReadSource.java -- shows how to work with readLine and FileReader
//How do you tokenize a String
//How to convert a String to an Integer
//int x = Integer.parseInt(String) ;
//Putting it altogether:
public static void main(String [] args)
{
/************************
* IF STUDENTS > 40
* PRINT \"TOO MANY RECORDS\"
* AND QUIT PROGRAM
************************/
Student lab6 [] = new Student[40];
//Populate the student array
if (lab6.length > 40)
{
System.out.println(\"Too Many Records\");
}
lab6 = Util.readFile(\"Data.txt\", lab6);
Statistics statlab6 = new Statistics();
statlab6.findlow(lab6);
//add calls to findhigh and find average
//Print the data and statistics
StringTokenizer st = new StringTokenizer(\"this is a test\");
while (st.hasMoreTokens())
{
System.out.println(st.nextToken());
}
}
}
Class 2
import java.io.*;
public class Student
{
private int SID; //Student ID
private Integer scores[] = new Integer[5];
public int getSID() {
return SID;
}
public void setSID(int SID) {
this.SID = SID;
}
public Integer[] getScores() {
return scores;
}
public void setScores(Integer[] scores) {
this.scores = scores;
}
//add methods to print values of instance variables.
public String Print()
{
Student [] students = new Student[5];
for (int i = 0; i < students.length; i++)
{
return (\"SID: \" + this.SID + \"Scores\" + this.scores);
}
return (\"SID: \" + this.SID + \"Scores\" + this.scores);
}
}
Class 3
package Lab6;
import java.io.*;
import corejava.*;
public class Util
{
public static Student [] readFile(String filename, Student [] stu)throws Exception
{
/* - Reads the file and builds student array.
- Open the file using FileReader Object.
- In a loop read a line using readLine method.
- Tokenize each line using StringTokenizer Object
- Each token is converted from String to Integer using parseInt method
- Value is then saved in the right property of Student Object.
*/
String x;
FileReader fr = new FileReader(\"Data.txt\");
BufferedReader br = new BufferedReader(fr);
while ((x = br.readLine())!= null)
{
System.out.println(x);
}
fr.close();
return stu;
}
Student a1[][] = new Student [40][6]; //array of object references
//if numofrows > 40 exit with an error message else compute statistics
/* if number of rows < 40
* a1[] = new Student (...........);
* where i < 40
*/
public static void read()
{
}
}




