CS120
Lab #14
These are only suggested practice exercises - they do not have to be turned in.
- Write a function to calculate the minimum, maximum, or average value
of an array. The function should be passed the array and an
integer representing the size of the array.
- Write the code to get an integer in the range 1-5 from the user. If the
integer is outside of this range the code should print an error message and
request a new number.
-
Write code that uses nested loops to print a 10x10 multiplication table.
- Create a class called creature that represents creatures in an
Artificial Life simulation. The data members of the class should include
the x, y, and heading of the creature represented as integers; and the current
energy of the creature represented by double. The heading stores a
value from 0-3 representing up, down, left, right. Write a
constructor that sets the x and y
to random values in the range -1000 to 1000, the heading to a
random value from 0-3, and the energy to 100.
Wrtie a print function that prints the position, heading, and energy of
a creature. Write a
move function that decreases the energy by 0.1 and changes the position
of the creature by 1 bases on it's heading.
- Write a swap() function that uses pass-by-reference to
swap the values if two integer arguments.
- Write a swap() function that uses pointers to
swap the values if two integer arguments.
- Using a node class create three nodes in main() and in main()
change their next pointers so that they are linked together in a short
linked list.
- Write a node function print() that prints a linked list from
beginning to end. Modify the function to print the linked list
in reverse order.
- For the exam you may want to practice going from decimal to binary to
hexadecimal and vice versa.
Turn in:
There is nothing to turn in.