A machine with demands

Tags:    c++

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:
Fold kodeboks ind/udKode 


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.
Fold kodeboks ind/udKode 


I write in English because I have difficulty expressing myself in Danish.I hope you guys don't mind.





6 svar postet i denne tråd vises herunder
2 indlæg har modtaget i alt 8 karma
Sorter efter stemmer Sorter efter dato
Question 2 is stating that the owner of the machine can fill up the machine with coins (the currency the machine spits out). So question two is saying that you should create a function which takes an enum type (Is it a 10 or 20 coin?) and an integer value (How any of the given coin is he showing in?).

So in short the function should act like this:

Fold kodeboks ind/udKode 


Above code should not compile, but should be able to give you the idea about what is meant by question 2. Hope it helped.

/ Mads



You declared the function as private u should have declared it public in your .h file.
Fold kodeboks ind/udKode 


the statement "private:", "public:" and "protected:" defines the accesibility of subsequent elements in your class declaration.

public means they can be called on instances of the class.

private means only instances of the class or subclass can call the element internally.

protected means only instances of the class can call the element internally.



Indlæg senest redigeret d. 25.10.2010 20:09 af Bruger #5620
This is probably better using the enum values:
Fold kodeboks ind/udKode 


Also if no one actually made the enum u would need to do that too.

As i recall this is done like this:
enum coinType {TI=10, TYVE=20};




Thanks to both of you.
I've worked on it and found some help from a previous post. But the program keeps coming up with an error. What am I doing wrong?
Fold kodeboks ind/udKode 


I'm getting these errors
Fold kodeboks ind/udKode 


And any idea about how I can make the void exchange (note type s) and calculate (int amount) (question 5)?




Ohhh I see, now I get it :)

I've tried to make the exchange (note type s) function, but in that I also have to make a helping function called calculate (int amount). And that is where I get a bit confused.

Main.cpp (machine)
Fold kodeboks ind/udKode 


Automat.h
Fold kodeboks ind/udKode 


Automat.cpp
Fold kodeboks ind/udKode 


Exchange (note type s)
Fold kodeboks ind/udKode 


How can I make the Calculate function so that it give some sense?



I have now figured out how to solve the problem, but thanks for your help anyway :)




t