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

#ifndef WALLET H #define WALLET H #include class Wallet private: int id; int dol

ID: 3909209 • Letter: #

Question

#ifndef WALLET H #define WALLET H #include class Wallet private: int id; int dollars; int cents static int count; static int make id //unique wallet id //dollar value of this wallet //cent value of this wallet //current count of all wallets created //static function to get/increment count public: //constructors Wallet() Wallet (int d, int c) I/constructor. Sets dollars to d. Sets cents to c. Wallet (const Wallet &w;) //copy constructor //default constructor. Sets id. Sets dollars and cents to zero //getters int get dollars) const;//returns the current value of dollars int get_cents() const: //returns the current value of cents int get_id) const; //returns this wallet id //setters void set (int d,int c) //Sets dollars to d. Sets cents to c void set dollars (int d)://Sets dollars to d. void set cents(int c) //sets cents to c. void add(int d,int c) //Adds d to dollars. Adds c to cents void add dollars (int d)://Adds d to dollars. void add cents(int c) //Adds c to cents. void sub(int d,int c): /Subtracts d from dollars. Subtracts c from cents void subdollars (int d)://Subtracts d from dollars. void sub cents (int c) //Subtracts c from cents. /loverloaded operators friend std:tostream &operator;

Explanation / Answer

//wallet.cpp

#include "Wallet.h"
#include <iostream>

using namespace std;
//constructors
Wallet::Wallet(){
this->dollars = 0;
this->cents = 0;
}
//default constructor. Sets id. Sets dollars and cents to zero
Wallet::Wallet(int d, int c){
int val = 100*d + c;
this->dollars = val /100;
this->cents = val % 100;
} //constructor. Sets dollars to d. Sets cents to c.
Wallet::Wallet (const Wallet &w){
this->dollars = w.dollars;
this->cents = w.cents;
} //copy constructor
//getters
int Wallet::get_dollars() const{
return this->dollars;
}//returns the current value of dollars
int Wallet::get_cents() const{
return this->cents;
} //returns the current value of cents
int Wallet::get_id() const{
return this->id;
} //returns this wallet id
//setters
void Wallet:: set(int d, int c){
int val = 100*d + c;
this->dollars = val /100;
this->cents = val % 100;
} //Sets dollars to d-> Sets cents to c->
void Wallet:: set_dollars(int d){
this->dollars = d;
} //Sets dollars to d->
void Wallet:: set_cents (int c){
int val = this->dollars * 100 + this->cents;
this->dollars = val /100;
this->cents = val % 100;
} //Sets cents to c->
void Wallet:: add(int d, int c){
int val = (this->dollars+d) * 100 + (this->cents+c);
this->dollars = val /100;
this->cents = val % 100;
} // Adds d to dollars-> Adds c to cents->
void Wallet:: add_dollars (int d) {
int val = (this->dollars+d) * 100 + (this->cents);
this->dollars = val /100;
this->cents = val % 100;
}//Adds d to dollars->
void Wallet:: add_cents (int c){
int val = (this->dollars) * 100 + (this->cents+c);
this->dollars = val /100;
this->cents = val % 100;
} // Adds cto cents->
void Wallet:: sub(int d, int c){
int val = (this->dollars-d) * 100 + (this->cents-c);
this->dollars = val /100;
this->cents = val % 100;
} //Subtracts d from dollars-> Subtracts c from cents->
void Wallet:: sub_dollars(int d){
int val = (this->dollars-d) * 100 + (this->cents);
this->dollars = val /100;
this->cents = val % 100;
} //Subtracts d from dollars->
void Wallet:: sub_cents(int c){
int val = (this->dollars) * 100 + (this->cents-c);
this->dollars = val /100;
this->cents = val % 100;
}//Subtracts c from cents->
//overloaded operators
std::ostream & operator <<(std::ostream &stream, Wallet &W){
stream << "$" <<W.dollars <<"."<< W.cents << endl;
return stream;
}//cout &lt;&lt; myWallet;
bool Wallet::operator >(const Wallet &r){
return this->dollars > r.dollars && this->cents > r.cents;
}
//is this wallet greater than right wallet?
bool Wallet::operator <(const Wallet &r){
return this->dollars < r.dollars && this->cents < r. cents;
}//is this wallet less than right wallet?
bool Wallet::operator ==(const Wallet &r){
return this->dollars == r.dollars && this->cents == r. cents;
}//is this wallet equal to the right wallet?
Wallet Wallet::operator +(const Wallet &r){
this->dollars += r.dollars;
this->cents += r.cents;
} //add this wallet to right wallet-> return result wallet
Wallet Wallet::operator -(const Wallet &r){
this->dollars -= r.dollars;
this->cents -= r.cents;
}
//subtract right wallet from this wallet. return result wallet

//main_wallet.cpp

#include<stdio.h>
#include "Wallet.h"
#include <iostream>

using namespace std;
int main(){
Wallet w1 = Wallet(10,20);
std::cout << w1;
Wallet w2 = Wallet(11,20);
std::cout << w2;
std:;cout << w1 << w2;
w2.add(2,5);
w1.sub(1,90);
}