Using one- and two-dimensional arrays with functions.

Assignment Help Basic Computer Science
Reference no: EM13165313

Objective(Please do not post the whole code online, please send the code to my email([email protected])) 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).

 

 

Reference no: EM13165313

Questions Cloud

Write the code to implement the method : The "linked list" has a integer "position". In an array, the position is very easy to implement as it is related to the "index" of the array. In the "linked list", the position is much more difficult.
High-performing project teams : Describe what you believe are the four most important characteristics of high-performing project teams as being a wedding planner. Tell why you believe each is so critical, explain how they are related to each other, and give at least two specific ex..
Generates a random number between 1 and 100 : Write a program that generates a random number between 1 and 100 (inclusive) and then prompts the user to guess the number. The user should be given up to 10 chances to guess the number.
Prompt the user for and read 6 numbers : Write a program using an array that will store input data. Prompt the user for and read 6 numbers between 70 and 90. Verify the numbers should be greater than 70 and less than 90. If the number is less than or equal to 70 or greater than 90, repro..
Using one- and two-dimensional arrays with functions. : Objective using one- and two-dimensional arrays with functions.
Divide the network whose cidr address : Divide the network whose CIDR address is 165.221.204.0/25 into three subnets, with one subnet having half the addresses and the other two subnets having a quarter of the addresses each. Give the CIDR address of each subnet. How many addresses are ..
Probably not get the job : Was Benko’s remark that the plaintiff would “probably not get the job” when the plaintiff revealed her age sufficient evidence for a jury to find that the defendant stated reasons served as a pretext to hide discriminatory practice?
Make a class employee : Make a class EMPLOYEE with a name and salary. Make a class MANAGER inherit from EMPLOYEE. Add an instance field, named DEPARTMENT
Get to know your member : Follow the instructions in the text closely and use the Web sites provided to search for committee jurisdiction and to find your representative.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Using jflap construct a turing machine

Using JFLAP construct a turing machine that does integer division for numbers in unary notation. For example your machine should execute the calculation

  Find monthly break-even volume for company

Variable cost per pound of fertilizer is $0.15. Evergreen sells fertilizer for $0.40 per pound. Find out the monthly break-even volume for company.

  Page translation table for virtual memory system

Design a page translation table to meets the requirements of virtual memory system.

  Websites be required to adhere to section standards

what is the purpose then? Do you think that all websites should be required to adhere to Section 508 standards? Why or why not?

  Explaining stepwise refinement and refactoring

Are stepwise refinement and refactoring the equivalent thing ? If not, describe how do they vary? Term component is sometimes a difficult one to define.

  Copy and paste the code

Copy and paste the code below in a filename LastFirst_lab43.cpp (e.g. DoeJoe_lab43.cpp) and save it in Lab 4 folder. Bring in the LastFirst_lab43.cpp program from the Lab 3 folder.

  Solve problem and categorize it by using big-theta notation

Sometimes slight change in problem can significantly modify form of its solution. For instance, determine simple algorithm for solving following problem and categorize it using big-theta notation.

  Conduct observation used in business or organization

Conduct the observation to someone involved in procedure which is used in a business or organization. This person could be someone at university, in small business in your neighborhood.

  Storing and compiling a large amount of data

Because information systems are able to store and compile a large amount of data, many people worry that, their private data will end up in the wrong hands. Explain your position.

  Detection software automatically analyzes network traffic

What detection software automatically analyzes all network traffic. Assesses system vulnerabilities, recognizess any unauthorized access (intrusions).

  Application letter and resume

In this project, you will work with a fax cover sheet, an application letter, and a resume. To complete the project you will create a table, add text to a table, and format tables.

  Determining accurate formula using undetermined coefficients

Determine a more accurate formula for f'(t) using method of undetermined coefficients. Let's say the formula is of the form f'(t)= Af(t + 2h) + Bf(t + h) - Bf(t - h) - Af(t - 2h).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd