Question

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

Display ri Student ID 9933 Student Name: Pete Luckman Student Average: 85.4 Display r2 Student ID 6273 Student Name James Smy

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

  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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;
}

---------------------------------------------------------------------------

#include #include <iostream> <string> 1 4 using namespace std; 6 class Report private: int adno; string name; float marks[51;

// operator) adds the averages of 2 objects float operator+(Report &r2) 39 40 ▼ 41 42 43 return (getAvg) r2.getAvg()); // ope

// operator く() -check if lesser or not and return the value accordingly bool operator< (Report &r2) 76 78 79 80 81 82 83 84

120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 int main 142 143 144 145 146 147 148

152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 cout <<Display r1nn; cout << Student ID. くく---------------------

OUTPUT ::

Result... compiLed and executed in 12.42 sec(s) Display r1 Student ID: 9933 Student Name: Pete Luckman Student Average: 76.4

Thank you! Display r3 Student ID 6273 Student Name: James Smythe Student Average: 73.6 Comparisons... Compare r2r3: Different

Add a comment
Know the answer?
Add Answer to:
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...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT