Ok thank you for replying.. my code is quite large but I'll post it.
I am using Visual Studio 2008, professional (provided by the college)
Code:
//Student.h the specification file for class Student
#include <iostream>
using namespace std;
class Student{
friend istream & operator>> (istream&, Student &);
//Function overrides the instream operator.
//Intended to ease the input of student data
friend ostream & operator<< (ostream&, const Student &);
//Function overrides the outstream operator.
//Intended to ease the output of student data
private:
char name[46];
//Student’s name: 45 characters, alpha-numeric
char grade;
//Student grade: Characters, A, B, C, D, & F
float gpa;
//Student GPA: floats
public:
void setName(std::string newName);
//Function to set the name of the student
//Postcondition: name = newName;
std::string getName();
//Function to get the name of the student
//Postcondition: returns the name of the student
// as a string
void setGrade(char newGrade);
//Function to set the Grade of the student
//Postcondition: grade = newGrade;
char getGrade();
//Function to get the grade of the student
//Postcondition: returns the grade of the student
// as a character
void setGpa(float newGpa);
//Function to set the name of the student
//Postcondition: gpa = newGpa;
float getGpa();
//Function to get the gpa of the student
//Postcondition: returns the gpa of the student
// as a float
Student();
//Default Constructor
//All variables are set to 0 or "" or ' '
~Student();
//default destructor
};
Code:
//Student.cpp The implementation file
#include "stdafx.h"
#include <String>
//#include <iostream>
#include "Student.h"
//using namespace std;
istream& operator>>(istream& cin2, Student &studentObject)
{
char temp;
cin2 >> temp;
//studentObject.setGrade(temp);
return cin2;
}
ostream& operator<<(ostream& cout, const Student &studentObject)
{
return cout;
}
void Student::setName(string newName)
{
for (unsigned int i = 0; i < newName.length(); i++)
{
name[i] = newName.at(i);
}
}
string Student::getName()
{
return name;
}
void Student::setGrade(char newGrade)
{
grade = newGrade;
}
char Student::getGrade()
{
return grade;
}
void Student::setGpa(float newGpa)
{
gpa = newGpa;
}
float Student::getGpa()
{
return gpa;
}
Student::Student()
{
char name[46] = "";
char grade = ' ';
float gpa = 0.0;
}
Student::~Student(){}
//default destructor
Code:
/*
Module7-Assignment7.cpp : main project file.
Written by Schuett, Hugh for Assignment 2, Module 2
10SS_INFO_1532_WW - C++ Programming II, Metropolitan Community College
Modified by Russell Dempsey, for Assignment 2, Module 2, MCC, JUNE 2010
Modified by Russell Dempsey, for Assignment 6, Module 6, MCC, JULY 2010
Modified by Russell Dempsey, for Assignment 7, Module 7, MCC, AUG 2010
*/
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string>
#include "Student.h"
/*
For this project you are going to take the last project, #6 (the grades program), and this time you are going to add operator overloading.
Remember the programming example at the end of the chapter is a great example of this.
Project Requirements:
<!--[if !supportLists]-->1. <!--[endif]-->A class object of this class will be all the information for one student.
<!--[if !supportLists]-->2. <!--[endif]-->You will have an array (4) of the objects, one element for each student.
<!--[if !supportLists]-->3. <!--[endif]-->You will overload the extraction operator (“>>”). The overloaded operator will then
perform all of the grade input for that individual. The code in your main will look like this: cin >> students[counter];
Where students is the array of objects and counter is the subscript.
<!--[if !supportLists]-->4. <!--[endif]-->You will overload the insertion operator (“<<”). The overloaded operator will then
perform all of the grade output for that individual. The code in your main will look like this: cout << students[counter]; Where
students is the array of objects and counter is the subscript.
*/
Student students[];
void gradeRecursion(int);
void displayOutput();
using namespace std;
int main ()
{
/*
name = new string[4];
//DEBUGGING
//cout << "\n\n " << &name << "\n\n";
//DEBUGGING
*name = "Freddie";
*(++name) = "Jane";
*(++name) = "Jonathan";
*(++name) = "Mary";
//DEBUGGING
//cout << "\n\n " << &name << "\n\n";
//DEBUGGING
name=name-3;
totalGPA = new double[4];
*/
Student students[4];
students[0].setName("Freddie");
students[1].setName("Jane");
students[2].setName("Jonathan");
students[3].setName("Mary");
gradeRecursion(3);
//cin >> students[1];
displayOutput();
cout << "\nPress any key to continue ..." << flush;
_getch();
/*
delete [] name;
delete [] totalGPA;
name = 0;
totalGPA = 0;
*/
return 0;
}
void gradeRecursion(int numGradesToGet)
{
if (numGradesToGet >= 0)
{
//char grade;
cout << "Enter " << students[numGradesToGet].getName() << "'s Grades" << endl;
for ( int y=1; y<6; y++ )
{
cout << "Grade # " << students[numGradesToGet].getName() << "'s Letter Grade: ";
cin >> students[numGradesToGet];
switch(students[numGradesToGet].getGrade())
{
case 'A': case 'a': students[numGradesToGet].setGpa(students[numGradesToGet].getGpa()+4);
break;
case 'B': case 'b': students[numGradesToGet].setGpa(students[numGradesToGet].getGpa()+3);
break;
case 'C': case 'c': students[numGradesToGet].setGpa(students[numGradesToGet].getGpa()+2);
break;
case 'D': case 'd': students[numGradesToGet].setGpa(students[numGradesToGet].getGpa()+1);
break;
case 'F': case 'f': students[numGradesToGet].setGpa(students[numGradesToGet].getGpa()+0);
break;
default: cout << "A Valid Letter Grade is A, B, C, D, or F " << endl;
y--;
}
}
students[numGradesToGet].setGpa(students[numGradesToGet].getGpa()/5);
system("cls");
if (numGradesToGet > 0)
{
gradeRecursion(numGradesToGet-1);
}
}
}
void displayOutput()
{
cout << fixed << showpoint << setprecision(3);
cout << setw(30) << left << "Student" << right << "GPA\n " << endl;
for( int x=3; x>=0; x-- )
{
//cout << students[x];
//cout << setw(30) << left << name[x] << right << totalGPA[x]/5 << endl;
}
}