How can I get Highest, Lowest and Average ?

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2005
Posts: 9
Reputation: tenoran is an unknown quantity at this point 
Solved Threads: 0
tenoran tenoran is offline Offline
Newbie Poster

How can I get Highest, Lowest and Average ?

 
0
  #1
Mar 2nd, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,674
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: How can I get Highest, Lowest and Average ?

 
0
  #2
Mar 2nd, 2005
To find the largest value in a list, save the first value and walk through the list, saving the largest:
  1. T largest = list[0];
  2. for (int i = 1; i < list.size(); i++) {
  3. if (list[i] > largest)
  4. largest = list[i];
  5. }
  6. cout<<"The largest value is "<< largest <<endl;
To find the smallest, just reverse the test:
  1. T smallest = list[0];
  2. for (int i = 1; i < list.size(); i++) {
  3. if (list[i] < smallest)
  4. smallest = list[i];
  5. }
  6. 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:
  1. T sum = 0;
  2. for (int i = 0; i < list.size(); i++)
  3. sum += list[i];
  4. cout<<"The average is "<< sum / list.size() <<endl;
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,025
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 932
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: How can I get Highest, Lowest and Average ?

 
0
  #3
Mar 2nd, 2005
Take a look at:
http://www.daniweb.com/code/snippet139.html

It might just give you an idea.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 9
Reputation: tenoran is an unknown quantity at this point 
Solved Threads: 0
tenoran tenoran is offline Offline
Newbie Poster

Re: How can I get Highest, Lowest and Average ?

 
0
  #4
Mar 2nd, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,362
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 241
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: How can I get Highest, Lowest and Average ?

 
0
  #5
Mar 2nd, 2005
Code tags will preserve the spacing.
Originally Posted by tenoran
Thanks for trying. But my queestion was little bit unclear.
I will put the txt file and out put that I get so far.
  1. txt file out put
  2. 1234 052 007 100 078 034 Id Quiz1 Quiz2 Quiz3 Quiz4 Exam
  3. 2134 090 036 090 077 030 1234 52 7 100 78 34
  4. 3124 100 045 020 090 070 2134 90 36 90 77 30
  5. 4532 011 017 081 032 077 3124 100 45 20 90 70
  6. 5678 020 012 045 078 034 4532 11 17 81 32 77
  7. 6134 034 080 055 078 045 :
  8. 7874 060 100 056 078 078 :
  9. 8026 070 010 066 078 056 :
  10. 9893 034 009 077 078 020 :
  11. 1947 045 040 088 078 055 :
  12. 2877 055 050 099 078 080 :
  13. 3189 082 080 100 078 077 Highest
  14. 4602 089 050 091 078 060 Lowest
  15. 5405 011 011 000 078 010 Average
  16. 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?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,025
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 932
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: How can I get Highest, Lowest and Average ?

 
0
  #6
Mar 2nd, 2005
Originally Posted by tenoran
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 ...
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,674
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: How can I get Highest, Lowest and Average ?

 
0
  #7
Mar 2nd, 2005
>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'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 9
Reputation: tenoran is an unknown quantity at this point 
Solved Threads: 0
tenoran tenoran is offline Offline
Newbie Poster

Re: How can I get Highest, Lowest and Average ?

 
0
  #8
Mar 3rd, 2005
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC