Question

In: Computer Science

A. Create a Dollar currency class with two integer attributes and one string attribute, all of...

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.

  • The value of the conversion factor can be defaulted in the class definition based on 1 USD = 1.36 C2D or 1 C2D = 0.74 USD.
  • Also, 1000 of C2D fractional parts equals 1 C2D whole part.

C. In your two currency classes, add public methods for the following:

  • Default Construction (i.e. no parameters passed)
  • Construction based on parameters for all attributes
  • Copy Constructor and/or Assignment, as applicable to your programming language of choice
  • Destructor, as applicable to your programming language of choice
  • Setters and Getters for all attributes
  • Adding two objects of the same currency
  • Subtracting one object from another object of the same currency
  • Comparing two objects of the same currency for equality/inequality
  • Comparing two objects of the same currency to identify which object is larger or smaller
  • Print method to print details of a currency object
  • In your derived class only, methods to convert USD objects to C2D and vice versa

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:

  • A default Constructor which sets
    • the first element of the array to a zero value Dollar object
    • the second element of the array to a zero value CIS22C Dollar object
  • A Destructor, as applicable to your programming language of choice
  • Methods to add or subtract
    • USD objects to/from the first element only and
    • C2D objects to/from the second element only
  • Methods to compare if the value of either element is greater or smaller than an input value
  • A method to Print the values of the two elements in the Wallet

E. In your main:

  • Create a Wallet object
  • Provide the user a main menu to add/ subtract/ compare the Dollar and CIS22C Dollar values in the Wallet as well as print the contents of the Wallet
  • You can use a second level menu choice to allow the user to select currency type
  • Based on user choice, create either UD or C2d objects as needed to perform the desired operations.
  • The main menu should be run in a loop until the user selects the Exit option
  • There is no sample output - you are allowed to provide user interactivity as you see fit and programs will be graded for clarity of interaction

Language C++

Solutions

Expert Solution

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.


Related Solutions

Needs to be done in PYTHON A. Create a Dollar currency class with two integer attributes...
Needs to be done in PYTHON 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...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string...
In C++ Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string • speed : float Create a FigherPlane class that inherits from the Airplane class and adds the following attributes: • numberOfMissiles : short
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score (int). A constructor expects a name as a parameter. A method getLevel to get the level(char) of the student. score level table: A: score >= 90 B: score >= 80 and < 90 C: score >= 60 and < 80 D: score < 60 Example:          Student student = new Student("Zack"); student.score = 10; student.getLevel(); // should be 'D'. student.score = 60; student.getLevel(); //...
Create a Class to contain a customer order Create attributes of that class to store Company...
Create a Class to contain a customer order Create attributes of that class to store Company Name, Address and Sales Tax. Create a public property for each of these attributes. Create a class constructor without parameters that initializes the attributes to default values. Create a class constructor with parameters that initializes the attributes to the passed in parameter values. Create a behavior of that class to generate a welcome message that includes the company name. Create a Class to contain...
PYTHON PLEASE: Construct a class “Monster” with the following attributes: self.name (a string) self.type (a string,...
PYTHON PLEASE: Construct a class “Monster” with the following attributes: self.name (a string) self.type (a string, default is ‘Normal’) self.current_hp (int, starts out equal to max_hp) self.max_hp (int, is given as input when the class instance is created, default is 20) self.exp (int, starts at 0, is increased by fighting) self.attacks (a dict of all known attacks) self.possible_attacks (a dictionary of all possible attacks) The dictionary of possible_attacks will map the name of an attack (the key) to how many...
Add the following private attributes: String publisher String title String ISBN String imageName double price Create...
Add the following private attributes: String publisher String title String ISBN String imageName double price Create getter/setter methods for all data types Create a constructor that takes in all attributes and sets them Remove the default constructor Override the toString() method and return a String that represents the book object that is formatted nicely and contains all information (attributes) In the main class: Create a main method that throws FileNotFoundException Import java.io libraries Import java.util.Scanner Create a loop to read...
public class Main{ public static void main (String[] args) { Map<Integer, String> ssnMap = new HashMap<Integer,...
public class Main{ public static void main (String[] args) { Map<Integer, String> ssnMap = new HashMap<Integer, String>(); ssnMap.put (8675309,"Jenney"); ssnMap.put (42, "Answer to Everything"); ssnMap.put (8675309, "Stacy"); ssnMap.put (1006, "Peter"); System.out.println(ssnMap.get (8675309)); } } What is the output of the above code. Why?
The Person Class Uses encapsulation Attributes private String name private Address address Constructors one constructor with...
The Person Class Uses encapsulation Attributes private String name private Address address Constructors one constructor with no input parameters since it doesn't receive any input values, you need to use the default values below: name - "John Doe" address - use the default constructor of Address one constructor with all (two) parameters one input parameter for each attribute Methods public String toString() returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as...
Create a class that calls for user to input a string. Pass the string from that...
Create a class that calls for user to input a string. Pass the string from that class to another and count how many words the string has, count how many vowels are in the string and count how many letters end with d. java language
Details: Create a class called CompareArrays that determines if two specified integer arrays are equal. The...
Details: Create a class called CompareArrays that determines if two specified integer arrays are equal. The class should have one static methods: public static boolean compare(int[] arrayOne, int[] arrayTwo) – Which compares the two arrays for equality. The two arrays are considered equal if they are the same size, and contain the same elements in the same order. If they are equal, the method should return true. Otherwise, the method should return false. NOTE: You are not allowed to use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT