Hello, I have an assignment that I am struggling with and could use help.
Here are the instructions.
1. Based on StudentTestScores.h (with the overloaded operator) created in the class, please create
an individual cpp file to implement a main function to do the following tasks:
(a) Create records for the following students:
“Mike” with two test scores (100, 98),
“Shawn” with three test scores (60, 55, 70),
and “Peter” with five test scores (90, 67, 75, 89, 81);
(b) Show each student’s record on the screen using the format (from the example code showed
in the class);
(c) Let Mike=Peter (pseudo code), show Mike’s information on the screen;
(d) Let Peter=Shawn (pseudo code), show Peter’s information on the screen.
I will provide the header file. I can't get C and D. So here is my code
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
//Header File
#pragma once
#include <string>
using namespace std;
const double DEFAULT_SCORE = 0;
class StudentTestScores
{
private:
string studentName;
double* testScores;
int numTestScores;
void creatTestScoresArray(int size)
{
numTestScores = size;
testScores = new double[size];
for (int i =0; i < size; i++)
testScores[i] = DEFAULT_SCORE;
}
public:
StudentTestScores(string name, int numScores)
{
studentName = name;
creatTestScoresArray(numScores);
}
StudentTestScores(const StudentTestScores& obj)
{
studentName = obj.studentName;
numTestScores = obj.numTestScores;
testScores = new double[numTestScores];
for (int i= 0; i < numTestScores; i++)
testScores[i] = obj.testScores[i];
}
const StudentTestScores operator=(const StudentTestScores& right)
{
delete[] testScores;
studentName = right.studentName;
numTestScores = right.numTestScores;
testScores = new double[numTestScores];
for (int i = 0; i < numTestScores; i++)
testScores[i] = right.testScores[i];
return *this;
}
~StudentTestScores()
{
delete[] testScores;
}
void setTestScore(double score, int index)
{
testScores[index] = score;
}
void setStudentName(string name)
{
studentName = name;
}
string getStudentName()
{
return studentName;
}
int getNumTestScroes()
{
return numTestScores;
}
double getTestScores(int index)
{
return testScores[index];
}
};
// Main CPP
#include <iostream>
#include "StudentTestScores.h"
using namespace std;
int main()
{
StudentTestScores student1("Mike", 2);
student1.setTestScore(100.0, 0);
student1.setTestScore(98.0, 1);
StudentTestScores student2("Shawn", 3);
student2.setTestScore(60.0, 0);
student2.setTestScore(55.0, 1);
student2.setTestScore(70.0, 2);
StudentTestScores student3("Peter", 5);
student3.setTestScore(90.0, 0);
student3.setTestScore(67.0, 1);
student3.setTestScore(75.0, 2);
student3.setTestScore(89.0, 3);
student3.setTestScore(81.0, 4);
//b ALL STUDENTS INFORMATION
/* cout << "Name: " << student1.getStudentName() << endl;
cout << "test scores: ";
for (int a = 0; a < student1.getNumTestScroes(); a++)
{
cout << student1.getTestScores(a) << " ";
}
cout << endl;
cout << "Name: " << student2.getStudentName() << endl;
cout << "test scores: ";
for (int a = 0; a < student2.getNumTestScroes(); a++)
{
cout << student2.getTestScores(a) << " ";
}
cout << endl;
cout << "Name: " << student3.getStudentName() << endl;
cout << "test scores: ";
for (int a = 0; a < student3.getNumTestScroes(); a++)
{
cout << student3.getTestScores(a) << " ";
}
cout << endl;*/
//c MIKE = PETER
student3 = student1;
cout << "Name: " << student3.getStudentName() << endl;
cout << "test scores: ";
for (int a = 0; a < student3.getNumTestScroes(); a++)
{
cout << student3.getTestScores(a) << " ";
}
cout << endl;
//d) PETER = SHAWN
/*tudent2 = student3;
cout << "Name: " << student2.getStudentName() << endl;
cout << "test scores: ";
for (int a = 0; a < student2.getNumTestScroes(); a++)
{
cout << student2.getTestScores(a) << " ";
}
cout << endl;*/
}
|
Here is part 2. That no one in my class can understand:
. Based on your code for assignment 1, create a new C++ project using the same
StudentTestScores.h and cpp file. Then replace the following lines in the main function with a
user defined standalone function: displayStudentInfo(StudentTestScores student), which can be
called by the main function:
cout << "Name: " << student.getStudentName() << endl;
cout << "Test Scores: ";
for (int i = 0; i < student.getNumTestScores(); i++)
cout << student.getTestScore(i) << " ";
cout << endl;
Compile and run the revised code
****Please help****