| | |
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:
Solved Threads: 0
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.
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.
To find the largest value in a list, save the first value and walk through the list, saving the largest:
To find the smallest, just reverse the test:
To find the average of all values in a list, sum them and then divide by how many items there were:
C++ Syntax (Toggle Plain Text)
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;
C++ Syntax (Toggle Plain Text)
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;
C++ Syntax (Toggle Plain Text)
T sum = 0; for (int i = 0; i < list.size(); i++) sum += list[i]; cout<<"The average is "<< sum / list.size() <<endl;
I'm here to prove you wrong.
•
•
Join Date: Mar 2005
Posts: 9
Reputation:
Solved Threads: 0
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?
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.
•
•
•
•
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.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?C++ Syntax (Toggle Plain Text)
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
"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
•
•
•
•
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?
•
•
•
•
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
the fields of Id Quiz1 Quiz2 Quiz3 Quiz4 Exam
using fscanf() or whatever ...
May 'the Google' be with you!
![]() |
Similar Threads
- how to find highest and lowest number.. (C++)
- Highest and Lowest (C++)
- calculating sum, average, highest and lowest grades (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: how do I do this? 1 = ' is on the x-axis'; (C++)
- Next Thread: c++ SQLServer ODBC errors
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






