Advertisement
homeworkhelp111

Money

Oct 18th, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //Class named Cash
  5. class Cash {
  6.     //Private variables to store number of dollars and cents
  7.     private:
  8.         int numDollars;
  9.         int numCents;
  10.    
  11.     public:
  12.         //Mutator function to set number of dollars
  13.         void setDollars(int numD) {
  14.             numDollars = numD;
  15.         }
  16.        
  17.         //Mutator function to set number of cents
  18.         void setCents(int numC) {
  19.             numCents = numC;
  20.         }
  21.        
  22.         //Accessor function get number of dollars
  23.         int getDollars() {
  24.             return numDollars;
  25.         }
  26.        
  27.         //Accessor function get number of cents
  28.         int getCents() {
  29.             return numCents;
  30.         }
  31.        
  32.         double money() {
  33.             double value = numDollars + (double)numCents/100;
  34.             return (value);
  35.         }
  36. };
  37.  
  38. int main() {
  39.     Cash myObj1;
  40.     //Set dollars to 5
  41.     myObj1.setDollars(5);
  42.     cout<<"Object 1:"<< endl << "Num Dollars:"<< myObj1.getDollars()<<endl;
  43.     cout<<"Amount of money: $" << myObj1.money() <<endl<<endl;
  44.    
  45.     Cash myObj2;
  46.     //Set only cents to 20
  47.     myObj2.setDollars(5);
  48.     myObj2.setCents(20);
  49.     cout<<"Object 2:"<<endl<<"Num Dollars:"<< myObj2.getDollars()<<" Num cents:"<< myObj2.getCents()<<endl;
  50.     cout<<"Amount of money: $" << myObj2.money()<<endl<<endl;
  51.    
  52.     Cash myObj3;
  53.     //Set dollars to 4 and cents to 50
  54.     myObj3.setDollars(4);
  55.     myObj3.setCents(50);
  56.     cout<<"Object 3:"<<endl<<"Num Dollars:"<< myObj3.getDollars()<<" Num cents:"<< myObj3.getCents()<<endl;
  57.     cout<<"Amount of money: $" << myObj3.money()<<endl<<endl;
  58.    
  59.     Cash myObj4;
  60.     //Set dollars to 5 and cents to 80
  61.     myObj4.setDollars(5);
  62.     myObj4.setCents(80);
  63.     cout<<"Object 4:"<<endl<<"Num Dollars:"<< myObj4.getDollars()<<" Num cents:"<< myObj4.getCents();
  64.     cout<<endl<<"Amount of money: $" << myObj4.money();
  65.    
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement