Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> #include <string> using namespace std; class StudentRecord{

ID: 3694082 • Letter: #

Question

#include <iostream>

#include <string>

using namespace std;

class StudentRecord{

private:

   string name;

   string major;

   string term;

   double marks[5];  

public:

   StudentRecord();

   string getName();

   string getMajor();

   string getTerm();

   double getMarks();

   void setName(string nm);

   void setMajor(string mj);

   void setTerm(string trm);

   void setMarks(double mrk[]);

  

   double findAverage();

   void displayProfile();

};

StudentRecord::StudentRecord(){

  

}

string StudentRecord::getName(){

   return name;

}

string StudentRecord::getMajor(){

   return major;

}

string StudentRecord::getTerm(){

   return term;

}

double StudentRecord::findAverage(){

   double avg;

  

   for(int i = 0; i<5; i++){

       avg=avg+marks[i];

   }

  

   return avg/5;

}

void StudentRecord::setName(string nm){

   name = nm;

}

void StudentRecord::setMajor(string mj){

   major = mj;

}

void StudentRecord::setTerm(string trm){

   term = trm;

}

void StudentRecord::setMarks(double mrk[]){

   marks = mrk;

   for( int i = 0; i>5; i++){

       marks[i] = mrk[i];

   }

}

void StudentRecord::displayProfile(){

   cout << "Name:" << name << endl;

   cout << "Major:" << major << endl;

   cout << "Term:" << term << endl;

   cout << "Term Average:" << findAverage() << endl;

}

int main(){

   StudentRecord myProfile;

   string name;

   string major;

   string term;

   double marks[5];

  

   cout<< "Please insert your name:" << endl;

   cin >> name;

   myProfile.setName(name);

   cout<< "Please insert your major:" << endl;

   cin >> major;

   myProfile.setMajor(major);

  

   cout << "Please insert your term:" << endl;

   cin >> term;

   myProfile.setTerm(term);

  

   for(int i = 0; i < 5; i++){

       cout<< "Please enter a number from 0-100:" << endl;

       cin >> marks[i];

   }

   myProfile.setMarks(marks);

   myProfile.findAverage();

   myProfile.displayProfile();

   return 0;

}

In member function ‘void StudentRecord::setMarks(double*)’: porject2.cpp:58:8: error: incompatible types in assignment of ‘double*’ to ‘double [5]’ marks = mrk; ^ what is the problem?

Explanation / Answer

remove marks = mrk; from void StudentRecord::setMarks(double mrk[])

essentially this is what your function should look like

void StudentRecord::setMarks(double mrk[]){

   for( int i = 0; i>5; i++){

       marks[i] = mrk[i];

   }

}

Reason: You can't assign one array to another simply using assignment operator

One more problem in your code:

double StudentRecord::findAverage(){

   double avg = 0;  

   for(int i = 0; i<5; i++){

       avg=avg+marks[i];

   }

   return avg/5.0;

}