473,320 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 8914
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
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
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
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
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
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
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
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
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
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
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
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.