473,657 Members | 2,612 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 alternativesPle ase
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 9053
On 2007-03-11 11:29, ar*****@gmail.c om 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.c om 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
3096
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
5028
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
2653
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 it differently. FOUR QUESTIONS: The background: I got three (3) files
3
3076
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 before rowID answID qryrow questionID datafield 1591 12 06e 06e 06e question 1593 12 06f 06f 06f question 1594 12 answer to the question 06f
10
3418
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 database or continue to process on to the next page. I am now trying to learn ASP to see if we can replace some of our applications that were written in php with an ASP alternative. However, after doing many searches on google and reading a couple...
10
3710
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 Error in '/QuickStartv20' Application. -------------------------------------------------------------------------------- Configuration Error Description: An error occurred during the processing of a configuration file
53
4057
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
4750
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
4271
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 less to more for example). I have a question object that has two properties that contain the collections Options and Ratings. now I want this kind of layout: --- Rating1 Rating2 Rating3 Option 1 () () ...
3
2547
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 class="not-required-question"><p>Question Text</p><input /></div>
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2726
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 we have to send another system
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.