class help!!!!

hi i was wondering if someone can help me in writing this,
Create a class Student with the following private attributes:
 Student ID: should be an integer attribute.
 Student Name: should be a string attribute.
 Student Major: should be an object of class Major.
 Student Number of Credits: should be an integer attribute.
 Student GPA: should be a floating-point attribute.
 Student Level: should be a string attribute.
 Average GPA: should be a static floating-point attribute.
 Number of Students: should be a static integer attribute.
The class Student should contain the following behaviors:
 A constructor with no arguments should initialize the attributes to empty values except for Student Major and Average GPA.
 A constructor with five arguments (ID, Name, Major, Credits, GPA) should call the set all function.
 Number of Students attribute must be initialized to 0 and incremented by 1 in both constructors.
 Set functions for each attribute that enables cascading except for Student Level and Number of Students with the necessary integrity checking.
 A static set function that must assigns the attribute Average GPA, which is equal to the sum of all students’ GPAs divided by the number of students.
 A set all function that takes five arguments and calls the attributes’ set functions.
 Constant get functions for each attribute except for Number of Students. Average GPA should not have a constant get function, but a static get function.
 A destructor should decrement the Number of Students by 1 and print the Student Name plus the phrase “has been removed.”
 A print function to display the values of the attributes in a tabular format except for Average GPA and Number of Students. Student GPA should have only 1 decimal place.
 A utility function that sets the student level based on the number of credits found within the student’s major. The function must be called when the major is given to the student and when the student number of credits is changed. The following ranges must be used: 0 – 30: Sophomore / 31 – 60: Junior / 61 and up: Senior


i wrote a bit of it but i dont know if its right

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef Student_H
#define Student_H

#include "Major.h"

class Student
{
	private :
		int StudentID;
		string StudentName;
		Major StudentMajor;
		int StudentCredits;
		float StudentGPA;
		string StudentLevel;
		static float AverageGPA;
		static int NumberOfStudents;

	public :
	Student(int ,string ,int ,float ,string ,static int=0);
	Student(int, string ,Major ,int ,float );

Something like this?

Note, you can't simply access all of the GPAs from all instances of this class. Therefore instead of making a static set function that assigns the
average GPA, I just made a static member that keeps track of the sum of all GPAs

Also, I used tabs to get a tabular form, you may want to use setw().
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <string>
#include <iostream>
#include <iomanip>

class Major
{
public:
    bool good() const { return true;}  // returns true if the class is valid
    std::string name;
};

class Student
{
private: // Members
    int         m_id;
    std::string m_name;
    Major       m_major;
    int         m_nbCredits;
    float       m_gpa;
    std::string m_level;
public:
    static float s_avgGpa;
    static float s_totalGpa;
    static int   s_nbStudents;

public: // Contrustors
    Student() : m_id(0), m_name(""), m_nbCredits(0), m_gpa(0.0f), m_level("")
    {
        ++s_nbStudents;
    }

    Student(int id, std::string name, Major& major, int credits, float gpa)
    {
        ++s_nbStudents;
        set(id, name, major, credits, gpa);
    }

    ~Student()
    {
        s_totalGpa -= m_gpa;
        --s_nbStudents;

        std::cout << m_name << " has been removed." << std::endl;
    }

public: // Set Functions
    bool setID(const int id) // returns true if successful
    {
        if (id < 1) // ID must be > 0
            return false;

        m_id = id;
        return true;
    }
    bool setName(const std::string& name) // returns true if successful
    {
        if (name.empty()) // Input most not be empty
            return false;

        m_name = name;
        return true;
    }
    bool setMajor(const Major& major)
    {
        if (!major.good()) // Some arbirary check for whether major is valid
            return false;

        m_major = major;

        setLevel(); // This really doesn't do anything

        return true;
    }
    bool setCredits(const int credits)
    {
        if (credits<0) // credits must be positive
            return false;

        m_nbCredits = credits;

        setLevel();

        return true;
    }
    bool setGpa(const float gpa)
    {
        if (gpa < 0.0 || gpa > 5.0) // GPA must be within this range
            return false;

        // handling the total GPA
        s_totalGpa -= m_gpa;
        s_totalGpa += gpa;

        // Setting the value
        m_gpa = gpa;

        // Calculating the average GPA
        if (s_nbStudents > 0)
            s_avgGpa = s_totalGpa / s_nbStudents;
        else
            s_avgGpa = 0.0f;

        return true;
    }
    bool set(const int id, const std::string& name, const Major& major, const int credits, const float gpa)
    {
        bool result = setID(id);
        result      = setName(name)       && result;
        result      = setMajor(major)     && result;
        result      = setCredits(credits) && result;
        result      = setGpa(gpa)         && result;
        return result;
    }
public: // Get functions
    const int         getID()      { return m_id;        }
    const std::string getName()    { return m_name;      }
    const Major       getMajor()   { return m_major;     }
    const int         getCredits() { return m_nbCredits; }
    const float       getGpa()     { return m_gpa;       }
    const std::string getLevel()   { return m_level;     }
    static float      getAvgGpa()  { return s_avgGpa;    }

public: // I/O
    void print()
    {
        std::cout << getID() << '\t';
        std::cout << getName() << '\t';
        std::cout << getMajor().name << '\t';
        std::cout << getCredits() << '\t';
        std::cout << std::setprecision(2) << getGpa() << std::endl;
    }
private: // Utilities
    void setLevel()
    {
        if      (m_nbCredits < 31) m_level = "Sophomore";
        else if (m_nbCredits < 61) m_level = "Junior";
        else                       m_level = "Senior";
    }
};

int   Student::s_nbStudents = 0;
float Student::s_totalGpa   = 0.0f;
float Student::s_avgGpa     = 0.0f;

int main()
{
    Student s;
    Major m;
    s.set(5, "Henry", m, 35, 3.6f );
    s.print();
    return 0;
}
yes, 10x mate you helped me alot
Topic archived. No new replies allowed.