Name: Anonymous 2010-11-03 21:00
In my class we have an assignment in which we change GPA to Student Name. I've not done any work with names in c++ (my major has nothing to do with programing) but here is the default:
bool studentDB::addStudent(int num, double GPA) {
int i;
if(numStudents==MAXSTUDENTS) return false; // database is full
for(i=0;i<numStudents;i++) {
if(si[i].number==num) return false; // student already in database
if(si[i].number>num) { // slide the rest of the students to the right and insert student here
for (int j=numStudents;j>i;j--) {
si[j] = si[j-1]; // move student one to the right
}
break;
}
}
// insert student in correct place (if break above) otherwise add student at end
si[i].number = num;
si[i].GPA = GPA;
numStudents++; // we've added a student
return true; // success
}
and what I assume I should change it to (I can't compile and test yet since I have to make a new .h and .cpp for new classes and stuff). Note that our teacher gave a file called stdstuff.h and string2002 is used for characters.
bool studentDB::addStudent(int num, const String2002 &name) {
int i;
if(numStudents==MAXSTUDENTS) return false; // database is full
for(i=0;i<numStudents;i++) {
if(si[i].number==num) return false; // student already in database
if(si[i].number>num) { // slide the rest of the students to the right and insert student here
for (int j=numStudents;j>i;j--) {
si[j] = si[j-1]; // move student one to the right
}
break;
}
}
// insert student in correct place (if break above) otherwise add student at end
si[i].number = num;
si[i].name = name;
numStudents++; // we've added a student
return true; // success
}
Thanks
bool studentDB::addStudent(int num, double GPA) {
int i;
if(numStudents==MAXSTUDENTS) return false; // database is full
for(i=0;i<numStudents;i++) {
if(si[i].number==num) return false; // student already in database
if(si[i].number>num) { // slide the rest of the students to the right and insert student here
for (int j=numStudents;j>i;j--) {
si[j] = si[j-1]; // move student one to the right
}
break;
}
}
// insert student in correct place (if break above) otherwise add student at end
si[i].number = num;
si[i].GPA = GPA;
numStudents++; // we've added a student
return true; // success
}
and what I assume I should change it to (I can't compile and test yet since I have to make a new .h and .cpp for new classes and stuff). Note that our teacher gave a file called stdstuff.h and string2002 is used for characters.
bool studentDB::addStudent(int num, const String2002 &name) {
int i;
if(numStudents==MAXSTUDENTS) return false; // database is full
for(i=0;i<numStudents;i++) {
if(si[i].number==num) return false; // student already in database
if(si[i].number>num) { // slide the rest of the students to the right and insert student here
for (int j=numStudents;j>i;j--) {
si[j] = si[j-1]; // move student one to the right
}
break;
}
}
// insert student in correct place (if break above) otherwise add student at end
si[i].number = num;
si[i].name = name;
numStudents++; // we've added a student
return true; // success
}
Thanks