Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

Wayne State University Operator Overloading C++ Programming Code

Wayne State University Operator Overloading C++ Programming Code

Wayne State University Operator Overloading C++ Programming Code

Description

Instructions

Make sure your Assignment 1’s class* contains at least one (1) numeric attribute (int, float, double). If it does not, add a numeric attribute to your class.

Define the behavior of the following operators in your class’ objects:

  • Two objects of that class are considered equal (==) if …
  • The sum (+) of two objects of that class returns …
  • When passing one object of that class to cout operator, it displays …

Using those definitions, modify your class to overload those operators. In the corresponding operator overloading function add a comment that explains the operator functionality (i.e. the definition of each operators)

In the main program

Create three objects of your Assignments 1’s class and demonstrate that ==, +, and cout operators works as expected when using them with your class’ objects.

Submission

Files to submit:

  • Visual Studio solution/project files.
  • Class files (.h and .cpp)
  • Main program (.cpp)

Submit the Visual Studio project in a zip folder.

Example of expected submission

Note: the Solution/project files are not presented in this examples since those are automatically generated by Visual Studio. However, those are expected in students’ submission.

GroupCohesiveness.h

#include <iostream>

class GroupCohesiveness {
private:
int answer0, answer1, answer2, answer3;
public:
void setAnswer0(int a);
void setAnswer1(int a);
void setAnswer2(int a);
void setAnswer3(int a);
int getAnswer0() const;
int getAnswer1() const;
int getAnswer2() const;
int getAnswer3() const;
float getGroupCohesiveness() const;
bool operator==(const GroupCohesiveness& survey2) const;
GroupCohesiveness operator+(const GroupCohesiveness& survey2) const;
friend ostream& operator<<(ostream& os, const GroupCohesiveness& survey);
GroupCohesiveness();
GroupCohesiveness(int a0, int a1, int a2, int a3);
~GroupCohesiveness();
};

GroupCohesiveness.cpp

#include "GroupCohesivness.h"

void GroupCohesivness::setAnswer0(int a) {
if (a>=1 && a<=5) answer0=a;
}
void GroupCohesivness::setAnswer1(int a) {
if (a>=1 && a<=5) answer1=a;
}
void GroupCohesivness::setAnswer2(int a) {
if (a>=1 && a<=5) answer2=a;
}
void GroupCohesivness::setAnswer3(int a) {
if (a>=1 && a<=5) answer3=a;
}
int GroupCohesivness::getAnswer0() const {
return answer0;
}
int GroupCohesivness::getAnswer1() const {
return answer1;
}
int GroupCohesivness::getAnswer2() const {
return answer2;
}
int GroupCohesivness::getAnswer3() const {
return answer3;
}
float GroupCohesivness::getGroupCohesiveness() const {
return (answer0+answer1+answer2+answer3)/4.0;
}
// Two objects of that class are considered equal (==) if all the answers are the same
bool GroupCohesivness::operator==(const GroupCohesiveness& survey2) const {
return answer0==survey2.answer0 && answer1==survey2.answer1 && answer2==survey2.answer2 && answer3==survey2.answer3;
}
// The sum (+) of two objects of that class returns a new objects whose answers are the average of the 2 operand's GroupCohesiveness answers.
GroupCohesiveness GroupCohesivness::operator+(const GroupCohesiveness& survey2) const {
GroupCohesiveness temp;
temp.answer0=(answer0+survey2.answer0)/2;
temp.answer1=(answer1+survey2.answer1)/2;
temp.answer2=(answer2+survey2.answer2)/2;
temp.answer3=(answer3+survey2.answer3)/2;
return temp;
}
// When passing one object of that class to cout operator, it displays the answers of the surveys enclosed by parentheses.
friend ostream& operator<<(ostream& os, const GroupCohesiveness& survey) {
os << "(" << survey.answer0 << "," << survey.answer1 << "," << survey.answer2 << "," << survey.answer3 << ")";
return os;
}
GroupCohesiveness::GroupCohesiveness() {
answer0=1;
answer1=1;
answer2=1;
answer3=1;
}
GroupCohesiveness::GroupCohesiveness(int a0, int a1, int a2, int a3) {
answer0=a0;
answer1=a1;
answer2=a2;
answer3=a3;
}
GroupCohesiveness::~GroupCohesiveness() {
cout << "A Group Cohesiveness object has been removed from memory.";
}

Main.cpp

main() {
GroupCohesiveness surveyA(1,2,3,2);
GroupCohesiveness surveyB(3,5,4,3);
GroupCohesiveness surveyC;
surveyC=surveyA;

if (surveyA==surveyB)
cout << "Survey A and Survey B are equal" << endl;
else
cout << "Survey A and Survey B are not equal" << endl;
if (surveyA==surveyC)
cout << "Survey A and Survey C are equal" << endl;
else
cout << "Survey A and Survey C are not equal" << endl;
cout << "The average of Survey A and Survey B is: ";
GroupCohesiveness temp;
temp = surveyA+surveyB;
cout << temp << endl;
}

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Eminence Papers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Eminence Papers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Eminence Papers are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Eminence Papers, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20