Guest_imported
New member
- Jan 1, 1970
- 0
I have the following program and it's not working. I worte the code all in void main() at first, then I broke it up into different functions. I dont know if i'm not passing the arguments correctly or what, but it's not working. The code reads in the following data file
CPSC 230 01
SPRING 01
6
able 90 90
baker 80 80
charlie 70 70
delta 60 60
fox 59 59
echo 0 0
and outputs the information in corresponding HTML code. It takes the two grades (i.e. 90 90; 80 80) and calculates the average, and returns a letter grade (i.e. 'A', 'B') My code follows below...
********
#include <iostream>
#include <fstream>
#include <string>
using std::ifstream;
using std:fstream;
using namespace std;
// FUNCTION PROTOTYPES
void read_in(ifstream in, char course[13], char semester[10], int numstudents, int gradecalc, int midterm, int final, char grade, char student);
char grade_calc(int gradecalc, char grade);
void output(ifstream in, ofstream out, char course [13], char semester[10], char student[128], int midterm, int final, char grade);
void main()
{
ifstream in("c:\\info.txt"
ofstream out("output.txt"
char student[128];
char course[13];
char semester[10];
int numstudents;
char grade;
int gradecalc;
int midterm, final;
read_in(in, course, semester, numstudents, gradecalc,
midterm, final, grade, student[128]);
output(in, out, course, semester, student, midterm, final, grade);
}
void read_in(ifstream in, char course[13], char semester[10], int numstudents, int gradecalc, int midterm, int final, int grade, char student[128])
{
in.getline(course,13);
in.getline(semester, 10);
in >> numstudents;
int i=0;
while (i < numstudents){
in >> student;
in >> midterm >> final;
gradecalc = (midterm + final) /2;
grade_calc(gradecalc, grade);
i++;}
}
char grad_calc(int gradecalc, char grade)
{
if(gradecalc >=90)
grade = 'A';
if((gradecalc >=80) && (gradecalc <90))
grade = 'B';
if((gradecalc >=70) && (gradecalc <80))
grade = 'C';
if((gradecalc >= 60) && (gradecalc <70))
grade = 'D';
if(gradecalc <60)
grade = 'F';
return grade;
}
void output(ifstream in, ofstream out, char course[13], char semester[10], char student[128], int midterm, int final, char grade, int numstudents)
{
out << "<HTML>\n" << " <TITLE>" << "GRADE INFORMATION" << "</TITLE>\n"
<< "<BODY>\n" << " <H1>" << course << ", " << semester << "</H1>\n"
<< " <TABLE BORDER=1>\n";
int i =0;
while (i < numstudents)
{
out << " <TR>\n";
out << " <TD>" << student << "</TD><TD>" << midterm << "</TD><TD>" << final
<< "</TD><TD>" << grade << "</TD>\n" << " </TR>\n";
}
}
CPSC 230 01
SPRING 01
6
able 90 90
baker 80 80
charlie 70 70
delta 60 60
fox 59 59
echo 0 0
and outputs the information in corresponding HTML code. It takes the two grades (i.e. 90 90; 80 80) and calculates the average, and returns a letter grade (i.e. 'A', 'B') My code follows below...
********
#include <iostream>
#include <fstream>
#include <string>
using std::ifstream;
using std:fstream;
using namespace std;
// FUNCTION PROTOTYPES
void read_in(ifstream in, char course[13], char semester[10], int numstudents, int gradecalc, int midterm, int final, char grade, char student);
char grade_calc(int gradecalc, char grade);
void output(ifstream in, ofstream out, char course [13], char semester[10], char student[128], int midterm, int final, char grade);
void main()
{
ifstream in("c:\\info.txt"
ofstream out("output.txt"
char student[128];
char course[13];
char semester[10];
int numstudents;
char grade;
int gradecalc;
int midterm, final;
read_in(in, course, semester, numstudents, gradecalc,
midterm, final, grade, student[128]);
output(in, out, course, semester, student, midterm, final, grade);
}
void read_in(ifstream in, char course[13], char semester[10], int numstudents, int gradecalc, int midterm, int final, int grade, char student[128])
{
in.getline(course,13);
in.getline(semester, 10);
in >> numstudents;
int i=0;
while (i < numstudents){
in >> student;
in >> midterm >> final;
gradecalc = (midterm + final) /2;
grade_calc(gradecalc, grade);
i++;}
}
char grad_calc(int gradecalc, char grade)
{
if(gradecalc >=90)
grade = 'A';
if((gradecalc >=80) && (gradecalc <90))
grade = 'B';
if((gradecalc >=70) && (gradecalc <80))
grade = 'C';
if((gradecalc >= 60) && (gradecalc <70))
grade = 'D';
if(gradecalc <60)
grade = 'F';
return grade;
}
void output(ifstream in, ofstream out, char course[13], char semester[10], char student[128], int midterm, int final, char grade, int numstudents)
{
out << "<HTML>\n" << " <TITLE>" << "GRADE INFORMATION" << "</TITLE>\n"
<< "<BODY>\n" << " <H1>" << course << ", " << semester << "</H1>\n"
<< " <TABLE BORDER=1>\n";
int i =0;
while (i < numstudents)
{
out << " <TR>\n";
out << " <TD>" << student << "</TD><TD>" << midterm << "</TD><TD>" << final
<< "</TD><TD>" << grade << "</TD>\n" << " </TR>\n";
}
}