Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Exercise 13-2 Overloading Operators as Non-members Instructions Redo Programming Exercise 1 by overloading the operators as nonmembers of the class rectangleType. The header and

Programming Exercise 13-2 Overloading Operators as Non-members Instructions Redo Programming Exercise 1 by overloading the operators as nonmembers of the class rectangleType. The header and implementation file from Exercise 1 have been provided. Write a test program that tests various operations on the class rectangleType. 0.00 out of 10.00 Overloaded Operators 0 out of 5 checks passed. Review the results below for more details. Checks Unit TestIncomplete Overloading the + operator Build Status Build Failed Build Output In file included from /root/sandboxaab802fft-test-20e505df.cpp:2:0: /root/sandboxaab802ff/rectangleType.h:50:1: error: stray '\302' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ /root/sandboxaab802ff/rectangleType.h:50:2: error: stray '\251' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ In file included from /root/sandboxaab802ff/rectangleType.cpp:4:0, from /root/sandboxaab802fft-test-20e505df.cpp:3: /root/sandboxaab802ff/rectangleType.h:50:1: error: stray '\302' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ /root/sandboxaab802ff/rectangleType.h:50:2: error: stray '\251' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ In file included from /root/sandboxaab802fft-test-20e505df.cpp:2:0: /root/sandboxaab802ff/rectangleType.h:49:1: error: 'Contact' does not name a type Contact GitHub API Training Shop Blog About ^~~~~~~ make[2]: *** [CMakeFiles/runTests.dirt-test-20e505df.cpp.o] Error 1 make[1]: *** [CMakeFiles/runTests.dir/all] Error 2 make: *** [all] Error 2 Test Contents rectangleType rect1(12, 7); rectangleType rect2(4, 6); rectangleType rect3(16, 13); TEST(Addition, 0) { rectangleType temp = rect1 + rect2; ASSERT_EQ(temp, rect3); } Unit TestIncomplete Overloading the - operator Build Status Build Failed Build Output In file included from /root/sandboxaab802fft-test-8e9da8a5.cpp:2:0: /root/sandboxaab802ff/rectangleType.h:50:1: error: stray '\302' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ /root/sandboxaab802ff/rectangleType.h:50:2: error: stray '\251' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ In file included from /root/sandboxaab802ff/rectangleType.cpp:4:0, from /root/sandboxaab802fft-test-8e9da8a5.cpp:3: /root/sandboxaab802ff/rectangleType.h:50:1: error: stray '\302' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ /root/sandboxaab802ff/rectangleType.h:50:2: error: stray '\251' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ In file included from /root/sandboxaab802fft-test-8e9da8a5.cpp:2:0: /root/sandboxaab802ff/rectangleType.h:49:1: error: 'Contact' does not name a type Contact GitHub API Training Shop Blog About ^~~~~~~ make[2]: *** [CMakeFiles/runTests.dirt-test-8e9da8a5.cpp.o] Error 1 make[1]: *** [CMakeFiles/runTests.dir/all] Error 2 make: *** [all] Error 2 Test Contents rectangleType rect1(12, 7); rectangleType rect2(4, 6); rectangleType rect3(8, 1); TEST(Subtraction, 0) { rectangleType temp = rect1 - rect2; ASSERT_EQ(temp, rect3); } Unit TestIncomplete Overloading the ++ operator Build Status Build Failed Build Output In file included from /root/sandboxaab802fft-test-5bc5fea0.cpp:2:0: /root/sandboxaab802ff/rectangleType.h:50:1: error: stray '\302' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ /root/sandboxaab802ff/rectangleType.h:50:2: error: stray '\251' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ In file included from /root/sandboxaab802ff/rectangleType.cpp:4:0, from /root/sandboxaab802fft-test-5bc5fea0.cpp:3: /root/sandboxaab802ff/rectangleType.h:50:1: error: stray '\302' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ /root/sandboxaab802ff/rectangleType.h:50:2: error: stray '\251' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ In file included from /root/sandboxaab802fft-test-5bc5fea0.cpp:2:0: /root/sandboxaab802ff/rectangleType.h:49:1: error: 'Contact' does not name a type Contact GitHub API Training Shop Blog About ^~~~~~~ make[2]: *** [CMakeFiles/runTests.dirt-test-5bc5fea0.cpp.o] Error 1 make[1]: *** [CMakeFiles/runTests.dir/all] Error 2 make: *** [all] Error 2 Test Contents rectangleType rect1(12, 7); rectangleType rect2(4, 6); rectangleType rect3(13, 8); TEST(postIncrement, 0) { rect1++; ASSERT_EQ(rect1, rect3); } TEST(preIncrement, 1) { rectangleType temp = ++rect1; ASSERT_GE(temp, rect3); } TEST(preIncrement, 2) { ASSERT_GE(rect1, rect3); } Unit TestIncomplete Overloading the -- operator Build Status Build Failed Build Output In file included from /root/sandboxaab802fft-test-2ef752d3.cpp:2:0: /root/sandboxaab802ff/rectangleType.h:50:1: error: stray '\302' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ /root/sandboxaab802ff/rectangleType.h:50:2: error: stray '\251' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ In file included from /root/sandboxaab802ff/rectangleType.cpp:4:0, from /root/sandboxaab802fft-test-2ef752d3.cpp:3: /root/sandboxaab802ff/rectangleType.h:50:1: error: stray '\302' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ /root/sandboxaab802ff/rectangleType.h:50:2: error: stray '\251' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ In file included from /root/sandboxaab802fft-test-2ef752d3.cpp:2:0: /root/sandboxaab802ff/rectangleType.h:49:1: error: 'Contact' does not name a type Contact GitHub API Training Shop Blog About ^~~~~~~ make[2]: *** [CMakeFiles/runTests.dirt-test-2ef752d3.cpp.o] Error 1 make[1]: *** [CMakeFiles/runTests.dir/all] Error 2 make: *** [all] Error 2 Test Contents rectangleType rect1(12, 7); rectangleType rect2(4, 6); rectangleType rect3(3, 5); TEST(decrement, 0) { rect2--; ASSERT_EQ(rect2, rect3); } TEST(preDecrement, 1) { rectangleType temp = --rect2; ASSERT_LE(temp, rect3); } TEST(preDecrement, 2) { ASSERT_LE(rect2, rect3); } Unit TestIncomplete Overloading the == and != operator Build Status Build Failed Build Output In file included from /root/sandboxaab802fft-test-4bb4b7a0.cpp:2:0: /root/sandboxaab802ff/rectangleType.h:50:1: error: stray '\302' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ /root/sandboxaab802ff/rectangleType.h:50:2: error: stray '\251' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ In file included from /root/sandboxaab802ff/rectangleType.cpp:4:0, from /root/sandboxaab802fft-test-4bb4b7a0.cpp:3: /root/sandboxaab802ff/rectangleType.h:50:1: error: stray '\302' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ /root/sandboxaab802ff/rectangleType.h:50:2: error: stray '\251' in program 2017 GitHub, Inc. Terms Privacy Security Status Help ^ In file included from /root/sandboxaab802fft-test-4bb4b7a0.cpp:2:0: /root/sandboxaab802ff/rectangleType.h:49:1: error: 'Contact' does not name a type Contact GitHub API Training Shop Blog About ^~~~~~~ make[2]: *** [CMakeFiles/runTests.dirt-test-4bb4b7a0.cpp.o] Error 1 make[1]: *** [CMakeFiles/runTests.dir/all] Error 2 make: *** [all] Error 2 Test Contents rectangleType rect1(12, 7); rectangleType rect2(4, 6); rectangleType rect3(7, 12); TEST(NotEqual, 0) { ASSERT_FALSE(rect1 == rect2); } TEST(Equal, 1) { ASSERT_FALSE(rect1 != rect3); } Overloaded operators as non-member functions 0 out of 1 checks passed. Review the results below for more details. Checks Code PatternIncomplete Overloaded operators as non-member functions Description Searched your code for a specific pattern: friend\s+rectangleType+\s+operator+\W{1,} You can learn more about regular expressions [here](https://ruby-doc.org/core-2.1.1/Regexp.html). #include #include #include "rectangleType.h" using namespace std; void rectangleType::setDimension(double l, double w) { if (l >= 0) length = l; else length = 0; if (w >= 0) width = w; else width = 0; } double rectangleType::getLength() const { return length; } double rectangleType::getWidth()const { return width; } double rectangleType::area() const { return length * width; } double rectangleType::perimeter() const { return 2 * (length + width); } rectangleType::rectangleType(double l, double w) { setDimension(l, w); } rectangleType::rectangleType() { length = 0; width = 0; } rectangleType rectangleType::operator++() { //increment the length and width ++length; ++width; return *this; //return the incremented value of the object } rectangleType rectangleType::operator++(int u) { rectangleType temp = *this; //use this pointer to copy //the value of the object //increment the length and width length++; width++; #ifndef H_rectangleType #define H_rectangleType #include using namespace std; class rectangleType { //Overload the stream insertion and extraction operators friend ostream& operator>(istream&, rectangleType &); public: void setDimension(double l, double w); double getLength() const; double getWidth() const; double area() const; double perimeter() const; //Overload the arithmetic operators rectangleType operator + (const rectangleType &) const; rectangleType operator - (const rectangleType &) const; rectangleType operator * (const rectangleType&) const; //Overload the increment and decrement operators rectangleType operator ++ (); //pre-increment rectangleType operator ++ (int); //post-increment rectangleType operator -- (); //pre-decrement rectangleType operator -- (int); //post-decrement //Overload the relational operators bool operator == (const rectangleType&) const; bool operator != (const rectangleType&) const; bool operator = (const rectangleType&) const; bool operator > (const rectangleType&) const; //constructors rectangleType(); rectangleType(double l, double w); protected: double length; double width; }; #endif Contact GitHub API Training Shop Blog About 2017 GitHub, Inc. Terms Privacy Security Status Help

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Overloaded operators as non-member functions Overloaded operators as non-member functions Programming Exercise 13-2 Programming Exercise 13-2 \#ifndef H_rectangleType \#define H_rectangleType \#include using namespace std; class rectangleType \{ extraction operators friend ostream\& operator> (istream\&, public: void setDimension(double 1 , double w); double getLength() const; double getWidth() const; double area() const; double perimeter() const; Overloaded operators as non-member functions O out of 1 checks passed. Review the results below for more details. Checks Code Pattern - Incomplete > Overloaded operators as nonmember functions

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

4 What is specific in constructivist approach to group coaching?

Answered: 1 week ago

Question

What was the positive value of Max Weber's model of "bureaucracy?"

Answered: 1 week ago