Tutorial 10 Question 2a, 2b, 2c by Kapilesh Ramesh.

Slides:



Advertisements
Similar presentations
Position and Direction By Chris Clements Euro 2012.
Advertisements

7B Unit 3 Finding your way Integrated skills. Millie is walking across the road.Millie is walking along the road.Sandy is walking over the bridge.Kitty.
The following 5 questions are about VOLTAGE DIVIDERS. You have 20 seconds for each question What is the voltage at the point X ? A9v B5v C0v D10v Question.
Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.
SNFS: The design and implementation of a Social Network File System Ch. Kaidos, A. Pasiopoulos N. Ntarmos, P. Triantafillou University of Patras.
Internal Auditing in the Government of Ontario, Canada Stuart Campbell, CIA, CGA, CISA Director, Internal Audit Government of Ontario, Canada.
Probability and Conditional Probability. Probability Four balls What is the probability of choosing the ball in the red box? Since there are four balls.
How many wavelengths are represented in each figure below?
1H NMR Chemical shift (δ) depends on molecular structure and solvent
Site Planning LA 222 King Abdulaziz University
1 Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure Definitions 10.3Initializing Structures 10.4Accessing.
Black Jack in Objective-C
Combinations Examples
Example from Wang group Work of Jiasheng Lu. Starting material.
1 Linked List Demo Node third = new Node(); third.item = "Carol"; third.next = null; Node second = new Node(); second.item = "Bob"; second.next = third;
Case Study: Focus on Structures Math 130 Lecture 21 B Smith: 10/04: Required 35 minutes to complete. 15 minutes was spent returning test 2 and completing.
2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure.
2008 Pearson Education, Inc. All rights reserved Pointers and Pointer-Based Strings.
C Programming Lecture 23 Enumeration Types Structures.
Programming in C Chapter 10 Structures and Unions
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 7.9Arrays of Pointers Arrays can contain pointers For.
2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Bits, Characters, Strings, and Structures Outline 16.1Introduction 16.2Structure Definitions.
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
Mock Objects. Unit-testing and TDD are challenging They require some effort to: – Write a test for a small functionality – Refactor production code and.
Directions: Form into Teams (up to 7 team members) Clear your tables and move chairs against the wall Only 4 people will participate per iteration Four.
15.7 Probability Day 3. There are 2 nickels, 3 dimes, and 5 quarters 1.) Find the probability of selecting 1 nickel, 1 dime, and 1 quarter in that order.
Error Detection / Correction Hamming code. Why might we need Error detection/correction? Even & Odd Parity — Error detection Hamming code — Used for error.
A New Paradigm for Inter-Domain Traffic Engineering Adrian Farrel Juniper Networks
Economics (H) Chapter 1 Review Game Factors of Production Production Possibilities Goods & Services Productivity & Growth Value & Wealth MISC
Microsoft Office Grade 10 A / B Cahaya Bangsa Classical School (C) 2010 Digital Media Production Facility 14 Microsoft Excel – 05.
1 Performance Monitoring A Guide for Larger Local Councils (First Draft)
Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]
(8) I. Word Processing Package (Mail Merge) Ex: MS Word, Open Office II. Spread sheet package (function) Ex: MS Excel III. Presentation software (picture,
Organic Chemistry Functional Groups This slide show will cycle on its own through all of the ochemlab functional groups and the ochem substituents. It.
Compiler Construction LR(1) Rina Zviel-Girshin and Ohad Shacham School of Computer Science Tel-Aviv University.
Figure S1 – Calibration curve SEC ideal mode Protein Quantitation using various modes of HPLC l Grotefend, Kaminski, Wroblewitz, El Deeb, Kühn, Reichl,
Click on the Schedule 1 tab.
EXAMPLES. Example 1: Write a Java method that performs addition on two binary numbers. Each binary number is kept in an integer array
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 7 - Pointers Outline 7.1Introduction 7.2Pointer.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 10 - C Structures, Unions, Bit Manipulations,
 2000 Prentice Hall, Inc. All rights reserved. Chapter 7 - Pointers Outline 7.1Introduction 7.2Pointer Variable Declarations and Initialization 7.3Pointer.
CS 106 Introduction to Computer Science I 11 / 08 / 2006 Instructor: Michael Eckmann.
o Simulate a deck of playing cards o Shuffle the deck o Deal (5) cards into the hand o Turn over the first card o The user must guess whether the next.
o Simulate a deck of playing cards o Shuffle the deck o Deal 5 cards into the hand o Turn over the first card o The user must guess whether the next card.
Refreshing Your Skills for Chapter 10.  If you flip a coin, the probability that it lands with heads up is 1/2.  If you roll a standard die, the probability.
Networking Basics lesson 17. This lesson includes the following sections: The Uses of a Network How Networks are Structured Network Topologies for LANs.
Algorithms. What is an algorithm?  An algorithm is a clear, concise, and correct step- by-step sequence of actions.
A Semantic Error in Google last weekend! Someone in Google typed an extra ‘/’ character into their URL List Link to CNN video report posted on Collab.
Copyright 2013, 2010, 2007, Pearson, Education, Inc. Section 12.2 Theoretical Probability
CPT: Ptr+Str/ Computer Programming Techniques Semester 1, 1998 Objective of these slides: –to discuss how pointers are used with structs.
Two Way Tables Venn Diagrams Probability. Learning Targets 1. I can use a Venn diagram to model a chance process involving two events. 2. I can use the.
15.3 Counting Methods: Combinations ©2002 by R. Villar All Rights Reserved.
Chapter 7 Arrays. A 12-element array Declaring and Creating Arrays Arrays are objects that occupy memory Created dynamically with keyword new int c[]
C Lecture Notes 1 Structures & Unions. C Lecture Notes Introduction Structures –Collections of related variables (aggregates) under one name Can.
CPT: Types/ Computer Programming Techniques Semester 1, 1998 Objective of these slides: –to look at how new types can be created 6. User-defined.
Draw 3 cards without replacement from a standard 52 card deck. What is the probability that: 1.They are all red ? 2.At least one is black ? 3.They are.
1 Lecture 12 Pointers and Strings Section 5.4, ,
1 EPSII 59:006 Spring HW’s and Solutions on WebCT.
1 Object-Oriented Programming Using C++ A tutorial for pointers.
1 Lecture 8 Pointers and Strings: Part 2 Section 5.4, ,
 2000 Prentice Hall, Inc. All rights reserved Introduction Structures –Collections of related variables (aggregates) under one name Can contain.
StructureStructure. Outline Introduction Structure Definitions Initializing Structures Accessing Members of Structures Using Structures with Functions.
Lesson Objective: Understand how to make and use Algorithms Learning Outcome: Design your own algorithms and flowcharts. Algorithms and Flowcharts.
PROBABILITY What is the probability of flipping a head? There is a 1 in 2 chance – ½ = 0.5.
Chapter 8: Arrays Gator Engineering One-dimensional array Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Move the first element to the.
Introduction to Programming
Lesson 17 Networking Basics.
Section 12.2 Theoretical Probability
Lesson 17 Networking Basics.
Homework Due Friday.
Presentation transcript:

Tutorial 10 Question 2a, 2b, 2c by Kapilesh Ramesh

Question 2 2) A deck of cards is commonly shuffled using the riffle shuffle technique in which half of the deck is held in each hand and the cards are released one by one in a left-right fashion such that they interleave into a new deck. A riffle shuffle is considered a perfect shuffle if the cards are perfectly interleaved in an orderly fashion. There are two types of pˆerfect riffle shuffles In-shuffle: the original top card ends up second from top in the shuffled deck. ˆOut-shuffle: the original top and bottom cards are preserved in the shuffled deck. Your task is to implement a deck of 52 cards and perform a number of (in or out) shuffles. Use the following as a guide in your implementation

