ECS30 Programming Assignment 2

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment

Description

5/5 - (5 votes)

Problem 1: charproperties.c (40 points, 4 per test case)
Write a program that reads in a char and prints the following properties (in order) of
the char, if they apply:
• The char is an uppercase letter.
• The char is a lowercase letter.
• The char is a vowel.
• The char is a digit.
• The char is punctuation.
• The char is a tab.
• The char is a double quote.
This documentation for ctype.h will be useful: https://www.tutorialspoint.com/c_
standard_library/ctype_h.htm. Example output:
[rsgysel@pc17 ˜]$ ./charproperties
Please enter a character: a
The char is a lowercase letter.
∗Last updated January 16, 2017
1
The char is a vowel.
[rsgysel@pc17 ˜]$ ./charproperties
Please enter a character: ”
The char is punctuation.
The char is a double quote.
[rsgysel@pc17 ˜]$ ./charproperties
Please enter a character: 8
The char is a digit.
Problem 2: roshambo.c (30 points, 3 per test case)
Implement rock paper scissors. The user will input ’r’ for rock, ’p’ for paper, ’s’ for scissors. On any other entry your program should report an error. Your program must
randomly generate its own rock, paper, or scissors, and compare it with the input
to determine the winner.
Example output:
Rock, paper, or scissors? r
I rolled rock. We tie!
Rock, paper, or scissors? s
I rolled paper. You win!
Rock, paper, or scissors? p
I rolled scissors. You lose!
Rock, paper, or scissors? a
Error: you did not enter ’r’, ’p’, or ’s’!
Problem 3: unitconversion.c (30 points, 3 per test case)
In this problem your program will convert units of volume for liquid measurements. One
gallon is four quarts, one quart is two pints, one pint is two cups, and one cup is eight
ounces. The user will first input a current measurement and unit of volume as a positive
integer and one of g for gallons, q for quarts, p for pints, c for cups, or o for ounces
separated by a space. Then the user will input a desired unit of volume as one of g for
gallons, q for quarts, p for pints, c for cups, or o for ounces. If the user’s input does not
match this specification, print the relevant errors in the examples below and quit.
2
Example output:
Enter your current measurement and unit of volume: 16 o
Enter your desired unit of volume: c
You have 2 cups of liquid.
Enter your current measurement and unit of volume: -13 o
Error! You entered a negative number.
Enter your current measurement and unit of volume: 13 a
Error! Enter one of ’g’ for gallons, ’q’ for quarts, ’p’ for pints, ’c’ for
cups, or ’o’ for ounces.
Enter your current measurement and unit of volume: -13 a
Error! You entered a negative number.
Error! Enter one of ’g’ for gallons, ’q’ for quarts, ’p’ for pints, ’c’ for
cups, or ’o’ for ounces.
Enter your current measurement and unit of volume: 13 o
Enter your desired unit of volume: z
Error! Enter one of ’g’ for gallons, ’q’ for quarts, ’p’ for pints, ’c’ for
cups, or ’o’ for ounces.
3