473,503 Members | 10,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question

The 36 possible outcomes of rolling two dice.


7.18 What does the following program do?

1 // Ex. 7.18: Ex07_18.cpp
2 // What does this program do?
3 #include <iostream>
4 using std::cout;
5 using std::endl;
6
7 int whatIsThis( int [], int ); // function prototype
8
9 int main()
10 {
11 const int arraySize = 10;
12 int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
13
14 int result = whatIsThis( a, arraySize );
15
16 cout << "Result is " << result << endl;
17 return 0; // indicates successful termination
18 } // end main
19
20 // What does this function do?
21 int whatIsThis( int b[], int size )
22 {
23 if ( size == 1 ) // base case
24 return b[ 0 ];
25 else // recursive step
26 return b[ size - 1 ] + whatIsThis( b, size - 1 );
27 } // end function whatIsThis

7.19 Modify the program of Fig. 6.11 to play 1000 games of craps. The
program should keep track of the statistics and answer the following
questions:
--------------------------------------------------------------------------------

[Page 394]
How many games are won on the 1st roll, 2nd roll, ..., 20th roll, and
after the 20th roll?

How many games are lost on the 1st roll, 2nd roll, ..., 20th roll, and
after the 20th roll?

What are the chances of winning at craps? [ Note: You should discover
that craps is one of the fairest casino games. What do you suppose
this means?]

What is the average length of a game of craps?

Do the chances of winning improve with the length of the game?

7.20 ( Airline Reservations System) A small airline has just purchased
a computer for its new automated reservations system. You have been
asked to program the new system. You are to write a program to assign
seats on each flight of the airline's only plane (capacity: 10 seats).

Your program should display the following menu of alternativesPlease
type 1 for "First Class" and Please type 2 for "Economy". If the
person types 1, your program should assign a seat in the first class
section (seats 1-5). If the person types 2, your program should assign
a seat in the economy section (seats 6-10). Your program should print
a boarding pass indicating the person's seat number and whether it is
in the first class or economy section of the plane.

Use a one-dimensional array to represent the seating chart of the
plane. Initialize all the elements of the array to 0 to indicate that
all seats are empty. As each seat is assigned, set the corresponding
elements of the array to 1 to indicate that the seat is no longer
available.

Your program should, of course, never assign a seat that has already
been assigned. When the first class section is full, your program
should ask the person if it is acceptable to be placed in the economy
section (and vice versa). If yes, then make the appropriate seat
assignment. If no, then print the message "Next flight leaves in 3
hours".

7.21 What does the following program do?

1 // Ex. 7.21: Ex07_21.cpp
2 // What does this program do?
3 #include <iostream>
4 using std::cout;
5 using std::endl;
6
7 void someFunction( int [], int, int ); // function prototype
8
9 int main()
10 {
11 const int arraySize = 10;
12 int a[ arraySize ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
13
14 cout << "The values in the array are:" << endl;
15 someFunction( a, 0, arraySize );
16 cout << endl;
17 return 0; // indicates successful termination
18 } // end main
19
20 // What does this function do?
21 void someFunction( int b[], int current, int size )
22 {
23 if ( current < size )
24 {
25 someFunction( b, current + 1, size );
26 cout << b[ current ] << " ";
27 } // end if
28 } // end function someFunction


--------------------------------------------------------------------------------

[Page 395]
7.22 Use a two-dimensional array to solve the following problem. A
company has four salespeople (1 to 4) who sell five different products
(1 to 5). Once a day, each salesperson passes in a slip for each
different type of product sold. Each slip contains the following:

The salesperson number

The product number

The total dollar value of that product sold that day

Thus, each salesperson passes in between 0 and 5 sales slips per day.
Assume that the information from all of the slips for last month is
available. Write a program that will read all this information for
last month's sales and summarize the total sales by salesperson by
product. All totals should be stored in the two-dimensional array
sales. After processing all the information for last month, print the
results in tabular format with each of the columns representing a
particular salesperson and each of the rows representing a particular
product. Cross total each row to get the total sales of each product
for last month; cross total each column to get the total sales by
salesperson for last month. Your tabular printout should include these
cross totals to the right of the totaled rows and to the bottom of the
totaled columns.

7.23 ( Turtle Graphics ) The Logo language, which is popular among
elementary school children, made the concept of turtle graphics
famous. Imagine a mechanical turtle that walks around the room under
the control of a C++ program. The turtle holds a pen in one of two
positions, up or down. While the pen is down, the turtle traces out
shapes as it moves; while the pen is up, the turtle moves about freely
without writing anything. In this problem, you will simulate the
operation of the turtle and create a computerized sketchpad as well.

Use a 20-by-20 array floor that is initialized to zeros. Read commands
from an array that contains them. Keep track of the current position
of the turtle at all times and whether the pen is currently up or
down. Assume that the turtle always starts at position (0, 0) of the
floor with its pen up. The set of turtle commands your program must
process are shown in Fig. 7.33.

Figure 7.33. Turtle graphics commands.
(This item is displayed on page 396 in the print version) Command
Meaning

1
Pen up

2
Pen down

3
Turn right

4
Turn left

5,10
Move forward 10 spaces (or a number other than 10)

6
Print the 20-by-20 array

9
End of data (sentinel)

Mar 11 '07 #1
2 8987
On 2007-03-11 11:29, ar*****@gmail.com wrote:
The 36 possible outcomes of rolling two dice.
There are alwyas people out there looking for good exercises so it was
kind of you to post some here, but it might be more useful if you could
post a solution too.

--
Erik Wikström
Mar 11 '07 #2
ar*****@gmail.com wrote:
[long problem set]
The answer is, "do your own homework". This applies equally whether
those were assigned to you in a class or you assigned them to yourself.
You only learn programming by doing. Reading solutions posted here will
help you very little.

Take those one at a time, work on them, post your solution. Follow the
FAQ instructions on how to post. Then you will learn.


Brian
Mar 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3083
by: Mohammed Mazid | last post by:
Can anyone please help me on how to move to the next and previous question? Here is a snippet of my code: Private Sub cmdNext_Click() End Sub Private Sub cmdPrevious_Click() showrecord
3
4996
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
2628
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
3058
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
3389
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
3682
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
4020
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
4695
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
4252
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from...
3
2538
by: Zhang Weiwu | last post by:
Hello! I wrote this: ..required-question p:after { content: "*"; } Corresponding HTML: <div class="required-question"><p>Question Text</p><input /></div> <div...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7294
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7361
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3183
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.