I am working on a Final Assessment for my first C++ programming course, which is
ID: 3751837 • Letter: I
Question
I am working on a Final Assessment for my first C++ programming course, which is an application using multiple files structure and specific parameters. I got an answer to what I was refferrign to but I have another questions to expound on this.
I have a class named Students held in filename Student:
Header file has constructor Student(string, string, string, string, int, int*)
and Private variables:
string studentID;
string firstName;
string lastName;
string email;
int age;
int daysInCourse[3];
string degreeProgram //which is not included in this list but located in another .h file enum degreeProgram {SECURITY, NETWORKING, SOFTWARE};
Then accessor/mutator list the above (minus degreeProgram) in Public:
However, there is an accessor:
virtual int getDegreeProgram();
and required mutator:
virtual void print();
Question:
1. virtual void print(); since it is void, it can't "get" so do I create an accessor and or mutator for virtual void print(); ?
2. The mutator
void Students::setDegreeProgram(string) {
degreeProgram;
}
Alert says it was not declared, which is true, so do I leave it out?
In .cpp file (reffer to questions)
string Students::getDegreeProgram() {
return();
}
void Students::setDegreeProgram(string) {
degreeProgram;
}
void Students::setPrint() {
print();
}
Explanation / Answer
Q1) virtual void print(); since it is void, it can't "get" so do I create an accessor and or mutator for virtual void print(); ?
Ans.: Accessor means getter and Mutator means setter.
Now after above explanation I understand that Accessor is getDegreeProgram();and you need to create mutator void print();
But mutator means setter so there is no need to return any value. So no need to create any accessor or mutator for void print();
void print(); itself work as mutator.
Q2) The mutator
void Students::setDegreeProgram(string) {
degreeProgram;
}
Alert says it was not declared, which is true, so do I leave it out?
Ans.: Declare it with the private variable.But you need to declare it as static, without its body.
string Students::getDegreeProgram() {
return degreeProgram();
}
void Students::setDegreeProgram(string s) {
degreeProgram=s;
}
void Students::setPrint() {
print();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.