This is the Header file
#ifndef STUDENT_H
#define STUDENT_H
// class Student definition
class Student
{
public:
Student( char *nPtr );
~Student();
void displayGrades() const;
Student addGrade( int );
static int getNumStudents();
private:
int *grades;
char *name;
int numGrades;
int idNum;
static int numStudents;
}; // end class Student
#endif // STUDENT_H
Here is my coding.. the only error is "strcpy_s( name, nPtr );" keeps saying it doesn't take 2 arguments.
#include <iostream>
using std::cout;
using std::endl;
#include <iomanip>
using std::setw;
#include <cstring>
#include "Student.h"
#include <new>
const int numStudents = 0;
// constructor
Student::Student( char *nPtr )
{
grades = new int[ 1 ];
grades[ 0 ] = 0;
name = new char[ strlen( nPtr ) + 1 ];
strcpy_s( name, nPtr );
numGrades = 0;
++numStudents;
cout << "A student has been added\n";
} // end class Student constructor
// destructor
Student::~Student()
{
cout << name << " has been deleted\n";
delete grades;
delete name;
--numStudents;
} // end class Student destructor
// function displayGrades definition
void Student::displayGrades() const
{
cout << "Here are the grades for " << name << endl;
// output each grade
for ( int i = 0; i < numGrades; i++ )
cout << setw( 5 ) << grades[ i ];
cout << endl << endl;
} // end function displayGrades
// function addGrade definition
Student Student::addGrade( int grade )
{
int *temp = new int[ numGrades + 1 ];
for ( int i = 0; i < numGrades; i++ )
temp[ i ] = grades[ i ];
temp[ numGrades ] = grade;
grades = temp;
++numGrades;
return *this;
} // end function addGrade
// function getNumStudents definition
int Student::getNumStudents()
{
return numStudents;
} // end function getNumStudents