there are 3 files but the one iam having problems with is the student.cpp
student.cpp
main.cpp
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <string>
using namespace std;
class student {
public:
//--constructors
student();
// post: Initialize a student object with a name as "?name?,"
// 0.0 credits, and 0.0 quality points
student(string initName, double initCredits, double initQualityPoin ts);
// post: Initialize a student object with this 3 argument constructor
// student("Delais io, Donna," 30.0, 120.0);
// A straight A sophomore at one school
//--modifier
void completedCourse (double credits, double numericGrade);
// post: record a completed course by adding credits to my_credits
// and incrementing the qualityPoints by (credits * numericGrade)
// aStudent.comple tedCourse(4.0, 3.67) // a 4 credit A- perhaps
//--accessors
double GPA() const;
// post: return the current grade point average as the accumulated
// quality points divided by the total number of credits.
string standing() const;
// post: use selection to return the current standing as either
// Freshman, Sophomore, Junior, or Senior.
string name() const;
// post: return the student's name
private:
string my_name;
double my_credits; // Total credits completed
double my_qualityPoint s; // sum of credits multiplied by grades
};
#endif
[/CODE]
student.cpp
Code:
#include <iostream> // for ostream << and istream >>
#include <string>
#include "student.h"
using namespace std;
//--constructors
student::student()
{
my_name = "?name?";
my_credits = 0.0;
my_qualityPoints = 0.0;
}
student::student(string initName, double initCredits, double initQualityPoints)
{
my_name = "initName,";
my_credits = initCredits;
my_qualityPoints = initQualityPoints;
}
//--modifiers
void student::completedCourse(double credits, double numericGrade)
{
my_credits = my_credits + credits;
my_qualityPoints = my_qualityPoints + (my_credits * numericGrade);
}
//--accessors
double student::GPA() const
{
my_qualityPoints / my_credits;
return;
}
string student::standing() const
{
if credits > 30
return “Freshman”;
if credits >= 30
return “Sophomore”;
if credits >= 60
return “Junior”;
if credits >=90
return “Senior”;
}
string student::name() const
{
Return my_name;
}
Code:
#include <iostream>
#include <string>
#include "student.h" // this includs student.h
#include "compfun.h" // for decimals
using namespace std;
void display(student aStudent)
{
decimals(cout, 2);
cout << "{ student: " << aStudent.name();
cout << ", GPA = " << aStudent.GPA() << " }" << endl;
}
int main()
{ // test drivbe student: this main will vary a,mongst students
student aStudent("Nguyen", 36.5, 123.5);
student anotherStudent("Stella", 4.0, 16.0); // Straight A so far
student one ("one should be 3.0", 0.0, 0.0);
one.completedCourse( 4.0, 2.0 );
one.completedCourse( 4.0, 4.0 ); // 4 credit A
display( one );
display( aStudent );
display( anotherStudent );
// Finish branch coverage testing of standing
student two("two", 100.0, 30.0);
student three( "three", 30.05, 100.0 );
student four("four" , 60.0, 100.0 );
student five("five ", 60.05, 100.0);
student six ("six " , 90.0, 100.0);
student seven("seven", 90.05, 100.0 );
cout << one.standing() << endl;
cout << two.standing() << endl;
cout << three.standing() << endl;
cout << four.standing() << endl;
cout << five.standing() << endl;
cout << six.standing() << endl;
cout << seven.standing() << endl;
return 0;
}
[B]student.h[/B]
[CODE]
#define STUDENT_H
#include <iostream>
#include <string>
using namespace std;
class student {
public:
//--constructors
student();
// post: Initialize a student object with a name as "?name?,"
// 0.0 credits, and 0.0 quality points
student(string initName, double initCredits, double initQualityPoin ts);
// post: Initialize a student object with this 3 argument constructor
// student("Delais io, Donna," 30.0, 120.0);
// A straight A sophomore at one school
//--modifier
void completedCourse (double credits, double numericGrade);
// post: record a completed course by adding credits to my_credits
// and incrementing the qualityPoints by (credits * numericGrade)
// aStudent.comple tedCourse(4.0, 3.67) // a 4 credit A- perhaps
//--accessors
double GPA() const;
// post: return the current grade point average as the accumulated
// quality points divided by the total number of credits.
string standing() const;
// post: use selection to return the current standing as either
// Freshman, Sophomore, Junior, or Senior.
string name() const;
// post: return the student's name
private:
string my_name;
double my_credits; // Total credits completed
double my_qualityPoint s; // sum of credits multiplied by grades
};
#endif
[/CODE]
Comment