Question 2 Part a 2a) Each card has a rank and suit. The suit is represented as one of four characters C, D, H or S (for clubs, diamonds, hearts and spades). The rank can be "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q" or "K". Define a C structure Struct Card to represent a single card. Solution : Note that rank is a character array struct Card because it can represent 10 only if it { is an array and not a character. char suit; char rank[3]; };

Question 2 Part b 2b) Declare deck as an array of 52 cards in the main function. Write a function generateDeck to generate cards in order of suit, i.e. clubs followed by diamonds, then hearts and lastly spades; cards of the same suit are ordered by rank. CA C2 C3 C4 C5 C6 C7 C8 C9 C10 CJ CQ CK DA D2 D3 D4 D5 D6 D7 D8 D9 D10 DJ DQ DK HA H2 H3 H4 H5 H6 H7 H8 H9 H10 HJ HQ HK SA S2 S3 S4 S5 S6 S7 S8 S9 S10 SJ SQ SK The function prototype is as follows. void generateDeck(struct Card deck[]); For example, CA represents the Ace of Clubs, S10 represents the 10 of Spades.

Solution void generateDeck(struct Card deck[]); int main() { struct Card deck[52]; generateDeck(deck); printDeck(deck); return 0; } void generateDeck(struct Card deck[52]) { int i, j = 0; for(i=0;i<52;i++) { if(i<13) deck[i]. suit= C ; else if(i>=13 && i<26) deck[i]. suit= D ;

else if(i>=26 && i<39) j++; deck[i]. suit= H ; if(j==13) else j=0; deck[i]. suit= S; } switch(j) } { case 0 : strcpy (deck[i]. Rank, A ); break; case 1 : strcpy (deck[i]. Rank, 2 ); break; case 2 : strcpy (deck[i]. Rank, 3 ); break; case 3 : strcpy (deck[i]. Rank, 4 ); break; case 4 : strcpy (deck[i]. Rank, 5 ); break; case 5 : strcpy (deck[i]. Rank, 6 ); break; case 6 : strcpy (deck[i]. Rank, 7 ); break; case 7 : strcpy (deck[i]. Rank, 8 ); break; case 8 : strcpy (deck[i]. Rank, 9 ); break; case 9 : strcpy (deck[i]. Rank, 10 ); break; case 10 : strcpy (deck[i]. Rank, J ); break; case 11 : strcpy (deck[i]. Rank, Q ); break; case 12 : strcpy (deck[i]. Rank, K ); break; }

Question 2 Part c 2c) Write a function printDeck to print the deck of cards according to the format in part 2b. void printDeck(struct Card deck[]); Verify that the card generation above is correct by using the main function as a driver and printing the deck of generated cards. Solution: void printDeck(struct Card deck[52]) { int i, j = 0; for(i=0;i<52;i++) { printf(%c%s, deck[i].suit, deck[i].rank ); printf( ); j++; if(j%13==0) printf(\n); }

OUTPUT: CA C2 C3 C4 C5 C6 C7 C8 C9 C10 CJ CQ CK DA D2 D3 D4 D5 D6 D7 D8 D9 D10 DJ DQ DK HA H2 H3 H4 H5 H6 H7 H8 H9 H10 HJ HQ HK SA S2 S3 S4 S5 S6 S7 S8 S9 S10 SJ SQ SK