C++ programming for class

Write a class name StudentRecord with the following specifications –
• Data members:
name, marks[], major, term (use appropriate data type)
• Member functions:
o You are allowed to leave the constructor default
o Implement all get/set methods
o double findAverage( ) – returns the average mark of the student
o void displayProfile( ) – displays the profile of a student in following manner
Name: John Smith
Major: Computer Science
Term: Fall 2015
Term average: 90%
• Main function:
o Take input from user for name, major and term name
o Take input from the user for 5 courses s/he has enrolled in this term (you must
put a validation checking that the range of input such that 100<=marks>=0)
o Create an object of StudentRecord class
o Set name, major, term name and the marks[]
o Invoke displayProfile() function to display the information of the student
• Special instruction: You MUST submit following 3 files –
o StudentProfile.h
o StudentProfile.cpp
o StudentProfileMain.cpp


Can someone please check to see what i did wrong here please?And this is what i got so far!

#include <iostream>
using namespace

class StudentRecord{
private:

string name;
string major;
string term;
int marks[];
public:

StudentRecord();
string getName();
string getMajor();
string getTerm();
int getMarks();
void setName();
void setMajor();
void setTerm();
void setMarks(int mark);

double findAverage(){

}
void displayProfile(name, major, term, termAverage);
};

StudentRecord::StudentRecord(){
name = "John Smith";
major = "Computer Science";
term = "Fall 2015"
term average = 90
}
string StudentRecord::getName(){
return name;
}
string StudentRecord::getMarks(){
return marks;
}
string StudentRecord::getTerm(){
return term;
}
double StudentRecord::findAverage(){
return 0.0;
}
void StudentRecord::setName(string nm){
Name = nm;
}
void StudentRecord::setMajor(string mj){
Major = mj;
}
void StudentRecord::setTerm(string trm){
Term = trm;
}
void StudentRecord::setMarks(int mark){
Marks = mark;
}
void StudentRecord::setdisplayProfile(){

}
int main(){

StudentRecord myProfile;

string findName = myProfile.getName();
cout<< findName << endl;

string findMajor = myProfile.getMajor();
cout << findMajor <<endl;

string findTerm = myProfile.getTerm();
cout << findTerm << endl;

}
Last edited on
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) You've marked this thread as solved. Does that mean you no longer want help with it?
Sorry, this is my first time using this and i am still need help with this. Thanks!
Here is your code cleaned up enough to compile. Search for "dmh" to see what I changed.
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
#include <iostream>
using namespace std;            // dmh

constexpr unsigned NumMarks = 5;        // dmh

class StudentRecord
{
  private:

    string name;
    string major;
    string term;
    int marks[NumMarks];        // dmh
  public:

    //    StudentRecord();              // dmh - delete this. Instruction say u\
se default
      string getName();
    string getMajor();
    string getTerm();
    int getMarks(unsigned idx); // dmh - you need to say which mark to get
    void setName(string n);     // dmh - need a param
    void setMajor(string m);    // dmh - need a param
    void setTerm(string t);     // dmh - need a param
    void setMarks(unsigned idx, int mark);      // dmh, you need to specify whi\
ch mark to set

    double findAverage();       // dmh
    void displayProfile();      // dmh - no need for args. Display the members
};

// dmh - delete this. Instructions say use the default
#if 0
StudentRecord::StudentRecord()
{
    name = "John Smith";
    major = "Computer Science";
    term = "Fall 2015" term average = 90;
}
#endif

string StudentRecord::getName()
{
    return name;
}

// dmh - forgot to implement this one.
string StudentRecord::getMajor()
{
    return major;
}

int                             // dmh
StudentRecord::getMarks(unsigned idx)
{
    return marks[idx];
}

string StudentRecord::getTerm()
{
    return term;
}

double
StudentRecord::findAverage()
{
    return 0.0;
}

void
StudentRecord::setName(string nm)
{
    name = nm;                                   // dmh - "name", not "Name"
}

void
StudentRecord::setMajor(string mj)
{
    major = mj;                                  // dmh = "major", not "Major"
}

void
StudentRecord::setTerm(string trm)
{
    term = trm;                                  // dmh - "term" not "Term"
}

void
StudentRecord::setMarks(unsigned idx, int mark)
{
    marks[idx] = mark;                           // dmh "term" not "Term"
}

// dmh - delete this. There is no such method (did you mean displayProfile()?
#if 0
void
StudentRecord::setdisplayProfile()
{

}
#endif

int
main()
{

    StudentRecord myProfile;

    string findName = myProfile.getName();
    cout << findName << endl;

    string findMajor = myProfile.getMajor();
    cout << findMajor << endl;

    string findTerm = myProfile.getTerm();
    cout << findTerm << endl;

}


Jesus I hate professors who require the blind use of get/set methods. I bet you spent hours putting this code together. It's equivalent to this:
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
#include <iostream>
using namespace std;

constexpr unsigned NumMarks = 5;

class StudentRecord
{
public:
    string name;
    string major;
    string term;
    int marks[NumMarks];
    double findAverage();
    void displayProfile();
};


int
main()
{

    StudentRecord myProfile;

    string findName = myProfile.name;
    cout << findName << endl;

    string findMajor = myProfile.major;
    cout << findMajor << endl;

    string findTerm = myProfile.term;
    cout << findTerm << endl;

}

The get/set methods in this case are nothing more than programming masturbation.
Topic archived. No new replies allowed.