34 lines
1.4 KiB
Markdown
34 lines
1.4 KiB
Markdown
|
You prepared the cashier for the step to multiple cashiers. But let's not go there yet.
|
||
|
First you should flesh out the concept of a customer.
|
||
|
|
||
|
## Model
|
||
|
|
||
|
In our model the customer should have a list of items he buys, but you could add more things to make it more interesting.
|
||
|
For example some customers pack their items painfully slow and some really fast. So let's add that too.
|
||
|
So the scanning phase takes the amount of time of the item plus the packing-speed.
|
||
|
|
||
|
## Knowledge
|
||
|
|
||
|
For that we need a new language construct. The struct.
|
||
|
A struct works similar to an enum, but instead counting up numbers, you basically packing
|
||
|
multiple variables together to build more complex data-types.
|
||
|
|
||
|
Here is an example of a struct for a person:
|
||
|
|
||
|
typedef struct
|
||
|
{
|
||
|
char *Name; // This is some Text
|
||
|
int Age;
|
||
|
|
||
|
gender Gender; // This is an enum
|
||
|
}person;
|
||
|
|
||
|
If you want to access a member of the struct you write first the name of the variable containing the struct, then a dot and then the name of the member.
|
||
|
For example we have a variable Bob ``person Bob`` and want to assign him an age of 35 ``Bob.age = 35``.
|
||
|
|
||
|
Because the file got a little big, we pulled out some of the definitions like the enums into a
|
||
|
header file and included it with the command `#include "supermarket.h"`.
|
||
|
|
||
|
## Task
|
||
|
|
||
|
Your task is to implement a struct for the customer and take the packing speed into account.
|