Table of Contents

Corning Community College

CSCS2330 Discrete Structures

~~TOC~~

Project: YOUR OPTIMIZED LOGIC (yol0)

Objective

I've seen far too many tendencies to “plug and chug”, as if programming is like reading recipes from a book. This project will focus on your ability to creatively solve programs and craft algorithms, according to various constraints.

Algorithms will rely on both mathematical and logical operations.

I would hope that all those weekly puzzles you have been doing (which you've been putting honest effort into doing and reflecting regularly on the process, especially the thought processes, right?) are starting to pay off… so much of the reasoning patterns you've likely had to apply to solve the puzzles will really come in handy with this project.

Decks of Cards

The standard deck of playing cards (for our purposes) possesses 52 distinct cards, spread out among 4 different suits.

The suits are (in this order):

The face values on the cards are (in this order):

13 face values, 4 suits, 13 x 4 = 52.

For the purposes of any programs we write, we are going to display the cards as 2- or 3-symbol strings, as such:

With the differing values used by the suits and face values (ie, by name it isn't immediately linear), you are going to need to “flatten” the data so that it can be represented by a single numeric value (ranging from 1-52).

Program

Your task is to write a program that processes cards.

It should have a menu allowing the selection of the following functions, and to prompt the user for the appropriate input, which gets passed into the selected function, displaying the resulting output.

It is to have the following functions:

And yes, you must implement all six functions, according to their implementation requirements. Any arrays created must be compatible for use by all functions you implement (no custom array per function).

There are 2 actual functions, the num2name() and its reverse, name2num(); however, to aid in your explorations, I'd like for you to create 3 different implementations of each, restricting yourself to the following:

You can (and should) make use of arrays.

I'd recommend 2 arrays:

You can use static arrays (the brackets) or dynamically allocated arrays; I'd caution against just using what you are comfortable with… you'll want to use what is best for the algorithm/program.

You should strive for optimized code, but if you can make something work by “wasting” or “skipping” an occasional space, by all means.

Example: Using num2name()

If we had the number 17 (out of 1-52), and we passed it to num2name(), with the specified suit ordering of Clubs, Diamonds, Hearts, and Spades, we should get: 4 of Diamonds

The actual return value from num2name() would be the string: “4D”

Another example, the number 34; we should get: “8H”

Or: 1; we should get: “AC” (Ace of Clubs)

Example: using name2num()

If we had “10C”, we should get: 10

If we had “QH”, we should get: 38

If we had “6D”, we should get: 19

Helpful hints

Remember that linearity can be of great value (especially if you cannot divert program flow with some conditional statement).

Finding ways to conveniently arrange or pack your data can make for a much, much easier implementation. But that requires planning, crafting, and maybe even a bit of creative brainstorming.

Do remember your third grade math.

Do consider making use of bitwise logic; by the way, your operators are:

Remember what a string is (a set of characters), what a character is (merely a number), and how a number can be expressed/manipulated.

Note the required parameter/return data types. Make sure you implement with these in mind. Type cast if necessary, but all input to (parameters) and output from (return value) your functions must be of those types.

Submission

Project Submission

To submit this program to me using the submit tool, run the following command at your lab46 prompt:

lab46:~/src/discrete/yol0$ submit discrete yol0 yol0.c
Submitting discrete project "yol0":
    -> yol0.c(OK) 

SUCCESSFULLY SUBMITTED

You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.

Submission Criteria

To be successful in this project, the following criteria must be met: