Starting from:

$15

Assignment 16 - Colored Cards Solution

Edit, compile, and run the following program on the UH UNIX shell:

The purpose of this assignment is to learn how to use an array of structures.

Modify the cards.c example codeThe struct card structure should also have the card's color, "red" or "black".
The corresponding code in the program should hold the new cards, and display their colors when printing.
You must use an array of struct card's in your program.
The color MUST be a part of the struct.Don't use the color as a separate array.
//structure definition
struct card{
char *rank;
char suit[MAX];
//** add the color of the cards here **
};

The display function should output the new structs as shown below.
Submit your C program via Laulima, and makefile if you use one.

Example I/O

Display an ordered deck of cards:

Ace of Clubs    (black)         Two of Clubs    (black)

Three of Clubs    (black)        Four of Clubs    (black)

Five of Clubs    (black)         Six of Clubs    (black)

Seven of Clubs    (black)       Eight of Clubs    (black)

Nine of Clubs    (black)         Ten of Clubs    (black)

Jack of Clubs    (black)       Queen of Clubs    (black)

King of Clubs    (black)         Ace of Diamonds (red)

Two of Diamonds (red)         Three of Diamonds (red)

Four of Diamonds (red)          Five of Diamonds (red)

Six of Diamonds (red)         Seven of Diamonds (red)

Eight of Diamonds (red)          Nine of Diamonds (red)

Ten of Diamonds (red)          Jack of Diamonds (red)

Queen of Diamonds (red)          King of Diamonds (red)

Ace of Hearts   (red)           Two of Hearts   (red)

Three of Hearts   (red)          Four of Hearts   (red)

Five of Hearts   (red)           Six of Hearts   (red)

Seven of Hearts   (red)         Eight of Hearts   (red)

Nine of Hearts   (red)           Ten of Hearts   (red)

Jack of Hearts   (red)         Queen of Hearts   (red)

King of Hearts   (red)           Ace of Spades   (black)

Two of Spades   (black)       Three of Spades   (black)

Four of Spades   (black)        Five of Spades   (black)

Six of Spades   (black)       Seven of Spades   (black)

Eight of Spades   (black)        Nine of Spades   (black)

Ten of Spades   (black)        Jack of Spades   (black)

Queen of Spades   (black)        King of Spades   (black)

 

shuffling deck ...

 

Seven of Hearts   (red)          Four of Diamonds (red)

Four of Hearts   (red)          Five of Diamonds (red)

Two of Diamonds (red)           Ace of Hearts   (red)

Two of Hearts   (red)         Three of Clubs    (black)

Six of Diamonds (red)          King of Hearts   (red)

Four of Clubs    (black)       Eight of Hearts   (red)

Nine of Clubs    (black)       Three of Diamonds (red)

Queen of Spades   (black)        Jack of Diamonds (red)

Jack of Hearts   (red)           Two of Spades   (black)

Six of Clubs    (black)         Ten of Hearts   (red)

King of Clubs    (black)         Two of Clubs    (black)

Nine of Spades   (black)       Eight of Spades   (black)

Ten of Spades   (black)       Seven of Diamonds (red)

Ace of Diamonds (red)          King of Diamonds (red)

Six of Spades   (black)        Five of Clubs    (black)

King of Spades   (black)        Four of Spades   (black)

Queen of Diamonds (red)         Seven of Clubs    (black)

Queen of Hearts   (red)         Queen of Clubs    (black)

Jack of Clubs    (black)       Three of Hearts   (red)

Three of Spades   (black)       Eight of Diamonds (red)

Nine of Hearts   (red)           Ten of Diamonds (red)

Eight of Clubs    (black)         Six of Hearts   (red)

Seven of Spades   (black)        Nine of Diamonds (red)

Five of Hearts   (red)           Ace of Clubs    (black)

Ten of Clubs    (black)        Jack of Spades   (black)

Five of Spades   (black)         Ace of Spades   (black)

 

Would you like to shuffle again?

If so, press "Enter" key. If not, enter any other char.

 

 

More products