-
Classes
I have a class called final it inherits attributes from a class called average. I am using constructor for the class. I am not to familiar with constructors but I know it initializes data members when it is instantiated. I am reading records from a file in a Do loop and it seems I must Declare this variable (Final FGrade(int[][], int[], int) in the loop to get the program to work right(it works if it is outside the loop but it keeps processing the first record). Am I doing something wrong? One last thing I use a member function after the loop and try to use FGrade (FGrade.RoundNum(int,2)) it says it is undeclared and I have to call the variable again. Would someone tell me if I am missing something or is this the way it is supposed to work. I mean the program is working it just seems to me that at the very least when I use it after the loop that I shouldn't have to declare the variable again.
-
Hard to tell what is going on or if you are using the ctor right. Post some of your code so we can see what is going on and know better how to help you.
-
main function for class
Here is most of my main function. Thanks in advance
//read a record
fscanf(StuIn,"%5d,%25[a-z A-Z],"
"%3[a-z],%2[abcdf+-],%2[abcdf+-],%2[abcdf+-],%2[abcdf+-],%2[abcdf+-],%2[abcdf+-],"
"%2[abcdf+-],%2[abcdf+-],%3d,%3d,%3d,%3d,%3s"
,&StuNum, Name, CurCode, C[0], C[1], C[2], C[3], C[4], C[5], C[6], C[7],
&T[0], &T[1], &T[2], &T[3], F);
//Print Headings
fprintf(GReport, "%60s\n\n", "Grade Report"),
fprintf(GReport,"%-7s %-26s %4s%19s%26s%13s%8s%7s\n"
, "Student", "Student", "Curr", "Class", "Test", "Final","Final", "Final");
fprintf(GReport,"%-7s %-26s %4s%19s%26s%13s%8s%7s\n"
, "Number", "Name", "Code", "Grades", "Grades", "Test","Avg", "Grade");
fprintf(GReport,"%-7s %-26s %4s %30s%18s%8s%8s%7s\n"
, "-------", "-------------------------", "----",
"-----------------------------", "--------------", "-----","-----", "-----");
do
{
//capitalize the first letter of the first and last name
Name[0] = toupper(Name[0]);
for(int cnt = 1; cnt < NameSize; cnt++)
if(Name[cnt] == ' ')
{
Name[cnt + 1] = toupper(Name[cnt + 1]);
break;
}
//capitalize the curriculum code
for(int cnt1 = 0; cnt1 < CurSize; cnt1 ++)
CurCode[cnt1] = toupper(CurCode[cnt1]);
//average is declared here so the variables being passed to the class are
//refreshed each time a new record is read
Final FGrade(F, C, T, TestSize);
//call class function to calculate the final grade
FinalGrade = FGrade.CalcFinal();
//convert the final grade to a letter grade
LetterFinal = ConvertFinGrade(FinalGrade);
//write a detail line to the backup file
fprintf(StuSave,"%d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, %d,%d,%d,%d,%s,%d,%c\n"
, StuNum, Name, CurCode, C[0], C[1], C[2], C[3], C[4], C[5],
C[6], C[7], T[0], T[1], T[2], T[3], F,FinalGrade, LetterFinal);
//write a line to the report file
fprintf(GReport,"%-5d %-26s %-3s %-3s%-4s%-4s%-4s%-4s%-4s%-4s%-4s%4d%4d%4d%4d%7s%8d%6c%\n"
, StuNum, Name, CurCode, C[0], C[1], C[2], C[3], C[4], C[5],
C[6], C[7], T[0], T[1], T[2], T[3], F, FinalGrade, LetterFinal);
StuCounter++; //StuCounter = Total # of student
FinGradeCntr +=FinalGrade; //Accumulate final grades
}
//read records until EOF
while((fscanf(StuIn,"%5d,%25[a-z A-Z],"
"%3[a-z],%2[abcdf+-],%2[abcdf+-],%2[abcdf+-],%2[abcdf+-],%2[abcdf+-],%2[abcdf+-],"
"%2[abcdf+-],%2[abcdf+-],%3d,%3d,%3d,%3d,%3s"
,&StuNum, Name, CurCode, C[0], C[1], C[2], C[3], C[4], C[5], C[6], C[7],
&T[0], &T[1], &T[2], &T[3], F)) ==16);