Really need help with the main function of this Class program

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
Last edited on

Don't post homework questions
Programmers are good at spotting homework questions; most of us have done them ourselves. Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.

http://www.cplusplus.com/forum/beginner/1/
So what do you have so far? If you have your class all defined and ready you just need to create and instance in main and use the methods you created to modify said instance.
#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(string nm);
void setMajor(string mj);
void setTerm(string trm);
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;

}
Having trouble setting the 'marks[]' and finding the average stuff
is marks supposed to be an array?
In the StudentRecord you need to define like this:
 
int marks[5];

The you can set it like this:
 
void setMarks(int marks[5]);
Thank you!
How would I go about getting the average of the 5 user input numbers and displaying it?
I know that I have to put in a for loop for the:
'void studentRecord::setMarks(int mark[])'
but i don't know how to go from there
There are many ways to do this. I will demonstrate some.
1
2
3
4
5
6
7
int marks[5];
for (int i = 0; i < 5; i++) {
  int mark = 0;
  std::cin >> mark;
  marks[i] = mark;
 }
theStudentRecord.setMarks(marks);


1
2
3
4
5
int sum = 0;
for (int i = 0; i < 5; i++) {
  sum += marks[i];
}
int average = sum / 5.0;

the code is pretty simple, I think you could improve it by yourself.
Last edited on
Ahh thank you soo muchhh you're awesomeee!!
Topic archived. No new replies allowed.