CS 1313 010: Programming for Non-majors, Spring 2023 Programming Project #2: Census
This second assignment will introduce you to designing, developing, testing and debugging your own C program, as well as to declaring variables, inputting and outputting. You will also learn to add new projects to your makefile.
I. PROBLEM DESCRIPTION
You are a software developer for the United States Cencus Bureau, working on software for the 2023 Census.
The particular program that you’re developing will ask three questions about a cnesus subject: 1. the average number of e-mails that the subject sends per month.
2. the average number of hours that the subject spends on homework per week.
3. the subject’s Social Security Number.
Notice that the average number of e-mails sent per month MIGHT NOT BE AN INTEGER; for example, a person might average 13.25 text messages sent per day.
Note that a number that doesn’t have to be an integer is known in mathematics as a real number, and is also known in computing as a floating point number.
On the other hand, notice that a person’s Social Security Number can be expressed as three integers (the area number, the group number and the serial number),1 separated by hyphens; for example:
123 - 45 - 6789
So, this program will have a user input two real numbers (average number of e-mails sent per month, average number of homework hours per week) and three integers (the parts of the Social Security Number), and then output those numbers in a specific format.
Write a program to perform the above task. Note that your program MUST begin with a declaration section in which you declare all necessary variables. This will be followed by the execution section (body), which will:
1. greet the user and explain what the program does, and then
2. prompt the user and input the requested information, and then 3. output the five numbers.
Details follow. Please read all of this specification CAREFULLY.
IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT!!!
This programming project specification contains many small code examples. In most cases, these code examples will be extremely useful in your actual PP#2. WE URGE YOU TO USE THEM.
II. WHAT TO DO FIRST: Insert an Entry for the New Program into Your Makefile
AS THE VERY FIRST STEP, in your makefile, insert a makefile entry for the new program, so that, when you’re ready to compile your new program, you can use make instead of having to use the gcc command directly (which would risk disaster).
Your C source file MUST be named census.c
and your executable MUST be named census
Using your preferred text editor (for example, nano), edit your makefile (which is named makefile) to include the following lines at the TOP of the makefile, ABOVE the make entry for Programming Project #1 (PP#1), with a blank line between the entries for PP#2 and PP#1:
census: census.c
gcc -o census census.c
IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT!!!
- In the gcc command, the filename after -o should be the executable (NO .c extension),
and the filename at the end should be the C source file (WITH the .c extension).
- DON’T DELETE THE MAKE ENTRY FOR PROGRAMMING PROJECT #1, nor
any other make entry, EVER.
- On the first line, above, between the colon and the name of the C source file, there are one
or more tabs (on most keyboards, it’s in the upper left, to the left of the Q key). There are
NO SPACES between the colon and the filename.
- On the second line, immediately before the gcc, there are one or more tabs. There are
NO SPACES immediately before the gcc.
IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT!!!
Also in the makefile, update the clean entry (the bottommost entry in the makefile) by putting in another rm command, as the LAST rm command in the clean entry, like this:
clean:
rm -f my_number
rm -f census
NOTES:
- DON’T DELETE THE rm COMMAND FOR PROGRAMMING PROJECT #1, nor
any other rm command, EVER.
- In the new rm command, above, immediately before the rm, there are one or more tabs.
There are NO SPACES immediately before the rm.
- NEVER put ANYTHING on the same line as clean: regardless of what it may be that
you want to put there. LEAVE THAT LINE COMPLETELY ALONE!
IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT!!! In the clean entry, the file to be removed with the rm should ALWAYS ALWAYS ALWAYS be the EXECUTABLE (for PP#2, census) and NEVER NEVER NEVER a source file.
NOTE: You MUST use the lecture slide packets titled “C Introduction,” “Variables” and “Standard I/O” to complete this project. You should study every single slide CAREFULLY. You can also look at the “Software” and “Constants” packets, but the bulk of the crucial information will be in the “C Introduction,” “Variables” and “Standard I/O” packets.