Write a class name StudentRecord with the following specific
Solution
// StudentRecord.h
#ifndef StudentRecord_H
#define StudentRecord_H
class StudentRecord
{
string name;
double marks[5];
string major;
string term;
public:
StudentRecord();
void setName(string studName);
void setMarks(double studMarks[]);
void setMajor(string tempMajor);
void setTerm(string tempTerm);
string getName();
double[] getMarks();
string getMajor();
string getTerm();
double findAverage();
void displayProfile();
};
#endif
--------------------------------------------------------------------------
// StudentRecord.cpp
#include \"StudentRecord.h\"
//empty constructor
StudentRecord::StudentRecord(){
}
//setter methods
void StudentRecord::setName(string studName){
this.name = studName;
}
void StudentRecord::setMarks(double studMarks[]){
this.marks = studMarks;
}
void StudentRecord::setMajor(string tempMajor){
this.major = tempMajor;
}
void StudentRecord::setTerm(string tempTerm){
this.term = tempTerm;
}
//getter methods
string StudentRecord::getMajor(){
` return major;
}
string StudentRecord::getTerm(){
` return term;
}
string StudentRecord::getName(){
` return name;
}
double[] StudentRecord::getMarks(){
` return marks;
}
//finding average
doueble StudentRecord::findAverage(){
double sum = 0;
for(int i=0;i<5;i++){
sum = sum + marks[i];
}
return sum/marks.length;
}
// method to display profile
void StudentRecord::displayProfile(){
cout<<\"\ Name: \"<<name;
cout<<\"\ Major: \"<<major;
cout<<\"\ Term: \"<<term;
cout<<\"\ Team Average: \"<<findAverage();
}
//main
#include <iostream>
using namespace std;
int main(){
string name, major,term;
double marks[5];
//reading data
cout<<\"Enter name: \";
cin>>name;
cout<<\"Enter term: \";
cin>>term;
cout<<\"Enter major: \";
cin>>major;
cout<<\"Enter your 5 course marks: \";
for(int i=0;i<5;i++){
double score;
cin>>score;
if(score > 100 || score < 0){
marks[i] = 0;
}
else{
marks[i] = score;
}
}
//creating student record object
StudentRecord obj;
//calling methods
obj.setName(name);
obj.setTerm(term);
obj.setMajor(major);
obj.setMarks(marks);
obj.displayProfile();
return 0;
}
![Write a class name StudentRecord with the following specifications - Data members: name, marks[], major, term (use appropriate data type) Member functions: You Write a class name StudentRecord with the following specifications - Data members: name, marks[], major, term (use appropriate data type) Member functions: You](/WebImages/44/write-a-class-name-studentrecord-with-the-following-specific-1138402-1761609932-0.webp)
![Write a class name StudentRecord with the following specifications - Data members: name, marks[], major, term (use appropriate data type) Member functions: You Write a class name StudentRecord with the following specifications - Data members: name, marks[], major, term (use appropriate data type) Member functions: You](/WebImages/44/write-a-class-name-studentrecord-with-the-following-specific-1138402-1761609932-1.webp)
![Write a class name StudentRecord with the following specifications - Data members: name, marks[], major, term (use appropriate data type) Member functions: You Write a class name StudentRecord with the following specifications - Data members: name, marks[], major, term (use appropriate data type) Member functions: You](/WebImages/44/write-a-class-name-studentrecord-with-the-following-specific-1138402-1761609932-2.webp)