Question
#include #include #include #include using namespace std; class ReviewType { public: ReviewType(); // Default Constructor ReviewType(string, int); // Parameterized Constructor ReviewType(const ReviewType&); // Copy Constructor
#include
#include
#include
#include
using namespace std;
class ReviewType
{
public:
ReviewType(); // Default Constructor
ReviewType(string, int); // Parameterized Constructor
ReviewType(const ReviewType&); // Copy Constructor
~ReviewType(); // Destructor
// TODO: Implement the greater than operator overload as a member
function.
bool operator>(const ReviewType&) const;
// TODO: Implement the less than operator overload as a member
function.
bool operator
// TODO: Implement the equality operator overload as a member
function.
bool operator==(const ReviewType&) const;
// TODO: Just for practice implementing a NON-MEMBER function,
implement
// the not-equal operator overload as a NON-MEMBER function.
friend bool operator!=(const ReviewType& first, const ReviewType&
second) const;
bool isGreater(const ReviewType&) const;
bool isLess(const ReviewType&) const;
bool isEqual(const ReviewType&) const;
bool isNotEqual(const ReviewType&) const;
string getBookName();
void printInfo();
private:
int generateRating();
string bookName;
int numberOfRatings;
int sumOfRatings;
int *arrayPointer;
};
// Default Constructor
ReviewType::ReviewType()
{
bookName = "Default";
numberOfRatings = 0;
sumOfRatings = 0;
arrayPointer = NULL;
}
// Parameterized Constructor
ReviewType::ReviewType(string bookName, int numOfRatings)
{
this->bookName = bookName;
if (numOfRatings > 0)
{
this->numberOfRatings = numOfRatings;
arrayPointer = new int[numberOfRatings];
for (int i = 0; i
{
arrayPointer[i] = generateRating();
sumOfRatings += arrayPointer[i];
}
}
}
// Copy Constructor
ReviewType::ReviewType(const ReviewType &other)
{
this->bookName = other.bookName;
this->numberOfRatings = other.numberOfRatings;
this->sumOfRatings = other.sumOfRatings;
if (numberOfRatings > 0)
{
arrayPointer = new int[numberOfRatings];
for (int i = 0; i
arrayPointer[i] = other.arrayPointer[i];
}
}
// The array pointer might be NULL if the book has
// 0 ratings. If the book has more than 0 ratings,
// the dynamically allocated memory will be deleted
// when an instance of the ReviewType class goes
// out of scope.
ReviewType::~ReviewType()
{
if (arrayPointer != NULL)
delete[] arrayPointer;
}
bool ReviewType::isGreater(const ReviewType &other) const
{
return sumOfRatings > other.sumOfRatings;
}
bool ReviewType::isLess(const ReviewType &other) const
{
return sumOfRatings
}
bool ReviewType::isEqual(const ReviewType &other) const
{
return sumOfRatings == other.sumOfRatings;
}
bool ReviewType::isNotEqual(const ReviewType &other) const
{
return sumOfRatings != other.sumOfRatings;
}
string ReviewType::getBookName()
{
return bookName;
}
void ReviewType::printInfo()
{
cout
cout
cout
cout
for (int i = 0; i
cout
cout
}
// For simplicity, a user rating is simulated with a
// random number between 1 and 10.
int ReviewType::generateRating()
{
return (rand() % 10) + 1;
}
///////////////////////////////////////////////////////////////
/// Please do not change any of the code above this line. ///
///////////////////////////////////////////////////////////////
/// Write your operator overload implementations here:
////////////////////////////////////////////////////////////////
/// After completing your operator overload implementations, ///
/// you may uncomment the statements in main that use the ///
/// overloads, but other than uncommenting those lines, ///
/// please don't change any of the code in main. ///
////////////////////////////////////////////////////////////////
int main()
{
srand(time(NULL));
ReviewType book1("Book 1", 12);
ReviewType book2("Book 2", 12);
book1.printInfo();
book2.printInfo();
cout
if (book1.isGreater(book2))
cout
book2.getBookName()
if (book1.isEqual(book2))
cout
book2.getBookName()
if (book1.isLess(book2))
cout
book2.getBookName()
if (book1.isNotEqual(book2))
cout
book2.getBookName()
cout
// the above tests don't make use of the operator overloads.
Uncomment the code below to
// test your operator overload implementations.
/*
cout
if (book1 > book2)
cout
book2.getBookName()
if (book1 == book2)
cout
book2.getBookName()
if (book1
cout
book2.getBookName()
if (book1 != book2)
cout
book2.getBookName()
*/
cout
return 0;
}
These are your specific tasks: 1) Following the design in the class header, overload the> operator as a member function. True is 2 Following the design in the class header, overload the operator as a member function. True is 3) Following the design in the class header, overload theoperator as a member function. True is 4) returned if this sumOtRatings is greater than the parameter object's sumOlKatings. Else false returned if this sumOtRatings is less than the parameter object's sumQtRatings. Else false. returned if this sumOfRatings is equal to the parameter object's sumORatings. Following the design in the class header, overload the-operator as a NON-MEMBER function. True is returned if one sumQtRatings is not equal to another sumOfRatines Note the word friend in the class header and the use of two parameters instead of one. Sample Output: Because the ratings are randomized, your output will be slightly different. um of Ratings: 12 um of Ratings: 58 Ratings: 86 10 6 13632131 Book 2 Book Name um of Ratings: 12 Sum of Ratings: 55 Ratings: 513267383665 OT USING OPERATOR OVERLOADING.. Book 1 S iorse than Book 2 Book 1 and Book 2 are NOT equally liked SING OPERATOR OVERLOADING Book 1 is worse than Book 2 Book 1 and Book 2 are NOT equally liked ress any key to cont inueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started