Please send questions to
st10@humboldt.edu .
#include <iostream>
#include "sumArray.h"
#include "Dice.h"
using namespace std;
/***************************************************
Contract: main : void -> int
Purpose: playing with simple arrays, part 1
Examples: not really applicable
CS 131 - Lecture 9-2 - 10-22-03
By: Sharon M. Tuttle
last modified: 10-23-03 (this opening comment block! 8-) )
**************************************************/
int main()
{
// local variables
int desiredSize;
const int DICE_SET_SIZE = 5;
Dice setOfDice[DICE_SET_SIZE];
// what size of a number set is desired?
cout << "How many numbers shall be in the set? ";
cin >> desiredSize;
// now declare array of numbers of that size
double numSet[desiredSize];
// now, FILL it...
for (int i=0; i < desiredSize; i++)
{
numSet[i] = i/2.0;
}
// now, VIEW it...
for (int i=0; i < desiredSize; i++)
{
cout << "numSet[" << i << "]: " << numSet[i]
<< endl;
}
// now, show its SUM
cout << "sumArray returns: "
<< sumArray(numSet, desiredSize) << endl;
// now, let's play with setOfDice --- it has places
// for 5 Dice --- but no actual Dice IN there,
// yet... let's do so
for (int i=0; i < DICE_SET_SIZE; i++)
{
// create a 6-sided die "in" this array element
setOfDice[i] = Dice(6);
// look how I can call instance methods using
// the array reference...
cout << "die #" << (i+1) << " value: "
<< setOfDice[i].roll() << endl;
}
// let's declare a 2-d array
double twoD[10][5];
for (int i=0; i < 10; i++)
{
for (int j =0; j < 5 ; j++)
{
twoD[i][j] = i+j;
}
}
// print twoD's contents, 1 row per line
for (int i=0; i < 10; i++)
{
for (int j =0; j < 5 ; j++)
{
cout << " " << twoD[i][j];
}
// go to the next line AFTER each row
cout << endl;
}
return 0;
}