Greetings!
I think that I have found my sort routine, yet I can't seem to get it to produce the desired results.
I am attempting to get my program to sort the information that it reads from another file, I can get the program to read and print the items yet when I attempt to sort them, I cannot get it to compile.
CODE
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
const char* bookName = "C:\\Documents and Settings\gradebook.txt";
const int columnWidth[4] = { 10, 24, 6, 7 };
const int maximumStudents = 100;
void readStudentRecord (istream& gradebook, int& studentId, string& firstName, string& lastName, int& entryCount);
void reportStudentInformation (ostream& report, int studentId, string firstName, string lastName);
void readGradeRecord (istream& gradebook, string& date, string& assignmentType, int& earnedScore, int& maximumScore);
void reportGradeInformation (ostream& report, string date, string assignmentType, int earnedScore, int maximumScore);
void reportGradeHeading (ostream& report);
float computeCurrentNumericGrade (int attendanceScore, int attendanceMaximum,
int homeworkScore, int homeworkMaximum,
int testScore, int testMaximum,
int projectScore, int projectMaximum);
void reportFinalGrades (ostream& report, int id[], string student[], float grade[], int studentCount);
int main(int argc, char *argv[])
void homeworkScore(double [],const double);
void testScore(double [],const double);
void projectScore(double [],const double);
void homeworkMaximum(double [],const double);
void testMaximum(double [],const double);
void projectMaximum(double [],const double);
void main()
{
const int size=5;
double testScore[size];
int count=0;
double testScore=0;
cout << "Test: " <<endl;
for (count=0;count<=size;count++)
{
cout << "Test: ";
cin >> testScore;
if (testScore == 0)
{
break;
}
if (testScore < 0)
{
while (testScore < 0)
{
cout << "Error";
cin >>;
if (testScore == 0)
{
break;
}
}
}
testScore[count] = testScore;
}
testMinimum(testScore,size);
homeworkMinimum(homeworkScore,size);
projectMinimum(projectScore,size);
}
void testScore (double testScore[],double size)
{
int count=0;
for (count=0;count<=size;count++)
{
cout << testScore[count] << " ";
}
}
void projectScore(double scores[],double size)
{
bool swap;
double temp;
int count=0;
do
{
swap = false;
for (int count=0; count <= size;count++)
{
if (projectScore[count] > projectMaximum[count+1])
{
temp = projectScore[count];
projectScore[count] = projectScore[count+1];
projectMaximum[count+1] = temp;
swap = true;
}
}
} while (swap==true);
cout << "Project: " <<endl;
for(count=0;count<=size;count++)
{
cout << projectScore[count] << " ";
}
}
void homeworkScore(double homeworkScore[],double size)
{
bool swap;
double temp;
int count=0;
do
{
swap = false;
for (int count=0; count <= size;count++)
{
if (homeworkScore[count] < homeworkMaximim[count+1])
{
temp = homeworkScore[count];
homeworkScore[count] = homrworkScore[count+1];
homeworkScore[count+1] = temp;
swap = true;
}
}
} while (swap==true);
cout << "Homework: " <<endl;
for(count=0;count<=size;count++)
{
cout << homeworkScore[count] << " ";
}
void attendenceScore(double attendenceMaximum[],double size)
{
double high=0,low=0;
int count=0;
high = scores[0];
low = scores[0];
for (count=1;count<=size;count++)
{
if(attendanceScore[count] > high)
{
high = attendanceScore[count];
}
}
for (count=1;count<=size;count++)
{
if(attendanceScore[count] < low)
{
low = attendanceScore[count];
}
}
cout << "\Attendance: " << high <<endl;
cout << "Attendance" << low <<endl;
}
void average(double scores[],double size)
{
double average=0,total=0;
int count=0;
for (count=0;count<=size;count++)
{
total = total + scores[count];
}
average = total / size;
cout << "The average score is" << average <<endl;
}
{
int studentId, entryCount;http://news.yahoo.com/s/livescience/20071213/sc_livescience/captainkiddshipfound
string firstName, lastName;
int currentStudent = 0;
int attendanceScore;
int attendanceMaximum;
int homeworkScore;
int homeworkMaximum;
int testScore;
int testMaximum;
int projectScore;
int projectMaximum;
int studentCount;
int studentIdList[maximumStudents];
float gradeList[maximumStudents];
string fullStudentNameList[maximumStudents];
ifstream theBook; // Create the input file stream.
// The is NOT bound to the file yet ...
theBook.open(bookName);
if (theBook)
{
while (!theBook.eof())
{
readStudentRecord (theBook, studentId, firstName, lastName, entryCount);
reportStudentInformation (cout, studentId, firstName, lastName);
reportGradeHeading (cout);
attendanceScore = attendanceMaximum = homeworkScore = homeworkMaximum =
testScore = testMaximum = projectScore = projectMaximum = 0;
int i = 0;
while (i < entryCount)
{
string date, assignmentType;
int earnedScore, maximumScore;
readGradeRecord(theBook, date, assignmentType, earnedScore, maximumScore);
reportGradeInformation (cout, date, assignmentType, earnedScore, maximumScore);
if (assignmentType == "attendance")
{
attendanceScore = attendanceScore + earnedScore;
attendanceMaximum = attendanceMaximum + maximumScore;
}
else if (assignmentType == "homework")
{
homeworkScore = homeworkScore + earnedScore;
homeworkMaximum = homeworkMaximum + maximumScore;
}
else if (assignmentType == "test")
{
testScore = testScore + earnedScore;
testMaximum = testMaximum + maximumScore;
}
else if (assignmentType == "project")
{
projectScore = projectScore + earnedScore;
projectMaximum = projectMaximum + maximumScore;
}
else
{
cerr << "Unrecognized assignment type encountered: " << assignmentType << endl;
}
i = i + 1;
}
cout << endl;
studentIdList[currentStudent] = studentId;
fullStudentNameList[currentStudent] = firstName + " " + lastName;
gradeList[currentStudent] = computeCurrentNumericGrade(attendanceScore, attendanceMaximum, homeworkScore, homeworkMaximum, testScore, testMaximum, projectScore, projectMaximum);
currentStudent++;
}
studentCount = currentStudent;
theBook.close();
reportFinalGrades (cout, studentIdList, fullStudentNameList, gradeList, studentCount);
}
else
{
cerr << "Could not open the input file: " << bookName << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
void readStudentRecord (istream& gradebook,
int& studentId,
string& firstName,
string& lastName,
int& entryCount)
{
// Assume the input stream is open ...
gradebook >> studentId >> firstName >> lastName >> entryCount;
}
void readGradeRecord (istream& gradebook,
string& date,
string& assignmentType,
int& earnedScore,
int& maximumScore)
{
gradebook >> date >> assignmentType >> earnedScore >> maximumScore;
}
My goal is to get the "score" and "maximum" grades for "test, homework, project and attendance" (streamed from another file), yet I seem to be muddling something.
Anny suggestions are appreciated!
~Admin Edit: Closed [/code] tag. Post your code like this: