In: Computer Science
In C++ and their need to be 3 files please
Instructions
In this lab, you will modify the Student class you created in a previous lab. You will modify one new data member which will be a static integer data member. Call that data member count. You also add a static method to the Student class that will display the value of count with a message indicating what the value represents, meaning I do not want to just see a value printed to the screen.
Change main so that it calls this new method towards the end of the program. Call the method using the static syntax; do not use one of the instances of the Student class.
You will also need to change the Student constructor so that it increments the new data member you added, count. In your post explain why you get the value it displays.
Download Source Lab 7 Files:
File 1.) Source.cpp
#include
#include "Student.h"
using namespace std;
int main()
{
Student rich(2);
rich.DisplayStudent();
Student mary(3);
mary.DisplayStudent();
return 0;
}
File 2.) Student.cpp
#include "Student.h"
Student::Student(int numGrades)
{
quanity = numGrades;
grades = new int[numGrades];
name = "rich";
grades[0] = 88;
grades[1] = 96;
}
Student::~Student()
{
delete[] grades;
}
void Student::DisplayStudent()
{
cout << "Grades for " << name << endl;
for (int index = 0; index < quanity; index++)
{
cout << *(grades + index) << endl;
}
}
File 3.) Student.h #pragma once
#include
#include
using namespace std;
class Student
{
public: Student(int numGrades);
~Student();
void DisplayStudent();
private: string name;
int* grades;
int quanity;
};
If you have any doubts, please give me comment...
Student.h
#pragma once
#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
Student(int numGrades);
~Student();
void DisplayStudent();
static int getCount();
private:
static int count;
string name;
int *grades;
int quanity;
};
Student.cpp
#include "Student.h"
int Student::count = 0;
Student::Student(int numGrades)
{
quanity = numGrades;
grades = new int[numGrades];
name = "rich";
grades[0] = 88;
grades[1] = 96;
count++;
}
Student::~Student()
{
delete[] grades;
}
void Student::DisplayStudent()
{
cout << "Grades for " << name << endl;
for (int index = 0; index < quanity; index++)
{
cout << *(grades + index) << endl;
}
}
int Student::getCount(){
return count;
}
Source.cpp
#include<iostream>
#include "Student.h"
using namespace std;
int main()
{
Student rich(2);
rich.DisplayStudent();
Student mary(3);
mary.DisplayStudent();
cout<<"Number of students: "<<Student::getCount()<<endl;
return 0;
}
