Hello, everyone
I dont know if this is the right place to get some help with my assignment I'm working on these days. But since I dont know where else to get some help, I hope you guys can help me out.
The assignment I'm working on is to build a vending machine with some specific requirements. The vending machine exchanges notes to coins and the machine must accept notes with the following values (50,100, 200, 500) and exchange it to coins (10,20).
The specific requirements are:
1) The vending machine must be modeled by using a struct "indhold". This must record the number of coins using integer variables, a member variable of type "indhold" represent the coins back in the machine. When the machine is created, it must not include some coins or anything. It's a good idea to ensure that the coin reserve is being initialized properly.
2) However, it should be possible for the owner to fill up the reserve currency - therefore created a function which takes an enum type and an integer as an argument: void addCoins (coinType c, int number). Separate the vending machine so that exchange machine structure is in a (h - file) and functionality in a (cpp file).
3) The owner would like to be able to tell at any given time how many coins to exchange that is left in the machine. Make a member function void print (), which prints to the screen, how many coins are left in the machine. (It may be the second printing operation - which takes a content structure - as an argument).
4) Define a class "Automat" and place the struct "indhold" in the class together with the 2 functions addCoins and print.
5) To convert the vending machine to perform any work - it is necessary to give it a note and print the correct number of coins. Assume that you always have the correct number coins and implement the function void exchange (note type s), where the note type is a enumerator. Calculate the number of coins needed, in a helping function called calculate (int amount). Remember that "indhold" is part of the class "Automat's" scope and calls named approach from outer parts. The exchange function, must print the amount of each coin is returned (paid) on the screen.
6) Change the "udRegn" function so that it throws an exception, if there is enough coins of the correct size back in the machine to make the exchange. This is done by defining and throwing a struct notEnoughMoney without members who are in private in the "Automat" class. Catch the exception in the exchange ()-function and treat it sensible.... Hint: Three 20's is not enough to convert one "halvtredser" - if there are no more 10's back.
7) Unfortunately, not all people are honest - counterfeiters are now replaced by criminals who produces counterfeit notes (eg photocopied). Add INVALID seddelType and let the machine give an appropriate error message, if this type of note is introduced in the machine.
- The given code is:
1. #include "Automat.h"
2.
3. int main()
4. {
5. Automat m;
6. m.print();
7. m.add_coins( TYVE, 1 );
8. m.add_coins( TI, 3 );
9. m.print();
10. m.veksel(FEMTI);
11. m.print();
12. m.add_coins( TYVE, 3 );
13. m.veksel(INVALID);
14. m.veksel(FEMTI);
15. m.print();
16. m.add_coins( TYVE, 3 );
17. m.change(EN_HUND);
18. m.print();
19. }
I'm having problems understanding the function (question 2) they want us to create which takes an enum type and an integer as an argument.
#include <iostream>
using namespace std;
struct indhold
{
int Ti = 10;
int Tyve = 20;
};
int main()
{
};
I write in English because I have difficulty expressing myself in Danish.I hope you guys don't mind.