Our program got cut down from a .h and 2 .cpps to just one .h and one .cpp.... so trying to convert fucntions back to my .h I received tons of errors. Hopefully someone can help me get rid of most of these? please? I need to turn in the final program in like 23 hours. :) Thanks if you can help or if you will. I am not asking anyone to do it... just steer me in the right direction if you see where i am going wrong.... My program is nasty. :cry: :(
Here is the main thing on my lab that I am working on with it too.... for where the structs and arrays come in:
An array of 10 structures of type aClass will make up the storage mechanism; i.e., you will process 10 students.
Heres my .h:
#include<iostream> // all the classes I could ever need for this program
#include<iomanip> // and a few extra just incase.
#include<cmath>
#include<cstdlib>
#include<string>
using namespace std;
enum aGrade {a, b, c, d, f, w, i};
struct aClass
{
string courses;
aGrade grades;
int hours;
float GP;
};
aClass mycourses;
void printHead () // this section will display the heading for the output table
{
cout<<"\n\nList of the Courses"<<endl<<"\n Class Hours Grade \n";
cout<<"-----------------------------------"<<endl;
}
aGrade convert(enum aGrade in, //OUT: in
aClass mycourses) //IN: grades
{
switch (mycourses.grades) //switch stmt to get all the letters into the enum catagories
{
case 'a':case 'A':
in = a;
break;
case 'b':case 'B':
in = b;
break;
case 'c':case 'C':
in = c;
break;
case 'd':case 'D':
in = d;
break;
case 'f':case 'F':
in = f;
break;
case 'w':case 'W':
in = w;
break;
case 'i':case 'I':
in = i;
break;
}
return in;
}
int calcGradePoint(enum aGrade in,
aClass mycourses) //This function is used to calculate the totalgpa for one class
{
if(in == a)
return 4 * mycourses.hours;
if(in == b)
return 3 * mycourses.hours;
if(in == c)
return 2 * mycourses.hours;
if(in == d)
return 1 * mycourses.hours;
if(in == f)
return 0 * mycourses.hours;
if(in == w)
return 0 * mycourses.hours;
if(in == i)
return 0 * mycourses.hours;
}
void sortClass (aClass mycourses) //IN: cnt
//This bubblesort is used to put the courses into alphabetical order
{
int i = cnt, j = 0, k = 1, temper;
string temp;
char tmp;
while (i >= 0 && k)
{
k = 0;
for (j = 0; j <= i; j++)
if (mycourses.courses[j] > mycourses.courses[j+1])
{
temp = mycourses.courses[j];
mycourses.courses[j] = mycourses.courses[j+1];
mycourses.courses[j+1] = temp;
temper = mycourses.hours[j];
mycourses.hours[j] = mycourses.hours[j+1];
mycourses.hours[j+1] = temper;
tmp = mycourses.grades[j];
mycourses.grades[j] = mycourses.grades[j+1];
mycourses.grades[j+1] = tmp;
k = 1;
}
i--;
}
}
float calcGPA(const float gpaSum, //IN: gpaSum
const float totalHours ) //IN: totalHours
//This function is used to calculate overall gpa = totalofgpa / totalhours
{
float gpa;
gpa = float (gpaSum / totalHours);
return gpa;
}
void printLine (cnt, b, aClass mycourses, gpa, totalHour)
{
for (int b = 1; b <= cnt; b++) //puts the information into the table
{
cout<<setw(12)<<mycourses.courses<<setw(9)<<mycourses.hours<<setw(10)<<mycourses.grades<<endl;
}
cout<<"\nThe total GPA is "<<gpa<<" and you attempted "<<totalHours<<" hours."<<endl;
}
and here is my .cpp
#include "schedule.h"
int main(){ //Calls main function
int cnt = 0; //Variables used
char gpaForOneClass;
float gpa = 0.0, totalHours = 0.0, gpaSum = 0.0;
aGrade in;
while (cnt < 10)
{
while (1)
{
cout<<"\nEnter a course, the letter grade received, and the credit hours. "<<endl;
cin >> mycourses.courses;
if (mycourses.courses == "quit" || mycourses.courses == "QUIT" || mycourses.courses == "Quit") break; //ends input when quit or QUIT is typed
cin >> mycourses.grades;
cin >> mycourses.hours;
in = convert(in, aClass mycourses); //converts letter input into right value
gpaForOneClass = calcGradePoint(in, aClass mycourses, cnt); //gets gpa total for one class
gpaSum += gpaForOneClass; //totals up gpa
totalHours = totalHours + mycourses.hours; //totals up hours
cnt = cnt + 1;
}
}
gpa = calcGPA(gpaSum, totalHours); //calls gpa function
printHead(); //calls header function to display table
sortClass(aClass mycourses, cnt); // calls bsort function
printLine(cnt, b, aClass mycourses, gpa, totalHours);
cin>>cnt;
return 0;
}
and here are the ridiculous amount errors i get:
15 C:\Documents and Settings\Josh\Desktop\Lab5\cs110lab5.cpp In file included from C:/Documents and Settings/Josh/Desktop/Lab5/cs110lab5.cpp
C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h In function `void sortClass(aClass)':
87 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h `cnt' undeclared (first use this function)
87 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h (Each undeclared identifier is reported only once for each function it appears
100 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h cannot convert `std::string' to `char' in assignment
102 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h invalid types `int[int]' for array subscript
103 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h invalid types `int[int]' for array subscript
103 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h invalid types `int[int]' for array subscript
104 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h invalid types `int[int]' for array subscript
106 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h invalid types `aGrade[int]' for array subscript
107 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h invalid types `aGrade[int]' for array subscript
107 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h invalid types `aGrade[int]' for array subscript
108 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h invalid types `aGrade[int]' for array subscript
/Documents and Settings/Josh/Desktop/Lab5/schedule.h C:\Documents and Settings\Josh\Desktop\Lab5\C At global scope:
129 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h syntax error before `,' token
C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h In function `void printLine(...)':
136 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h `gpa' undeclared (first use this function)
136 C:\Documents and Settings\Josh\Desktop\Lab5\schedule.h `totalHours' undeclared (first use this function)
C:\Documents and Settings\Josh\Desktop\Lab5\cs110lab5.cpp In function `int main()':
35 C:\Documents and Settings\Josh\Desktop\Lab5\cs110lab5.cpp no match
for 'operator>>' in 'std::cin >> mycourses.aClass::grades'
error C:\Dev-Cpp\include\c++\3.3.1\bits\istream.tcc:83 candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
92 C:\Dev-Cpp\include\c++\3.3.1\bits\istream.tcc std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
101 C:\Dev-Cpp\include\c++\3.3.1\bits\istream.tcc std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT,
That same error.... 19 more times then..
74 C:\Dev-Cpp\include\c++\3.3.1\iomanip std::basic_istream<_CharT, _Traits>&
that same error....4 more times
38 C:\Documents and Settings\Josh\Desktop\Lab5\cs110lab5.cpp syntax error before `)' token
39 C:\Documents and Settings\Josh\Desktop\Lab5\cs110lab5.cpp syntax error before `,' token
50 C:\Documents and Settings\Josh\Desktop\Lab5\cs110lab5.cpp syntax error before `,' token
51 C:\Documents and Settings\Josh\Desktop\Lab5\cs110lab5.cpp syntax error before `,' token