CS120
Lab #5
Due at the end of lab.
In this lab you will be creating a structure to store information about
the player in your adventure game.
A structure combines multiple pieces of data into one program defined type.
So, you can make one data structure that includes an int (to store the amount of gold
collected), an array of characters (to store the player's name), a double (to store the
amount of health the player has left), etc. Then that collection of data can
be refered to by a single name.
The first part of the lab is to decide what data needs to be stored regarding
the character (health, money collected, lives left, astrological sign,
favorite movie, etc, etc). This part is almost completely up to you. However,
you should have at least three pieces of data, including one integer and one
array of characters.
Once you decide what pieces of data will go into your structure you
need to write a program that defines the structure and two functions to
test it:
- Initialization Function: this function should set the values of a new
copy of the structure that you have created. For example, if you created a
structure called adventurer, then the code:
struct adventurer player1;
player1 = initializeAdventurer();
creates a new structure called player1 (first line) and sets the initial
values (second line). The name of the structure and the function is up to
you.
Note that the initialization function can do things like ask the user for input
(for example the player's name) or generate random numbers (for example for
the player's statistics).
- Print Function: this function should take a structure as an argument
and print it in some reasonable format. That is the code:
print(player1);
should result in the details of the player1 structure being printed in a
way that is clear to the user/player.
-
The main part of the program should do several things:
- Define your structure.
- Create two variables of the type of your structure, for example create
a player1 struct and a player2 struct.
- Initialize both structures.
- Print both stuctures using the print function.
- Change some of the values in each of the structures - make the
changes different for the two strcutures..
- Reprint both stuctures using the print function to show that the values have
changed.
Turn in: Use the script command to generate the output of the
program.
Print and turn in a copy of the code and a copy of the output of the code.