[code]/Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:33:55: error: non-member function cannot have 'const' qualifier EnglishWeight operator - (EnglishWeight &subtract_ew) const { ^~~~~~ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:34:12: error: invalid use of 'this' outside of a non-static member function int p1 = this->pounds - subtract_ew.pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:34:39: error: 'pounds' is a private member of 'EnglishWeight' int p1 = this->pounds - subtract_ew.pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:14:9: note: declared private here int pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:35:12: error: invalid use of 'this' outside of a non-static member function int p2 = this->ounces - subtract_ew.ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:35:39: error: 'ounces' is a private member of 'EnglishWeight' int p2 = this->ounces - subtract_ew.ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:15:9: note: declared private here int ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:39:53: error: non-member function cannot have 'const' qualifier EnglishWeight operator / (EnglishWeight ÷_ew) const { ^~~~~~ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:39:15: error: overloaded 'operator/' must be a binary operator (has 1 parameter) EnglishWeight operator / (EnglishWeight ÷_ew) const { ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:40:16: error: no viable overloaded '=' if(divide_ew = 0) ~~~~~~~~~ ^ ~ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:12:7: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const EnglishWeight' for 1st argument class EnglishWeight { ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:43:14: error: invalid use of 'this' outside of a non-static member function int p1 = this.pounds / divide_ew.pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:43:38: error: 'pounds' is a private member of 'EnglishWeight' int p1 = this.pounds / divide_ew.pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:14:9: note: declared private here int pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:44:14: error: invalid use of 'this' outside of a non-static member function int p2 = this.pounds / divide_ew.ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:44:38: error: 'ounces' is a private member of 'EnglishWeight' int p2 = this.pounds / divide_ew.ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:15:9: note: declared private here int ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:62:14: error: read-only variable is not assignable if (number = 0) ~~~~~~ ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:91:50: error: non-member function cannot have 'const' qualifier EnglishWeight operator + (EnglishWeight &add_ew) const { ^~~~~~ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:92:12: error: invalid use of 'this' outside of a non-static member function int p1 = this.pounds + add_ew.pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:92:33: error: 'pounds' is a private member of 'EnglishWeight' int p1 = this.pounds + add_ew.pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:14:9: note: declared private here int pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:93:12: error: invalid use of 'this' outside of a non-static member function int p2 = this.ounces + add_ew.ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:93:33: error: 'ounces' is a private member of 'EnglishWeight' int p2 = this.ounces + add_ew.ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:15:9: note: declared private here int ounces; ^ 18 errors generated. [Finished in 0.3s with exit code 1][/code] |
|
|
|
|
|
|
|
|
EnglishWeight operator / (EnglishWeight ÷_ew) const; |
|
|
/Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:34:12: error: invalid use of 'this' outside of a non-static member function int p1 = this->pounds - subtract_ew.pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:34:39: error: 'pounds' is a private member of 'EnglishWeight' int p1 = this->pounds - subtract_ew.pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:14:9: note: declared private here int pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:35:12: error: invalid use of 'this' outside of a non-static member function int p2 = this->ounces - subtract_ew.ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:35:39: error: 'ounces' is a private member of 'EnglishWeight' int p2 = this->ounces - subtract_ew.ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:15:9: note: declared private here int ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:39:15: error: overloaded 'operator/' must be a binary operator (has 1 parameter) EnglishWeight operator / (EnglishWeight ÷_ew) { ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:40:16: error: no viable overloaded '=' if(divide_ew = 0) ~~~~~~~~~ ^ ~ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:12:7: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const EnglishWeight' for 1st argument class EnglishWeight { ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:43:14: error: invalid use of 'this' outside of a non-static member function int p1 = this->pounds / divide_ew.pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:43:39: error: 'pounds' is a private member of 'EnglishWeight' int p1 = this->pounds / divide_ew.pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:14:9: note: declared private here int pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:44:14: error: invalid use of 'this' outside of a non-static member function int p2 = this->pounds / divide_ew.ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:44:39: error: 'ounces' is a private member of 'EnglishWeight' int p2 = this->pounds / divide_ew.ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:15:9: note: declared private here int ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:62:14: error: read-only variable is not assignable if (number = 0) ~~~~~~ ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:72:12: error: invalid use of 'this' outside of a non-static member function int p1 = this->pounds + add_ew.pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:72:34: error: 'pounds' is a private member of 'EnglishWeight' int p1 = this->pounds + add_ew.pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:14:9: note: declared private here int pounds; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:73:12: error: invalid use of 'this' outside of a non-static member function int p2 = this->ounces + add_ew.ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:73:34: error: 'ounces' is a private member of 'EnglishWeight' int p2 = this->ounces + add_ew.ounces; ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.h:15:9: note: declared private here int ounces; ^ 15 errors generated. [Finished in 0.5s with exit code 1] |
EnglishWeight operator - (EnglishWeight &subtract_ew)
EnglishWeight EnglishWeight::operator-(EnglishWeight& subtract_ew)
if (number = 0)
|
|
/Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:40:16: error: invalid operands to binary expression ('EnglishWeight' and 'int') if(divide_ew == 0) ~~~~~~~~~ ^ ~ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:49:30: error: overloaded 'operator*' must be a unary or binary operator (has 3 parameters) EnglishWeight EnglishWeight::operator * (const EnglishWeight& mult_ew, const int number) { ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:55:30: error: overloaded 'operator*' must be a unary or binary operator (has 3 parameters) EnglishWeight EnglishWeight::operator * (const int number, const EnglishWeight& mult_ew) { ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:61:30: error: overloaded 'operator/' must be a binary operator (has 3 parameters) EnglishWeight EnglishWeight::operator / (const EnglishWeight& divide_ew, const int number) { ^ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:63:5: warning: expression result unused [-Wunused-value] false; ^~~~~ 1 warning and 4 errors generated. [Finished in 0.3s with exit code 1] |
EnglishWeight EnglishWeight::operator * (const int number, const EnglishWeight& mult_ew)
EnglishWeight:: |
EnglishWeight operator * (const int number, const EnglishWeight& mult_ew)
|
|
false;
doesnt do anything. Remember the function is suppose to return a type of EnglishWeight./Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:40:16: error: invalid operands to binary expression ('EnglishWeight' and 'int') if(divide_ew == 0) ~~~~~~~~~ ^ ~ /Users/renathomas/Documents/online_courses/C++Programming/Assignments/Assignment3/english_weights.cpp:63:5: warning: expression result unused [-Wunused-value] false; ^~~~~ 1 warning and 1 error generated. [Finished in 0.3s with exit code 1] |
|
|
|
|
|
|
In the English system of weights, we have pounds and ounces, with 1 pound equal to 16 ounces. Write a class to implement English weights. The type name of the class must be EnglishWeight. Declare the class in a header file called EnglishWeight.h and implement the class in separate file called EnglishWeight.cpp. Include appropriate constructors. Include new versions of the stream insertion and stream extraction operators appropriate to this class. Provide the following operators: EnglishWeight + EnglishWeight EnglishWeight - EnglishWeight EnglishWeight / EnglishWeight (this one takes some thought!) EnglishWeight * number number * EnglishWeight Englishweight / number Write a small test program in a file called EW_Driver.cpp to allow a user to enter two weights (in pounds and ounces) and a number. The program will output the results of the six operations described above. |
if(divide_ew == 0)
false;
part. I get that you have to take care of special situations like division by zero. Tell me with words what you want to happen if that happened, what is false;
suppose to represent, what did you think it would do? The thing is, if division by 0 occurs, you will have to return something. You can print out an error message but the return type has to be of type EnglishWeight.
|
|
double
. And that is not how to do division of the same type. For example: 12 feet 6 inches divided by 4 feet 0 inches is not 3.0 . So think about it like you are doing math with fractions. Same applies to all the math you do to your type.double
.getPounds
or getOunces
.
|
|
|
|
#include <cmath>