Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //Class named Cash
- class Cash {
- //Private variables to store number of dollars and cents
- private:
- int numDollars;
- int numCents;
- public:
- //Mutator function to set number of dollars
- void setDollars(int numD) {
- numDollars = numD;
- }
- //Mutator function to set number of cents
- void setCents(int numC) {
- numCents = numC;
- }
- //Accessor function get number of dollars
- int getDollars() {
- return numDollars;
- }
- //Accessor function get number of cents
- int getCents() {
- return numCents;
- }
- double money() {
- double value = numDollars + (double)numCents/100;
- return (value);
- }
- };
- int main() {
- Cash myObj1;
- //Set dollars to 5
- myObj1.setDollars(5);
- cout<<"Object 1:"<< endl << "Num Dollars:"<< myObj1.getDollars()<<endl;
- cout<<"Amount of money: $" << myObj1.money() <<endl<<endl;
- Cash myObj2;
- //Set only cents to 20
- myObj2.setDollars(5);
- myObj2.setCents(20);
- cout<<"Object 2:"<<endl<<"Num Dollars:"<< myObj2.getDollars()<<" Num cents:"<< myObj2.getCents()<<endl;
- cout<<"Amount of money: $" << myObj2.money()<<endl<<endl;
- Cash myObj3;
- //Set dollars to 4 and cents to 50
- myObj3.setDollars(4);
- myObj3.setCents(50);
- cout<<"Object 3:"<<endl<<"Num Dollars:"<< myObj3.getDollars()<<" Num cents:"<< myObj3.getCents()<<endl;
- cout<<"Amount of money: $" << myObj3.money()<<endl<<endl;
- Cash myObj4;
- //Set dollars to 5 and cents to 80
- myObj4.setDollars(5);
- myObj4.setCents(80);
- cout<<"Object 4:"<<endl<<"Num Dollars:"<< myObj4.getDollars()<<" Num cents:"<< myObj4.getCents();
- cout<<endl<<"Amount of money: $" << myObj4.money();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement