One Other Thing (That I Need Help With)
|
|||
|
Rank: ? (2)
Member #: 29343 |
Please see my other post for my (not-so-great) backstory. Here's the assignment:
Write a C++ program involving operator overloading. I have started a class PIGS. You are to take what I have started and add: 1. 2 constructors 2. 6 operator overloading functions The default constructor in to create a white PIG of 200 pounds. The parameterized constructor is to fill in the color and size with the parameters passed. What you are to overload: 1. The binary + to add two PIG objects a. Add the two sizes b. Take the color of the first operand 2. The binary + to add a float to a PIG object a. Just add the number to the size 3. The binary + to add a PIG object to a float Just add the number to the size 4. The incrementing operator ++ (prefix) a. Just add one to the size--make it work like normal prefix 5. The incrementing operator ++ (postfix) a. Just added one to the size--make it work like normal postfix 6. The overloaded assignment operator += a. Just added the float to the size--should work like normal += THE CODE TO USE #include <iostream> #include <string> using namespace std; class PIGS {private: string color; float size; public: PIGS(); PIGS(string, float); // place declarations here }; int main() {PIGS p1, p2("BLACK",150),p3; cout << p1 << endl; cout << p2 << endl; cin >> p3; cout << p3 << endl; p3 = p2 + p1; cout << p3 << endl; cout << p2 << endl; cout << p1 << endl; p3 = p2 + 10.5; cout << p3 << endl; p3 = 11.6 + p2; cout << p3 << endl; p3 = p1++; cout << p3 << endl; cout << p1 << endl; p3 = ++p1; cout << p3 << endl; cout << p1 << endl; p1+=5.6; cout << p1 << endl; return 0; } Like before, since I'm totally lost, a detailed walkthrough would be GREATLY appreciated. Thanks for your time. Sincerely, Jason Seehusen |
||
|
Please login or register to post a reply.