Make a class called Wallet. Wallet must hold the following 2 public attributes: int moneyAmt string owner Include 2 constructors, 1 default constructor and a 2-arg constructor in the order of amt then owner (see examples). The default constructor must assign the values 0, and "No Funds" to moneyAmt and owner, respectively. You must also add code to Wallet so that the following code will compile and compare 2 Wallet objects with the greater-than operator so that the Wallet with a greater moneyAmt is greater than the one with a lesser amount. Should both Wallet objects have the same amount, the one with the greater owner name is greater. For instance Wallet kar(9, "Karl"), al(9, "Alice"); In the above, kar must compare as greater than al. In other words, the following expression must be true: kar > al Also, Wallet must be able to compare not equals. Two Wallet objects are not equal if their moneyAmt and owner are different Examine the code in the main template and make it work without changing it. You may change it to test, but ensure you load the template and submit that to ensure everything is working as expected and that the output test passes. You only need add code to Wallet.h and Wallet.cpp

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Make a class called Wallet. Wallet must hold the following 2 public attributes:
int moneyAmt
string owner
Include 2 constructors, 1 default constructor and a 2-arg constructor in the order of amt then owner (see examples). The default constructor must assign the values 0, and "No Funds" to moneyAmt and owner, respectively.

You must also add code to Wallet so that the following code will compile and compare 2 Wallet objects with the greater-than operator so that the Wallet with a greater moneyAmt is greater than the one with a lesser amount. Should both Wallet objects have the same amount, the one with the greater owner name is greater. For instance

Wallet kar(9, "Karl"), al(9, "Alice");

In the above, kar must compare as greater than al. In other words, the following expression must be true:
kar > al

Also, Wallet must be able to compare not equals. Two Wallet objects are not equal if their moneyAmt and owner are different

Examine the code in the main template and make it work without changing it. You may change it to test, but ensure you load the template and submit that to ensure everything is working as expected and that the output test passes.

You only need add code to Wallet.h and Wallet.cpp

Hints. Examine the code to determine which operators need to be overloaded. If you overload more than 2 operators, you are doing too much. The string class has overloaded all boolean operators to work as alphabetical order.

 

main.cpp:

#include<iostream>
#include<string>
using namespace std;

#include "Wallet.h"

int main()
{

 


//ALL of the following code must work and output:
/*
Normal relationship
different
Zoe is first, then Alvin
*/


//Examine the code so you can know what must work.
//You can change this to test, but ensure you refresh the template before submitting

Wallet reg, poor(2, "Pennywise"), rich(27734, "Goldman"), owes(-3, "Borrower");
Wallet *first = new Wallet(50, "Zoe"), *second = new Wallet(50, "Alvin");


if( poor > rich)
   cout << "Something wrong";
else
   cout << "Normal relationship";

cout << endl;

if(owes != reg)
   cout << "different";
else
   cout << "Something wrong";
   
cout << endl;

if(*first > *second)  //this must evaluate to true since both have 50, but Zoe is after Alvin alphabetically
   cout << first->owner << " is first, then " << second->owner;
else
   cout << "Something not correct, Zoe should be first";
cout << endl;

 

return 0;

}

 

wallet.h:

#include<string>
using namespace std;


//finish the Wallet class prototype

class Wallet
{
 public:
   int moneyAmt;
   string owner;
   
};

 

Wallet.cpp:

#include "Wallet.h"

//Implement any Wallet methods here

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY