this c++ program is supposed to read in information about students from a file, calculate gpa and stuff and print it out, when i run the program i have all i get are weird outputs, help me figure this out plz
anyway heres the program
#include
#include
#include
using namespace std;
class Course{
char grade;
int hours;
public:
Course(){
name = "";
hours = 0;
}
Course(string n, char g, int h);
void setName(string n){name=n;}
void setGrade(char g){grade=g;}
void setHours(int h){hours=h;}
string getName(){return name;}
char getGrade(){return grade;}
int getHours(){return hours;}
void print(){
if (name != ""){
cout.width(10); cout<< name;
cout.width(4); cout << grade;
cout.width(4); cout << hours << endl;
}
else
cout << "....." << endl;
}
};
class Student{
string last,first,street,city,state,z...
int id;
int num_classes;
Course classes[15];
2007-04-23
19:17:53
·
3 answers
·
asked by
Alex P
2
in
Computers & Internet
➔ Programming & Design
int hours_att, hours_earned, grade_points;
double gpa;
public:
Student(){
last = first = street = city = state = zip = major = minor = "";
id = num_classes = hours_att = hours_earned = grade_points = 0;
}
Student(string f,string l,string s,string c,string st,string z, string ma, string mi,
int i, int ha, int he, int gp){
last=l;first=f;street=s;city=c...
id=i;hours_att=ha;hours_earned...
num_classes = 0; // Don't set number of classes to anything but zero.
}
void setLast(string l){last = l;}
void setFirst(string f){first = f;}
void setStreet(string s){street = s;}
void setCity(string c){city = c;}
void setState(string s){state = s;}
void setZip(string z){zip = z;}
void setMajor(string m){major = m;}
void setMinor(string m){minor = m;}
void setID(int i){id = i;}
void setHoursAtt(int h){
if (h > 0)
hours_att = h;
else
hours_att = 0;
}
2007-04-23
19:18:16 ·
update #1
void setHoursEarned(int h){
if (h > 0)
hours_earned = h;
else
hours_earned = 0;
}void setGradePoints(int g){
if (g > 0)
grade_points = g;
else
grade_points = 0;
}
void setGPA(double g){
if (g > 0)
if (g > 4.0)
gpa = 4.0; // > 4.0 is not reasonable
else
gpa = g;
else
gpa = 0; // < 0 is not reasonable
}
string getLast(){return last;}
string getFirst(){return first;}
string getStreet(){return street;}
string getCity(){return city;}
string getState(){return state;}
string getZip(){return zip;}
string getMajor(){return major;}
string getMinor(){return minor;}
int getID(){return id;}
int getHoursAtt(){return hours_att;}
int getHoursEarned(){return hours_earned;}
int getGradePoints(){return grade_points;}
double getGPA(){return gpa;}
void calculate_hours(char grade, int hours){
hours_att = hours_att+hours;
if (grade=='A'||grade=='B'||grade...
hours_earned = hours_earned+hours;
2007-04-23
19:18:43 ·
update #2
hours_earned = hours_earned;
if (grade=='A')
grade_points = (grade_points + hours*4);
if (grade=='B')
grade_points = (grade_points + hours*3);
if (grade=='C')
grade_points = (grade_points + hours*2);
if (grade=='D')
grade_points = (grade_points + hours*1);
gpa = (grade_points/hours_att);
}
void SetAll(string l,string f,string s,string c,string st,string z,string M,string m,int i){
cout<<"from SetAll"<
last=l;first=f;street=s;city=c...
}
void label(){
cout<
cout<
cout<
}
void print(){
cout << "Student printout:" <
cout << street << ", "<< city << ", "<< state << ", "<< zip << endl;cout << major << ", "<< minor << "; "<< hours_att<< ", "<
2007-04-23
19:19:05 ·
update #3
int load(Student x[], int count){
ifstream data("student.txt");
string l,f,s,c,st,z,M,m;
int i, ha,he, g;
int ct;
for(ct=0;ct
getline(data,l);
getline(data,f);
getline(data,s);
getline(data,c);
getline(data,st);
getline(data,z);
getline(data,M);
getline(data,m);
data>>i;
data>>ha;
data>>he;
data>>g;
data.ignore();
'
cout<<"Record #"<
<
x[ct].SetAll(l,f,s,c,st,z,M,m,...
}
return --ct;
}
int main(){
Student list[20];
int count = load(list, 20);
cout<<"'load' read in" << count <<" student." <
for (int i=0; i
list[i].print();
cout<
ifstream data("courses.txt");
string a,b,c,d;
int count1=20,ct;
for(ct=0;ct
getline(data, a);
getline(data, b);
getline(data, c);
getline(data, d);
}
}
2007-04-23
19:20:03 ·
update #4