Overclock.net - An Overclocking Community - View Single Post - We lost our programming virginity
View Single Post
post #172 of (permalink) Old 11-09-2009, 12:28 AM - Thread Starter
TheGrayNobleman
New to Overclock.net
 
TheGrayNobleman's Avatar
 
Join Date: Jun 2007
Location: Cali
Posts: 1,243
Rep: 111 (Unique: 104)
Anyone got any suggestions for my code?

It is a grading app that takes information from a file and reads it.
Input file
Code:
3 
1000  9.5  9.0  8.5  87.0  92.5  86.0 
2000 10.0  10.0 10.0 100.0 100.0 100.0 
3000  8.0  8.0  8.0  80.0  80.0  79.0
App
Code:
#include <iostream>
#include <fstream>
using namespace std;

int main ()
{
// Two file stream objects for input and output.
ifstream in_file;
ofstream out_file;

//Student and test numbers
int students_num, id;
double exam1, exam2, exam3, midterm1, midterm2, final, average;
int highperson = 0;
double highscore = 0;


//Decimal Fixs
cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2); 

out_file.setf(ios::fixed);
out_file.setf(ios::showpoint);
out_file.precision(2);

//File input
char file_name[80];
cout<< "Enter an input file name: ";
cin>> file_name;
in_file.open(file_name);

//in_file.open("C:\\\\Temp\\\\score.txt");
out_file.open("C:\\\\Temp\\\\Student_Grades.txt");

//File errors
if (in_file.fail()) {
    cout << "Error: input file open failed.\
";
    exit (1);
}

if (out_file.fail()) {
    cout << "Error: output file open failed.\
";
    exit (1);
}

// Get the number of students.
in_file >> students_num;

cout << "--------------------------------------------------------" << endl
<< "Course Report" << endl
<< "--------------------------------------------------------" << endl;

out_file << "--------------------------------------------------------" << endl
<< "Course Report" << endl
<< "--------------------------------------------------------" << endl;

//Average and grade loop
for(int i=0; i < students_num; i++) {
        in_file >> id >> exam1 >> exam2 >> exam3 >> midterm1 >> midterm2 >> final;
    
//Calculate average
double exam, midterm;
exam = (exam1*10+exam2*10+exam3*10)/3;
midterm = (midterm1+midterm2)/2;
average = (exam*.2)+(midterm*.4)+(final*.4);

    // Display the id and average
    cout << id << ' ' << average;

    // Output the id and average to the output data file.
    out_file << id << ' ' << average;

//Letter grade
char grade;

if (average > 89){
grade = 'A';
}
else if (average > 79){
grade = 'B';
}
else if (average > 69){
grade = 'C';
}
else if (average > 59){
grade = 'D';
}
else {
grade = 'F';
}

//Output grade
cout << " " << grade << endl;
out_file << " " << grade << endl;

//Finds highest grade
if (average > highscore){
highscore = average;
highperson = id;
}
else{
cout << "";
}
} //End for()

cout << "--------------------------------------------------------" << endl;
out_file << "--------------------------------------------------------" << endl;

//High score display
cout << endl << "*** The highest scoring student is " << highperson << "! (Average = " << highscore << ") ***" << endl << endl;
out_file << endl << "*** The highest scoring student is " << highperson << "! (Average = " << highscore << ") ***" << endl << endl;

//Close files
in_file.close();
out_file.close();

//Break
return 0;

} //End main()

Quote:
Originally Posted by Syrillian go_quote.gif
The inherent and insurmountable shortcoming is that the entire framework of human understanding is steeped in finite terms. Everything has a beginning, everything has an end.... we simply can not fathom anything before or after.

Infinite is not necessarily a word, it is more of a sound that has a connotation or a theory, as by definition... we can not define it.

Infinite Time and infinite Space. Attempting to define them is not only ironic, it is an act of futility.
TheGrayNobleman is offline