Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Objective(Please do not post the whole code online, please send the code to my email(812932219@qq.com)) thanks!!!!!!!!

In this lab, you will practise using one- and two-dimensional arrays with functions. In the last lab,

#3, drawCard() was one of the key functions you implemented and was used to simulate drawing

a card randomly out from a full deck of playing cards. This process is commonly referred to as

'sampling with replacement'.

Since a card is randomly drawn from a full deck each time, each of the 13 'ranks' { from ace to king

{ should be equally likely, and we expect an even distribution over many trials. We can also expect

an even distribution of cards from the four suits (spades, hearts, diamonds, and clubs).

In this lab, we will investigate how good our drawCard() function is at simulating a truely random

deck by running many trials and storing the outcome of our experiments in arrays that will allow

making subsequent analysis easier.

2 Part 1 | Histogram for drawCard() results

Write a program, lab4Cards1.c, that prompts the user for the number of cards to be drawn, and

then prints out the cards and displays a tally of the results according to rank. Below is a sample

output for 45 cards:

Enter the number of cards to draw: 45

Cards drawn:

Q 5 6 J 4 Q 8 4 6 X J J Q 4 9 A 5 7 Q 6 6 5 K 5 K K Q Q 7 6 9 5 8 Q

4 6 3 4 2 8 Q 4 4 4 5

Histogram (#occurances by rank):

A ( 1) *

2 ( 1) *

3 ( 1) *

4 ( 8) ********

5 ( 6) ******

6 ( 6) ******

7 ( 2) **

8 ( 3) ***

9 ( 2) **

X ( 1) *

J ( 3) ***

Q ( 8) ********

K ( 3) ***

2.1 Notes on Part 1

You need not worry about inserting newlines when printing the drawn cards. Simply continue

to print each character separated by a space until the end.

Assume that the number entered by the user is valid and will be low enough (say, below 700)

that the nal histogram will appear as expected (without any lines wrapping around, etc.).

For full marks, drawCard(), must conform to the original specication and should have the

prototype: char drawCard(void)

In developing your program, really try to exploit the power of arrays. Suggestions include the

following:

Array variables: A 13-element array of integers { call it cardCount[] for now { that can be

used to keep track of the number of occurances of each rank (i.e., from ace to king). Also

consider how a constant, global, character array

const char RankCharacters[13]=f'A','2','3','4','5','6','7','8','9','X','J','Q','K'g;

provides a convenient mapping between the representation of each rank as output by the

drawCard() function and the index to be used in other arrays like cardCount[].

Functions: Create a function that takes the character output from drawCard() and updates

cardCount[]. Also create a separate function that takes cardCount[] and produces the nal

histogram. Remember to test each new function separately before adding them to the main

program (even an existing function like drawCard() should be retested).

After you get the program working, you are ready to explore how uniform the distribution of

cards by rank is using drawCard(). Trying dierent sample sizes, do you nd the output in

fact uniform? If not, does drawCard() seem to exhbit a bias towards certain cards?

3 Part 2 | Extending program to include card suits

We want to extend the program in Part 1 to now keep track of both suit and rank. Each card will

now be represented by a character for the rank and a number from 0 to 3 to represent the suit (see

legend below). The nal results will be presented without histogram bars, but now in a 4x13 array

to show how many times each card was drawn. Below is the corresponding output for 45 cards:

Enter the number of cards to draw: 45

Cards drawn (0:Spades, 1:Hearts, 2:Diamonds, 3:Clubs)

Q1 62 40 82 61 J1 Q2 93 51 Q0 61 K1 K1 Q2 73 92 83 41 31

21 Q0 40 51 33 X1 A1 50 22 40 J3 A2 70 41 80 61 91 71 22

60 61 Q2 41 33 60 42

Card tally:

A 2 3 4 5 6 7 8 9 X J Q K Total (by suit)

Spades 0 0 0 3 1 2 1 1 0 0 0 2 0 10

Hearts 1 1 1 3 2 4 1 0 1 1 1 1 2 19

Diamonds 1 2 0 1 0 1 0 1 1 0 0 3 0 10

Clubs 0 0 2 0 0 0 1 1 1 0 1 0 0 6

3.1 Notes on Part 2

To minimize the modications needed to Part 1, we can simulate the determination of the suit

by randomly selecting a number from 0 to 3.

This time, you will present the total number of cards drawn from each suit.

After you get your program working, you can explore how uniform the distribution of cards

by suit. You can also readily generate other statistics from the data (for example, the total

number of face cards across all four suits).

 

 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9455431

Have any Question?


Related Questions in Computer Engineering

Two countries australia and france have their interest

Two Countries Australia and France have their interest rates to be 8% and 2 %, respectively. If their currencies trade according to 2 Australian $s buy one euro in the spot market, what will their future spot rate be in ...

The following table records the number of days the stock

The following table records the number of days the stock market recorded the following outcomes: # of Days NASDAQ Up NASDAQ Down NASDAQ Unchanged DJIA Up 30 15 4 DJIA Down 10 40 3 DJIA Unchanged 3 5 2 What is the probabi ...

How can word processing software give a person the ability

How can Word Processing software give a person the ability to better position themself or a business, in today's society? Why?

A restaurant offers a 12 dinner special that has 7 choices

A restaurant offers a? $12 dinner special that has 7 choices for an? appetizer, 13 choices for an? entrée, and 4 choices for a dessert. How many different meals are available when you select an? appetizer, an? entrée, an ...

Question suppose users share a 3 mbps link through circuit

Question : Suppose users share a 3 Mbps link through circuit switching. Also suppose each user requires 150 kbps when transmitting, but each user transmits only 10 percent of the time. a) How many users can be supported? ...

The literature on honeypots or so called fake networks to

The literature on honeypots or so called "fake networks" to attract hackers and attackers frequently mentions "entrapment" as one of the legal issues that must be considered. How of a concern is entrapment? What are some ...

Writing a research paperprepare a research paper on

Writing a Research Paper Prepare a research paper on Antisocial Personality Disorder. In this project, you will modify a research paper. You will add and format text and format the document using themes and paragraph for ...

Salesthe sales department is in a unique position customers

Sales The sales department is in a unique position: customers seek out Thermo-Chem because it has cornered the market with virtually no competition except in the chemicals market. Therefore, only limited sales effort is ...

Strengths and weaknesses of university that attracts and

Strengths and Weaknesses of University that attracts and distracts students from joining that university with respect to the theory of planned behaviour

C programmingnbsphelp with a program positivec that include

***C PROGRAMMING***  Help with a program positive.c that include the following function: Void extract(int *a, int n, int *positive, int *size);  The function should use pointer arithmetic, not subscripting. The extract f ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As