CS12, Lab 2

Week of April 8 – 12

 

 

This lab deals with compiling and running programs that span multiple files and contain a user-defined class.

 

After completing the lab, you should be comfortable with writing, compiling and running such a program in VisualC++.

 

In this lab you will also review electronic turning of assignments.

 

 

Topics:

 

·    Using user-defined types

·    Learning about a class from its header file

·    Assembling a project with multiple files

·    Proper use of #include statements

 

·    Electronic turnin

 

 

To do:

 

·    If you did not attend lab last week, complete lab1 first.

 

·    Download the files dice.h and dice.cpp

 

These are the header and implementation files for the Dice class described in the lecture.  Objects of the class simulate a six-sided die (singular of dice) that can be rolled to return a random number between 1 and 6, inclusive.  Other methods of the class are described in the file dice.h

 

·    Open a project and include both files in it.

·    Write a short main program in a separate file called lab2main.cpp. Your program should do the following:

 

1.   Declare a Dice object

2.   Roll the Dice object 5 times and print the result of each roll

3.   Change the number of sides of your Dice object to 25 using the appropriate class method (look in dice.h to find out which one).

4.   Roll the object once to get a random number n between 1 and 25.

5.   Roll the object n more times and print the result of each roll.

6.   Use one of the class methods to find the number of times that the object was rolled, and output the number of rolls.

.

·    Turn in the program electronically

 

Note: This is for turnin practice only. Your turned in project will not be looked at. You must show your work to the TA in lab to receive credit for your work.