Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You have been hired by Wally Wall\'s Wallet World to create a set of C++ classes

ID: 3826217 • Letter: Y

Question

You have been hired by Wally Wall's Wallet World to create a set of C++ classes for their new electronic wallet device. For the first phase, you are to write a C++ class named Wallet. Wally Wall expects that you will eventually be deriving other classes from your Wallet class, so you should design it appropriately. Here is what you know about the Wallet class: When a Wallet object is constructed, the user must provide a double representing the initial number of dollars in the wallet. (If the amount specified is negative, treat it as 0.) All wallets allow the user to determine whether the wallet has any money in it with an isEmpty() method. This method should return a bool that is true iff the amount of money in the wallet is zero. No derived class will ever determine the emptiness of the wallet in a different manner. All wallets have a deposit() method. This method allows the user to add more dollars to the wallet. It accepts a double parameter and adds that number of dollars to the amount already in the wallet. (If the amount is negative, treat it as 0.) The amount in a wallet can be determined by a value() method. This method takes no arguments and returns a double, the number of dollars currently in the wallet. (Notice there's no way to get your money out of the wallet. That's for Release 2.0...) Using your best style, write the class definition and method implementations for your Wallet. Be sure to use public, private, and const appropriately. Your answer must not contain the word protected. (You may continue onto the next page.)

Explanation / Answer

#include <iostream>
using namespace std;


class Wallet{
public:
double money;
public:
Wallet(double balance){
if(balance<0)// will update money as 0 if balance is in negative
{
money=0;
}
else
{
money=balance;
  
}
}
public:
void value();
void deposit(double);
bool isEmpty();
  
  
};
bool Wallet::isEmpty () {
if(money==0){
return true;
}
else
{
return false;
}
}
void Wallet::value () {
cout<<"The total amount in wallet:"<<money<<" ";
}

void Wallet::deposit(double amount) {
money=money+amount;
  
cout<<"The total amount in wallet after deposit:"<<money<<" ";
}

int main() {
double amount;
Wallet w1(280);
w1.value();
if(w1.isEmpty()){ // check wether wallet is empty or not
cout<<"wallet is empty"<<" ";
  
}
else{
cout<<"wallet is not empty"<<" ";
  
}
cout<<"enter the amount you want to deposit:"<<" ";
cin>>amount;
w1.deposit(amount);
   // your code goes here
   return 0;
}

Output:

sh-4.2$ main                                                                                                                                                                       
The total amount in wallet:280                                                                                                                                                     
wallet is not empty                                                                                                                                                                
enter the amount you want to deposit:                                                                                                                                              
204                                                                                                                                                                                
The total amount in wallet after deposit:484   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote