solutions15 - { int tosses; // count number of tosses int...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSCI-1100 Computer Science I Rensselaer Polytechnic Institute Spring 2004 Studio 15 -- Solutions 1. void weekname(int day) //PURPOSE: display name of week day for given day //PRECONDITIONS: 1 <= day <= 7, 1 = Sunday //POSTCONDITIONS: displays day name for given day { switch(day) { case 1: cout << "Sunday"; break; case 2: cout << "Monday"; break; case 3: cout << "Tuesday"; break; case 4: cout << "Wednesday"; break; case 5: cout << "Thursday"; break; case 6: cout << "Friday"; break; case 7: cout << "Saturday"; break; default: cout << "Invalid day."; } } 2. #include <iostream> #include "dice.h" using namespace std; int main () //PURPOSE: simulate tossing a coin //PRECONDITIONS: none //POSTCONDITIONS: displays number of heads and tails
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { int tosses; // count number of tosses int heads; // count number of heads int tails; // count number of tails int result; // result of a toss Dice coin(2); // create the coin to toss // initialize counters heads = 0; tails = 0; // simulate 10,000 tosses for (tosses=1; tosses&lt;=10000; tosses++) { result = coin.Roll(); if (result == 1) { heads = heads + 1; } else { tails = tails + 1; } } // display results cout &lt;&lt; &quot;After 10,000 tosses of the coin:&quot; &lt;&lt; endl; cout &lt;&lt; &quot;There were &quot; &lt;&lt; heads &lt;&lt; &quot; heads&quot; &lt;&lt; endl; cout &lt;&lt; &quot;There were &quot; &lt;&lt; tails &lt;&lt; &quot; tails&quot; &lt;&lt; endl; return 0; }...
View Full Document

Page1 / 2

solutions15 - { int tosses; // count number of tosses int...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online