In: Computer Science
A. Create a Dollar currency class with two integer attributes and one string attribute, all of which are non-public. The int attributes will represent whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equals 1 whole part. The string attribute will represent the currency name.
B. Create a CIS22C Dollar derived/inherited class with one additional non-public double attribute to represent the conversion factor from/to US Dollar.
C. In your two currency classes, add public methods for the following:
D. Create a Wallet class with one attribute - an array of two Dollar references / pointers and the following methods to demonstrate polymorphism of the currencies:
E. In your main:
Language C++
Here there four questions on above the given time very limited. plz make sure understand the given code.
cloud plz check the code for Dollar currency.
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class Dollar_currency
{
//Access specifier
private:
//Data members
int rupee, paisa;
string num1, num2;
public:
Dollar_currency(); //Default Constructor
Dollar_currency(int, int); //Parameterised Cosntructor
double getDOllar(); //Method to get USDdollar
int getReupee();
int getPaisa();
string getNum1();
void setReupee(int);
void setPaisa(int);
void setNum1(string);
void setNum2(string);
};
Dollar currency.cpp
#include "Dollar_Ccurrency.h"
#include<math.h>
//Default Constructor implementation
Dollar_currency::Dollar_currency()
{
this->rupee = 0;
this->paisa = 0;
this->num1 = "\0";
this->num2 = "\0";
}
Dollar_currency::Dollar_currency(int rupee, int paisa)
{
this->rupee = rupee;
this->paisa = paisa;
}
void Dollar_currency::setReupee(int rupee)
{
this->rupee = rupee;
}
void Dollar_currency::setPaisa(int paisa)
{
this->paisa = paisa;
}
void Dollar_currency::setNum1(string num1)
{
this->num1 = num1;
}
void Dollar_currency::setNum2(string num2)
{
this->num2 = num2;
}
double Dollar_currency::getDOllar()
{
double value = this->getPaisa();
double value1 = 0.01* value;
double ans = (double)this->getReupee() + value1;
//cout << this->getReupee << "." <<
this->getPaisa();
return ans;
}
int Dollar_currency::getReupee()
{
return this->rupee;
}
int Dollar_currency::getPaisa()
{
return this->paisa;
}
string Dollar_currency::getNum1()
{
int no1 = this->getReupee();
int last = no1 % 10;
no1 = no1 / 10;
string str1;
if (last == 1)
{
str1 = "One ";
}
else if (last == 2)
{
str1 = "Two ";
}
else if (last == 3)
{
str1 = "Three ";
}
else if (last == 4)
{
str1 = "Four ";
}
else if (last == 5)
{
str1 = "Five";
}
else if (last == 6)
{
str1 = "Six ";
}
else if (last == 7)
{
str1 = "Seven ";
}
else if (last == 8)
{
str1 = "Eight";
}
else if (last == 9)
{
str1 = "Nine ";
}
last = no1% 100;
string str2;
if (last == 1)
{
str2 = "Ten ";
}
else if (last == 2)
{
str2 = "Twenty";
}
else if (last == 3)
{
str2 = "Thirty ";
}
else if (last == 4)
{
str2 = "Forty ";
}
else if (last == 5)
{
str2 = "Fifty";
}
else if (last == 6)
{
str2 = "Sixty";
}
else if (last == 7)
{
str2 = "Seventy ";
}
else if (last == 8)
{
str2 = "Eighty";
}
else if (last == 9)
{
str2 = "ninety";
}
return (str2 +" "+ str1);
}
CIS22C Dolloar.h
#include "CIS22C_Dollar.h"
// Here the Default Constructor implementation must be takes place.
CIS22C _Dollar:: CIS22C _Dollar()
{
this->dollar = 0.0;
}
//Parameterised Cosntructor implementation
CIS22C _Dollar:: CIS22C _Dollar(int Ruppe,int Paise):Dollar_currency(Ruppe,Paise)
{
this->dollar=Dollar_currency::getDollar()*1.36;
}
//Copy Constructor implementation
CIS22C _Dollar:: CIS22C _Dollar(CIS22C _Dollar & cd)
{
this->dollar = cd.dollar;
}
CIS22C _Dollar::~ CIS22C _Dollar()
{
}
//+ operator overloaded implementation
CIS22C _Dollar CIS22C _Dollar::operator+( CIS22C _Dollar & cd)
{
CIS22C _Dollar cd1;
cd1.dollar = this->getDollar() + cd.getDollar();
return cd1;
}
CIS22C _Dollar CIS22C _Dollar::operator-( CIS22C _Dollar & cd)
{
CIS22C _Dollar cd1;
cd1.dollar = this->getDollar() - cd.getDollar();
return cd1;
}
double CIS22C Dollar::getDollar()
{
return this->dollar;
}
bool CIS22C _Dollar::greaterCurency(CIS22C _Dollar cd)
{
if (this->dollar > cd.dollar)
{
return true;
}
else
{
return false;
}
}
Main.cpp
#include" CIS22C _Dollar.h"
#include<string>
int main()
{
CIS22C _Dollar cd(10,25);
cout << "US dollar is: " << cd.getDOllar() << "
USD" << endl;
cout << "US Note: " << cd.getNum1() << " dollar"
<< endl;
cout << " CIS22C dollar is: " << cd.getDollar()
<< " CAD" << endl;
cout << endl;
cout << "Copy constructor: " << endl;
CIS22C _Dollar cd1(cd);
cout << " CIS22C dollar is: " << cd1.getDollar() << " CAD" << endl;
cout << endl;
cout << "2nd Oject Details:"
<< endl;
CIS22C _Dollar cd2(52, 20);
cout << "US dollar is: "
<< cd2.getDOllar() << " USD" << endl;
cout << "US Note: " << cd2.getNum1() << " dollar"
<< endl;
cout << " CIS22C dollar is: " << cd2.getDollar()
<< " CAD" << endl;
cout << endl;
CIS22C _Dollar cd3;
cd3 = cd2 + cd;
cout << "Addition of two objects is: " <<
cd3.getDollar() << endl;
CIS22C _Dollar cd4;
cd4 = cd2 - cd1;
cout << "Substraction of two objects is:
"<<cd4.getDollar()<<endl;
cout << "Object Comparision"
<< endl;
if (cd1.greaterCurency(cd2))
{
cout << "Object 1 is greater than object 2" <<
endl;
}
else
{
cout << "Object 2 is greater than object 1" <<
endl;
}
getch();
return 0;
}
plz make sure maintain some fix space while writting above programs
.
sorry for the inconvince i have not written th e code for the wallet class there is no time .
plz check the output for the above code .
Output:
US dollar is : 10.25 USD
US Note : Ten dollar
CIS22C dollar is : 13.94 C2D
Copy Constructor :
CIS22C dollar is : 13.94 C2D
2nd Object Details :
US dollar is : 52.2 USD
US Note : Fifty Two dollar
CIS22C dollar is : 70.992 C2D
Addition of two objects is : 84.932
Substraction of two objects : 57.052
Object Comparision
Object 2 is greater than Object 1
Please rate me ..It improves our community.. Thanks.