
Assignment Three: Classes and ArraysHomeworks are due at the beginning of class on the due date. This homework will produce a program that functions in a form that could actually be used to do something useful (unlike the last two homeworks.) Follow the instructions carefully, and get started early, because this is due on Friday, so you don't have very long for it. In this homework, you are pretending to be a rabid tama-gucci(TM) collector. (or did I mean avid?) Tama-guccis(TM) are toys made of leather and come from Italy. Each toy has a name, an integer from one to one hundred that indicates how healthy it is, and a similar integer that indicates how happy it is. Finally it has a floating point number that states its current value in US$. Being a rabid collector, you decided that you need a cataloging program to store all of the information about all of your tama-guccis(TM). This is that program. To write this program you will need two data structures. The first is a tama-gucci class to store the information about each of the tama-guccis(TM) in your collection. The second is an array that holds all of the tama-gucci information. Finally there should be a nice interface to your program. Each of these steps is described in detail below. The tama-gucci(TM) classThis class should be very simple. It should have a member variable for each attribute for the tama-gucci(TM). You can assume that all tama-gucci(TM) names are less than 30 characters. Be careful because the class will need to store the name, not just a pointer to the name.The variables should have accessor functions, which allow you to set their values, and something to read them. The tama-gucci(TM) arrayWhile you can have a set size for the array, we want anyone to be able to use our program, so it would be nice to have the array be of any size. To do this, he first thing the user will do is tell the program how many tama-guccis(TM) they have. Then the program will allocate an array of that size on the heap (aka the free store) using new. The syntax for this is TamaGucci * theArray = new TamaGucci[inSizeOfArray];You will need to create a loop to allow the user to initialize each of the variables for every tama-gucci(TM) in turn. Don't forget to use your accessor functions. The user interfaceThe main part of your program should have two parts, the initialization part, and the use part. The initialization part is described above. The use part should be a loop which asks you what information you want on your tama-gucci(TM) collection. That loop should look something like this:
// Create and initialize the array first.
char theAnswer = 'a'; // Gets us into the loop
while (theAnswer != 'q')// keep giving choices until the user is done.
{
cout << "Would you like to see: " << endl
<< " a) The total value." << endl
<< " b) The average value." << endl
<< " c) The average happiness." << endl
<< " d) The average health." << endl
<< " q) Exit the program." << endl;
cin >> theAnswer; // Get the user's choice.
// Call a different function depending on the choice:
You will need to write the functions that take the array and get out
the necessary information from the tama-gucci(TM) classes. A sample
run of the program should look something like:
Hello! Welcome to tama-gucci tabulator! Please tell me how many tama-guccis(TM) you have: 3 Please enter the name of tama-gucci(TM) 1: Fred Please enter the happiness of Fred: 27 Please enter the health of Fred: 54 Please enter the value of Fred (in US$): 45.67 Please enter the name of tama-gucci(TM) 1: Bob Please enter the happiness of Bob: 37 Please enter the health of Bob: 56 Please enter the value of Bob (in US$): 12.03 Please enter the name of tama-gucci(TM) 1: Chef Please enter the happiness of Chef: 100 Please enter the health of Chef: 22 Please enter the value of Chef (in US$): 123.45 Would you like to see: a) The total value. b) The average value. c) The average happiness. d) The average health. q) Exit the program. a The total value is: $181.15 Would you like to see: a) The total value. b) The average value. c) The average happiness. d) The average health. q) Exit the program. q Thanks for supporting tama-gucci(TM), We're working harder, so no one else will!So just to recap the user interface, you should write these functions:
You should feel free to allow the user to access your array in other ways if you want to. |