Computers and Technology

IN C++ A. Create an abstract base class called Currency with two integer attributes, both 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.
B. Create one derived class - Money - with two additional non-public string attributes which will contain the name of the currency note (Dollar) and currency coin (Cent) respectively. DO NOT add these attributes to the base Currency class.
C. In your base Currency class, add public class (C++ students are allowed to use friend methods as long as a corresponding class method is defined as well) methods for the following, where appropriate:
Default Construction (i. e. no parameters passed)
Construction based on parameters for all attributes - create logical objects only, i. e. no negative value objects allowed
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 - the result should be logical, i. e. negative results are not allowed
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
All of the above should be instance methods and not static.
The add and subtract as specified should manipulate the object on which they are invoked. It is allowed to have overloaded methods that create ane return new objects.
D. In your derived Money class, add new methods or override inherited methods as necessary, taking care that code should not be duplicated or duplication minimized. Think modular and reusable code.
E. Remember -
Do not define methods that take any decimal values as input in either the base or derived classes.
Only the print method(s) in the classes should print anything to console.
Throw String (or equivalent) exceptions from within the classes to ensure that invalid objects cannot be created.
F. In your main:
Declare a primitive array of 5 Currency references (for C++ programmers, array of 5 Currency pointers).
Ask the user for 5 decimal numbers to be input - for each of the inputs you will create one Money object to be stored in the array.
Once the array is filled, perform the following five operations:
Print the contents of the array of objects created in long form, i. e. if the user entered "2.85" for the first value, it should be printed as "2 Dollar 85 Cent".
Add the first Money object to the second and print the resulting value in long form as above.
Subtract the first Money object from the third and print the resulting value in long form as above.
Compare the first Money object to the fourth and print whether both objects are equal or not using long form for object values.
Compare the first Money object to the fifth and print which object value is greater than the other object value in long form.
All operations in the main should be performed on Currency objects demonstrating polymorphism.
Remember to handle exceptions appropriately.
There is no sample output - you are allowed to provide user interactivity as you see fit.

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 09:00, vetterk1400
Design a class tictactoe that: holds the following information about the game: two-dimensional array (3 by 3), and winner. add additional variables as needed. includes the functions to perform the various operations on objects. for example, function to print the board, getting the move, checking if move is valid, determining if there is a winner after each move. add additional operations as needed. includes constructor(s). write the functions of the class, and write a program that uses the class. the program should declare an object of type tictactoe. the program will create the board and store it in the array. the program will allow two players to play the tic-tac-toe game. after every valid move update the array, check if there is a winner. if there is no winner and no tie, then print the board again to continue.
Answers: 2
image
Computers and Technology, 23.06.2019 18:00, joybeth9591
What can a word user do with the customize ribbon dialog box? check all that apply. minimize the ribbon add a new tab to the ribbon remove a group from a tab add a group to a tab choose which styles appear choose which fonts appear choose tools to appear in a group
Answers: 1
image
Computers and Technology, 24.06.2019 00:50, anthonycraig0205
3. what is the output of the following statements? temporary object1; temporary object2("rectangle", 8.5, 5); temporary object3("circle", 6, 0); temporary object4("cylinder", 6, 3.5); cout < < fixed < < showpoint < < setprecision(2); object1.print(); object2.print(); object3.print(); object4.print(); object1.set("sphere", 4.5, 0); object1.print();
Answers: 1
image
Computers and Technology, 24.06.2019 13:00, CarlosParker99
Think of a spreadsheet as a giant calculator spread of paper chart data collector
Answers: 2
Do you know the correct answer?
IN C++ A. Create an abstract base class called Currency with two integer attributes, both of which...

Questions in other subjects: