i have win xp home edition... and my compiler is dev-C++ although i dont think its a compiler issue....
This is my project needs: (my attempted code follows)
(
Write a main function with all required internal functions subprograms (defined later) that tracks your college classes, grades and GPA. Sample I/O is shown below. Your lab instructor will give you final data to run.
Input: Engl325 C 2 (class, grade, hours)
Chem111 B 4
CS110 A 4
Phys115 D 4
Stat215 F 3
Phil201 W 0
QUIT or quit
Output: List of My Courses
Class Hours Grade GP
Chem111 4 B 12
CS110 4 A 16
Engl325 2 C 6
Phil201 3 W 0
Phys115 4 D 4
Stat215 3 F 0
Total 20 38 GPA = 2.23
Rules:
1. You must define an enum type to handle all grades (A,B,C,D,F,W,I). Each grade is input as a char, then you must change the char via a switch-stmt to your enum type.
2. Your main function must contain the following subprograms:
accepts return stmt? Out or InOut?
hours and grade for 1 course GP
hours, GP (2 arrays) GPA
3 arrays: sorts ascending on Class name all 3 arrays
prints heading void
skips to next line; print 1 line of table void
3. Use cin to input each class, grade, and hours, 3 items per line.
4. Sort the classes in ascending order for strings: CS110 < Engl325 < Phys115, etc.
Your lab instructor will talk about sorting on array.
5. Make your program stop when either quit or QUIT is entered as a class.
)
and here is my attempt at it....
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<string>
using namespace std;
enum gradevalue {a, b, c, d, e, f, w, i};
void header ()
{
cout<<"\nList of the Courses"<<endl<<"\n Class Hours Grade \n";
}
gradevalue convert(gradevalue& in, char grades)
{
switch (grades)
{
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 grade(gradevalue in, int hours )
{
if(in == a)
return 4 * hours;
if(in == b)
return 3 * hours;
if(in == c)
return 2 * hours;
if(in == d)
return 1 * hours;
if(in == f)
return 0 * hours;
if(in == w)
return 0 * hours;
if(in == i)
return 0 * hours;
}
void op_grade(gradevalue in)
{
if(in == a)
cout<<"A";
if(in == b)
cout<<"B";
if(in == c)
cout<<"C";
if(in == d)
cout<<"D";
if(in == f)
cout<<"F";
if(in == w)
cout<<"W";
if(in == i)
cout<<"I";
}
void bsort(int arrayC[], int c)
{
int temp = 0, i = 0, j = 0;
for (i = 1; i < c; i++);
{
for (j = 0; j < c - 1; j++);
{
if (arrayC[j] > arrayC[i])
{
temp = arrayC[j+1];
arrayC[j+1] = arrayC[j];
arrayC[j] = temp;
}
}
}
}
float gpaAvg(int gpaSum, int totalHours )
{
float gpa;
gpa = float ((gpaSum * 100) / totalHours);
return gpa;
}
int main(){
int hours[50], gpaForOneClass[50], arrayC[50], a = 0, b = 0, c = 0, totalHours = 0, gpaSum = 0;
char grades[50];
string course[50];
float gpa = 0.0;
gradevalue in;
cout<<"\nEnter a course, the letter grade received, and the credit hours "<<endl;
cin>>course[a]>>grades[a]>>hours[a];
while (course[a] != "quit" || course[a] != "QUIT")
{
in = convert(in, grades[a]);
gpaForOneClass[a] = grade(in, hours[a]);
op_grade(in);
gpaSum = gpaSum + gpaForOneClass[a];
totalHours = totalHours + hours[a];
a = a + 1;
cout<<"\nEnter the next course, the letter grade received, and the credit hours. "<<endl;
cin>>course[a]>>grades[a]>>hours[a];
}
gpa = gpaAvg(gpaSum, totalHours);
bsort(arrayC, c);
header();
for (b = 0; b < c; b++)
{
cout<<course[b]<<" "<<hours[b]<<" "<<grades[b]<<endl;
}
cout<<"The total GPA is "<<gpa<<" And you attempted "<<totalHours<<" hours."<<endl;
return 0;
}
to further explain my problem...
The program compiles just fine... the problem is with the output..
say you input math A 3 for math an A in the class and 3 hours
it returns the value A and you input more
after 2 or 3 inputs you have to type quit 2 times, not just one for the program to quit. Also once you do this... it just states the line
"Enter a course, the letter grade received, and the credit hours" over and over with the last letter value "A" or whatever in between each of the lines... It continues this until i get an error message from windows (it also looks around like 50 times) thats why i am curious if i did my arrays wrong or my bubblesort or what?
Thanks everybody who looks at it or tries to help or anything.