Starting from:

$30

Homework #1 Decoding Social Security Numbers

Homework #1

55 points total
Write your programs in C using the environment of your choice. Submit your code via Blackboard as a zip file.
We'll discuss what files to include in class. See the posted documentation guidelines.
1) (10 points) Decoding Social Security Numbers
Write a program that inputs a Social Security Number, with no dashes or spaces (e.g. 574343912). You can input
the number into a variable of type int.
From SSN-Check.org, the first three digits give you some information about the location of the SSN holder. If
the value is 574 then the person was born in Alaska. If the value is between 531 and 539 then the person was
born in Washington. 540-544 is Oregon and 545-573 is California.
Extract the first three digits of the SSN into an integer. There are several ways to do this, although I recommend
a mathematical approach. From the first three digits, use an if-statement to output what state they were born in.
If the three digits doesn't fall into any of those ranges, output "a state other than AK, CA, WA, OR."
2) (10 points) Looping Warmup - Output Binary Numbers
Write a program that outputs the numbers from 0-15 in decimal and binary. Here is the exact output that your
program should produce:
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111
Your program must use four nested loops, where one loop corresponds to the leftmost digit, another loop
corresponds to the second to left digit, another loop corresponds to the second to right digit, and the last loop
corresponds to the right most digit. Review 2.13 in zyBooks if you need a refresher on binary numbers.
3) (10 points) Debugging
The following two programs have errors. Correct them and turn in a listing of a working program (there are
several ways to fix each program).
a. The first course, main course, and each dessert should all be printed on their own lines. This program has
big problems and will not compile as-is.
//////////////////////////////////////////////////////
// CSCE A201
// *Your Name Here*
// *Date*
// Purpose: Print out a dinner menu
//////////////////////////////////////////////////////
#include "stdio.h"
const char SALAD = "Green Salad"
const MEAT = "Chicken Marsala"
const VEGGIE = "Carrots with lemon butter"
const STARCH = "Mashed potatoes"
const string DESSERT1 = "Cheesecake"
const string DESSERT2 = "Tiramisu"
const int numdesserts = 2
int main
{
 printf("First course: %d\n", SALAD);
 printf("Main course: ",MEAT," with ",VEGGIE," and ",STARCH);
 printf("There are %d desserts:\n",NUMDESSERTS);
 printf("Dessert 1: %dDessert 2: %d\n",DESSERT1,DESSERT2);
 return 0;
}

b. This program should convert fahrenheit to celsius. It will compile and run, but prints the incorrect answer
(try running it for various temperatures ranging from 0-100). The formula for converting from F to C is:
//////////////////////////////////////////////////////
// CSCE A201
// *Your Name Here*
// *Date*
// Purpose: Convert a Fahrenheit Temp to Celsius
//////////////////////////////////////////////////////
#include "stdio.h"
int main()
{
 int celsius;
 int fahrenheit;
 printf("Enter a temperature in Fahrenheit.\n");
 scanf("%d",&fahrenheit);
 celsius = ((fahrenheit - 32) / 9) * 5;
 printf("%d in Fahrenheit is %d in Celsius.\n",fahrenheit,celsius);
 return 0;
}
In your submission add a comment that identifies what the bug was and how your solution fixed the
problem.
4) (10 points) Temperature Equivalence
There is a temperature for which Fahrenheit and Celsius are the same. This value can be determined both
algebraically and experimentally. Solve the problem algebraically first and then write a program that finds the
value by brute force, testing all the Fahrenheit temperatures from -100 to 100 and for each find the
corresponding temperature in Celsius and output the value if it is the same.
5) (15 points) Game Show Simulation
You are a contestant on a game show and have won a shot at the grand prize! Before you are three doors. Behind
one door is $1,000,000 in cash. Behind the other two doors are the consolation prizes: a box of rice-a-roni. The
location of the prizes have been randomly selected. Naturally, you want the cash! The game show host asks you
to select a door, and you randomly pick one. However, before revealing the contents behind your door, the game
show host reveals one of the other doors that contains a consolation prize. At this point, the game show host asks
if you would like to stick with your original choice or switch your choice to the remaining door. What choice
should you make to optimize your chances of winning the grand prize, or does it matter?
Write a simulation program to help you make your choice. Your program should make 1000 simulated runs
through the game show scenario where the player sticks with the original choice, and 1000 runs where the player
switches doors. This could be the same program where you comment/uncomment some code that determines if
the player stays or switches doors (or do them both in the same program). For all 1000 runs the program should
count up how many times the player won the cash. The steps your program should make to simulate the game
are:
1. Randomly select a door to have the cash prize (this could be a random number that is 0, 1, or 2).
2. Randomly select a door for the player to pick (another random number that is 0, 1, or 2)
3. Compute a door that isn't the player's pick that doesn't have the cash prize and reveal it
4. Stick with the original choice or switch to the remaining door, depending upon what is being tested
5. Determine if the final door selection has the cash, and if so, increment tne number of times won
Be sure that your program simulates the process of selecting the door, revealing one, then switching. Do not
make assumptions about the actual solution. Turn in your code, along with your answer of what choice to make
based on your program's output.
If you need to review random numnbers, see section 2.19 in zyBooks.

More products