Define and implement a class, Report, that has these members
Private members :
adno 4 digit admission number
nam string
marks an array of 5 real values
average average marks obtained
Public members:
Default constructor
Constructor with the four data members
Copy constructor
Operator+()
Operator<<() //Make sure the output looks like display explicitly written in the driver.
Operator>>() //Use the example run as your guide
Operator>()
Operator<()
Operator==()
Get() for each data member
Set() for each member
Operator++ for prefix
Operator—for prefix
setAVG() a function to compute the average obtained in five subjects
Type your solution in the program shell to your left as commented.
Here is an example run of the solution
Here is the Code to start. Do not change int main().
#include <iostream>
#include <string>
using namespace std;
//Define class here
int main(){
double d[5] = {90, 87, 53, 85, 93};
Report r1;
Report r2(6273, "James Smythe", d);
r1.setAdno(9933);
r1.setName("Pete Luckman");
r1.setMarks(45, 78, 99, 72, 88);
r1.setAVG();
cout << "Display
r1\n===================================\n";
cout << " Student ID: " << r1.getAdno();
cout << "\n Student Name: " << r1.getName();
cout << "\n Student Average: " << r1.getAvg();
cout << "\n===================================\n\n";
cout << "Display
r2\n===================================\n";
cout << r2;
cout << "\n===================================\n\n";
Report r3 = r2;
cout << "Enter the marks for r3...\n\n";
cin >> r3;
cout << "Thank you!";
cin.get();
cout << "\n\nDisplay
r3\n===================================\n";
cout << r3;
cout << "\n===================================\n\n";
cout <<
"Comparisons...\n========================================\n";
cout << "Compare r2 == r3: "
<< ((r2 == r3) ? "Same average" : "Different average")
<< endl;
cout << "Compare r1 > r2: "
<< ((r1 > r2) ? "r1 is greater" : "r2 is greater or
equal") << endl;
cout << "Compare r3 < r1: "
<< ((r1 < r3) ? "r1 is less" : "r3 is less or equal")
<< endl;
cout << "========================================\n\n";
cout << "\nAdd r1 and r2: " << r1 + r2 <<
endl;
cout << "\nIncrement r3: " << ++r3 << endl;
cout << "\nDecrement r2: " << --r2 << endl;
cout << "\n\n---------------\nEnd of program..." <<
endl;
return 0;
}
//Implement class methods
Check out the solution and let me know if you have any queries through COMMENTS.
_____________________________
#include <iostream>
#include <string>
using namespace std;
class Report
{
private:
int adno;
string name;
float marks[5];
float average;
public:
// default constructor - initialized to default values
Report()
{
adno = 0;
name = "";
for(int i=0;i<5;i++)
marks[i] = 0;
}
// constructor with 4 data members - assign the class members with
give values
Report(int ad, string nm, float m[5])
{
adno = ad;
name = nm;
for(int i=0;i<5;i++)
marks[i] = m[i];
}
// copy constructor - copies object's info into another
Report (Report &rep)
{
adno = rep.adno;
name = rep.name;
for(int i=0;i<5;i++)
marks[i] = rep.marks[i];
}
// operator +() - adds the averages of 2 objects
float operator+(Report &r2)
{
return (getAvg() + r2.getAvg());
}
// operator <<() - prints the data as required
friend ostream& operator<<(ostream& op, Report
&r1)
{
// first set the average for the calculating average then get the
average
r1.setAVG();
op << " Student ID: " << r1.getAdno() << "\n
Student Name: " << r1.getName() << "\n Student Average:
" << r1.getAvg();
return op;
}
// operator >>() - get the user input with the operator
'>>'
friend istream& operator>>(istream& ip, Report&
r1)
{
cout << "\n\tmarks #1:";
ip >> r1.marks[0];
cout << "marks #2:";
ip >> r1.marks[1];
cout << "marks #3:";
ip >> r1.marks[2];
cout << "marks #4:";
ip >> r1.marks[3];
cout << "marks #5:";
ip >> r1.marks[4];
return ip;
}
// operator >() - check if greater or not and return the value
accordingly
bool operator>(Report &r2)
{
if(getAvg() > r2.getAvg())
return true;
else
return false;
}
// operator <() - check if lesser or not and return the value
accordingly
bool operator<(Report &r2)
{
if(getAvg() < r2.getAvg())
return true;
else
return false;
}
// operator ==() - check for equality
bool operator==(Report &r2)
{
if(getAvg() == r2.getAvg())
return true;
else
return false;
}
// getters for each data member
int getAdno()
{
return adno;
}
string getName()
{
return name;
}
float getAvg()
{
return average;
}
// setters for each members
void setAdno(int ad)
{
adno = ad;
}
void setName(string nm)
{
name = nm;
}
void setMarks(float m1, float m2, float m3, float m4, float
m5)
{
marks[0] = m1;
marks[1] = m2;
marks[2] = m3;
marks[3] = m4;
marks[4] = m5;
}
void setAVG()
{
float sum =0;
for(int i=0; i<5; i++)
sum = sum + marks[i];
average = sum/5;
}
// operator ++()
float operator++()
{
return (average + 1.0);
}
// operator --()
float operator--()
{
return (average - 1.0);
}
};
int main(){
float d[5] = {90, 87, 53, 85, 93};
Report r1;
Report r2(6273, "James Smythe", d);
r1.setAdno(9933);
r1.setName("Pete Luckman");
// average of r1 in screenshot of question is also wrong .. check
it out
r1.setMarks(45, 78, 99, 72, 88);
r1.setAVG();
cout << "Display
r1\n===================================\n";
cout << " Student ID: " << r1.getAdno();
cout << "\n Student Name: " << r1.getName();
cout << "\n Student Average: " << r1.getAvg();
cout << "\n===================================\n\n";
cout << "Display
r2\n===================================\n";
cout <<r2;
cout << "\n===================================\n\n";
// copy constructor - copies object r2 data into object r1 - so ID
- 6273
// dont refer the screenshot mentioned in the question as it has
some errors
Report r3 = r2;
cout << "Enter the marks for r3...\n\n";
cin >>r3;
cout << "Thank you!";
cin.get();
cout << "\n\nDisplay
r3\n===================================\n";
cout <<r3;
cout << "\n===================================\n\n";
cout <<
"Comparisons...\n========================================\n";
cout << "Compare r2 == r3: "<< ((r2 == r3) ? "Same
average" : "Different average") << endl;
cout << "Compare r1 > r2: "<< ((r1 > r2) ? "r1 is
greater" : "r2 is greater or equal") << endl;
cout << "Compare r3 < r1: "<< ((r1 < r3) ? "r1 is
less" : "r3 is less or equal") << endl;
cout << "========================================\n\n";
cout << "\nAdd r1 and r2: " << r1 + r2 <<
endl;
cout << "\nIncrement r3: " << ++r3 << endl;
cout << "\nDecrement r2: " << --r2 << endl;
cout << "\n\n---------------\nEnd of program..." <<
endl;
return 0;
}
---------------------------------------------------------------------------
---------------------
OUTPUT ::
Define and implement a class, Report, that has these members Private members : adno 4 digit admission number nam string marks an array of 5 real values average average marks obtained Public members: D...