All of my programming assignments for my CptS 121 course. Basic description of each PA is available in this file.
Programming Assignment 1 - Solving Equations
Programming Assignment 2 - Solving Equations using Scanning
Programming Assignment 3 - GPA Operations
Programming Assignment 4 - Craps
Programming Assignment 5 - Yahtzee
Programming Assignment 6 - Battleship
Programming Assignment 7 - 5-Card Poker
Create a program that evaluates equations. Checking for faulty numbers aren't required.
Equations
- Newton’s Second Law of Motion
- force = mass * acceleration
- Volume of a cylinder
- volume_cylinder = PI * radius² * height
- Character encoding
- encoded_character = (plaintext_character - 'a') + 'A
- Gravity
- force = G * mass1 * mass2 / distance²
- Resistive divider
- vout = r2 / (r1 + r2) * vin
- Distance between two points
- distance = √((x1 - x2)² + (y1 - y2)²)
- General equation
- y = (73 / 12) - x * z + a / (a % 2)
Alter PA 1 to be modular and use scanning (scanf) for inputs. Do not check for faulty inputs.
Write a program that processes numbers, corresponding to student records read from a file. You must define the following functions and process them accordingly.
Required Functions
- Read a double from a file.
- double read_double (FILE *infile)
- Read an int from a file.
- int read_integer (FILE *infile)
- Find the sum of the numbers.
- double calculate_sum (double number1, double number2, double number3, double number4, double number5)
- Find the average.
- double calculate_mean (double sum, int number)
- Find the deviation.
- double calculate_deviation (double number, double mean)
- Find the variance.
- double calculate_variance (double deviation1, double deviation2, double deviation3, double deviation4, double deviation5, int number)
- Find the standard deviation.
- double calculate_standard_deviation (double variance)
- Find the maximum number.
- double find_max (double number1, double number2, double number3, double number4, double number5)
- Find the minimum number.
- double find_min (double number1, double number2, double number3, double number4, double number5)
- Print a double to the output file.
- void print_double (FILE *outfile, double number)
Required Processes
- Find sum of GPAs.
- Find sum of class standings.
- Find sum of ages.
- Find average GPA, writing to output file.
- Find average class standing, writing to output file.
- Find average age, writing to output file.
- Find deviation of GPAs.
- Find variance of GPAs.
- Find standard deviation of GPAs, writing to output file.
- Determine minimum GPA, writing to output file.
- Determine maximum GPA, writing to output file.
- Close the input and output files.
Expected Input File Format
Student ID (int)
GPA (double)
Class Standing (int)
Age (double)
Expected Input File Format
GPA Mean (double)
Class Standing Mean (double)
Age Mean (double)
GPA Standard Deviation (double)
GPA Minimum (double)
GPA Maximum (double)
Write a program that plays a game of Craps, with wagering implemented. Required functions are listed below.
Required Functions
- Prints out the game rules.
- void print_game_rules (void)
- Prompts and gets a bank balance amount.
- double get_bank_balance (void)
- Prompts and gets a wager amount.
- double get_wager_amount (void)
- Checks wager amount to ensure you can spend it.
- int check_wager_amount (double wager, double balance)
- Rolls a die and returns the result.
- int roll_die (void)
- FInds the sum of the die faces.
- int calculate_sum_dice (int die1_value, int die2_value)
- Determines the result of the first roll. If sum is 7 or 11, the player wins. If sum is 2, 3, or 12, the player loses. Any other sum becomes the point.
- int is_win_loss_or_point (int sum_dice)
- Determines the result of any successive roll after the first roll. If the sum of the roll is the point_value, player wins. If the sum of the roll is a 7, player loses.
- int is_point_loss_or_neither (int sum_dice, int point_value)
- Add or subtract amount to/from bank balance.
- double adjust_bank_balance (double bank_balance, double wager_amount, int add_or_subtract)
- Random messages to add for fun.
- void chatter_messages (int number_rolls, int win_loss_neither, double initial_bank_balance, double current_bank_balance)
- Others?
Develop and implement an interactive two-player Yahtzee game. Required processes are listed below.
Required Processes
- Print a game menu.
- Get menu choice and either print rules, start game, or quit.
- Ask player to hit any key to continue.
- Roll 5 die and display them.
- Allow player to reroll die up to 3 times.
- Save the combination, as it cannot be changed anymore.
- Calculate points and validate the selections (which section on score card) the player chose to assign points to is valid and hasn't been used yet.
- Alternate players and repeat steps for 14 rounds.
- If the total score in the upper section (score card) is greater than or equal to 63 for a player, add 35 points to the score.
- Print scores for both players and display the winner.
- Return to step 1.
Write a program that simulates the game of Battleship. Both players' fleets consist of 5 ships that are hidden from the enemy. For each move made by Player1 and Player2, the results should be echoed to a file called "battleship.log". At the end of the game, Player1's and Player2's statistics should be written to "battleship.log". Must use structs to store log information. See optional functions, required processes, and expected output below.
Required Processes
- Print a game menu.
- Print menu, start game, or quit accordingly.
- Open logging file.
- Intializing Player1's and Player2's boards.
- Ask for manual or automatic placement for ships.
- Manually or automatically place ships for Player1.
- Automatically place ships for Player2 (CPU).
- Randomly select who goes first.
- Displaying game boards accurately, including hiding (but not changing) the enemy's board.
- Ask for coordinates, validate them and check for hits/misses.
- Determin if a ship is sunk.
- Alternate players.
- Keep going until there is a winner.
- Close logging file.
Expected Input File Format
Position (int int)
Hit or Miss (char)
Which Ship Sunk (char)
Number of Hits (int)
Number of Misses (int)
Number of Shots (int)
Hit to Miss Ratio (double)
Won or Lost (int)
Write a program that allows a user to play 5-Card-Draw Poker against the CPU.
Required Processes
- Declare a Card struct with 2 integers. One being the face value, the othe rbeing the suit.
- Declare a Had struct that contains an array of 5 Card structs.
- Print a game menu.
- Prints menu, start game, or quit accordingly.
- Make a draw function to draw a specific number of cards.
- Write a function to determine that determines if a hand is a pair, 2 pair, 3 a kind, 4 a kind, full house, flush, or a straight.
- Simulate the dealer, which should draw cards and replace up to 3 cards as needed to get a better hand.
- Determine and print the winner.