The assignment is to read and keep records and perform statistical analysis for a class of students.
This is what I have done so far,then the codes can show the information(Id,4quizes,exam) of each students on screen. But I need to show 3 more things (The Highest ,The Lowest,The Average of each quiz and exam ).
How can I get those ? I can't go ahead. Could anyone have an idea?

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

#include "Student.h"

int main()
{
    Student stuArray[50];
    int stuQuiz[4];
    int i;
    int numStudents = 0;
    int idIn;
    int quizIn[4];
    int examIn;

    ifstream inFile("page595data.txt");
    if(!inFile.is_open())
    {
        cerr << "Could not open input file. Terminating program." << endl;
        system("pause");
        exit(100);
    }    

    while(!inFile.eof())
    {
        inFile >> idIn;
        for( i = 0; i < 4; i++)
           inFile >> quizIn[i];
        inFile >> examIn;
        if(!inFile.eof())
        {
           stuArray[numStudents] = Student(idIn, quizIn, examIn);

           numStudents++ ;
        }    
    } // while


    cout << setw(8) << "ID" << setw(8) << "Quiz 1" << setw(8) << "Quiz 2" ;
    cout << setw(8) << "Quiz 3" << setw(8) << "Quiz 4" <<setw(8)<< "Exam"   << endl ; 
    for(i=0; i < numStudents; i++)
        stuArray[i].printStudent();



    cout << setw(8) << "High" << endl;
    cout << setw(8) << "Low"  << endl;
    cout << setw(8) << "Average" << endl;;  
    system("pause");
    return 0;
} // main
--------------------------------------------------
class Student
{
    private:
        int id;
        int quiz[4];
        int exam;
    public:
            Student();
            Student(int idIn,int quizIn[],int examIn);
        void getStudent(int& idOut, int quizOut[], int& examOut);
        void printStudent();

}; // Student 
----------------------------------------- 
#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
#include "Student.h"
Student :: Student ()
{

        }
Student :: Student(int idIn,int quizIn[],int examIn)
{
       id  = idIn      ;
   quiz[0] = quizIn [0];
   quiz[1] = quizIn [1];
   quiz[2] = quizIn [2];
   quiz[3] = quizIn [3];
      exam = examIn    ;
   }

void Student :: printStudent()
{
 cout << setw(8) << id << setw(8) << quiz[3] << setw(8) << quiz[1] ; 
 cout <<  setw(8) << quiz[2] <<  setw(8) << quiz [3] << setw(8) <<  exam << endl;
 }

It looks weird , but it worked so far.

Recommended Answers

All 7 Replies

To find the largest value in a list, save the first value and walk through the list, saving the largest:

T largest = list[0];
for (int i = 1; i < list.size(); i++) {
  if (list[i] > largest)
    largest = list[i];
}
cout<<"The largest value is "<< largest <<endl;

To find the smallest, just reverse the test:

T smallest = list[0];
for (int i = 1; i < list.size(); i++) {
  if (list[i] < smallest)
    smallest = list[i];
}
cout<<"The smallest value is "<< smallest <<endl;

To find the average of all values in a list, sum them and then divide by how many items there were:

T sum = 0;
for (int i = 0; i < list.size(); i++)
  sum += list[i];
cout<<"The average is "<< sum / list.size() <<endl;

Thanks for trying. But my queestion was little bit unclear.
I will put the txt file and out put that I get so far.

txt file out put
1234 052 007 100 078 034 Id Quiz1 Quiz2 Quiz3 Quiz4 Exam
2134 090 036 090 077 030 1234 52 7 100 78 34
3124 100 045 020 090 070 2134 90 36 90 77 30
4532 011 017 081 032 077 3124 100 45 20 90 70
5678 020 012 045 078 034 4532 11 17 81 32 77
6134 034 080 055 078 045 :
7874 060 100 056 078 078 :
8026 070 010 066 078 056 :
9893 034 009 077 078 020 :
1947 045 040 088 078 055 :
2877 055 050 099 078 080 :
3189 082 080 100 078 077 Highest
4602 089 050 091 078 060 Lowest
5405 011 011 000 078 010 Average
6999 000 098 089 078 020

What I need know is how I can get The highest and the lowest and The average of each. How can I add quiz1 in 1st student to quiz1 in 2nd student ? How can I compare them?

Code tags will preserve the spacing.

Thanks for trying. But my queestion was little bit unclear.
I will put the txt file and out put that I get so far.

txt file                               out put 
1234 052 007 100 078 034     Id      Quiz1  Quiz2  Quiz3  Quiz4  Exam
2134 090 036 090 077 030   1234        52        7     100     78     34
3124 100 045 020 090 070   2134        90      36       90     77     30
4532 011 017 081 032 077   3124       100      45       20     90     70
5678 020 012 045 078 034   4532         11      17       81     32     77
6134 034 080 055 078 045                              :
7874 060 100 056 078 078                              :
8026 070 010 066 078 056                              :
9893 034 009 077 078 020                              :
1947 045 040 088 078 055                              :
2877 055 050 099 078 080                              :
3189 082 080 100 078 077    Highest    
4602 089 050 091 078 060    Lowest
5405 011 011 000 078 010    Average
6999 000 098 089 078 020

What I need know is how I can get The highest and the lowest and The average of each. How can I add quiz1 in 1st student to quiz1 in 2nd student ? How can I compare them?

Thanks for trying. But my queestion was little bit unclear.
I will put the txt file and out put that I get so far.

txt file out put
1234 052 007 100 078 034 Id Quiz1 Quiz2 Quiz3 Quiz4 Exam
2134 090 036 090 077 030 1234 52 7 100 78 34
3124 100 045 020 090 070 2134 90 36 90 77 30
4532 011 017 081 032 077 3124 100 45 20 90 70
5678 020 012 045 078 034 4532 11 17 81 32 77
6134 034 080 055 078 045 :
7874 060 100 056 078 078 :
8026 070 010 066 078 056 :
9893 034 009 077 078 020 :
1947 045 040 088 078 055 :
2877 055 050 099 078 080 :
3189 082 080 100 078 077 Highest
4602 089 050 091 078 060 Lowest
5405 011 011 000 078 010 Average
6999 000 098 089 078 020

What I need know is how I can get The highest and the lowest and The average of each. How can I add quiz1 in 1st student to quiz1 in 2nd student ? How can I compare them?

If your text file would look something like this

1234 052 007 100 078 034
2134 090 036 090 077 030
3124 100 045 020 090 070
4532 011 017 081 032 077
5678 020 012 045 078 034
6134 034 080 055 078 045
7874 060 100 056 078 078
8026 070 010 066 078 056
9893 034 009 077 078 020
1947 045 040 088 078 055
2877 055 050 099 078 080
3189 082 080 100 078 077
4602 089 050 091 078 060
5405 011 011 000 078 010
6999 000 098 089 078 020

then you could read it into a list or array of structures with
the fields of Id Quiz1 Quiz2 Quiz3 Quiz4 Exam
using fscanf() or whatever ...

>But my queestion was little bit unclear.
Your question was clear enough, and the answer is the same. If it turns out that your question is actually how to read a text file so that you can easily store the results of each quiz in a list, that's a different story.

I got it done well!! Thank you all for trying to help me out !! I can't thank you guys enough.

You guys made me figure out that I had to study more about programming.
I will see you around!!

Thanks again.

Tenoran.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.