Project 2, Program Design1. (60 points) A u-pick farm allows customers to pick four different berry products in their farm.
The prices are: 1. strawberry – $1.99/lb, 2. blueberry – $4.39/lb, 3. blackberry $3.69/lb, 4.
raspberry – $5.99/lb.
Write a program that allows the user to select products, input the weights of each product, and
calculate the total amount due. The farm only accepts cash. Your program will take input of the
cash received and calculate the change.
A sample input/output:
Please select a product: 1. strawberry – $1.99/lb, 2.
blueberry – $4.39/lb, 3. blackberry $3.69/lb, 4. raspberry
– $5.99/lb. Enter 0 to stop selection.
Enter product selection: 1
Enter product weight (lb): 4.8
Enter product selection: 3
Enter product weight (lb): 2
Enter product selection: 7
Invalid selection, select from 1 to 4, enter 0 to stop selection
Enter product selection: 4
Enter product weight (lb): 1.6
Enter product selection: 0
Amount due ($): 26.52
Enter cash received ($): 30
Your change is $3.48
1) Name your program berries.c
2) If the user selects a number out of the range (1 through 4), display a message and allows the
user to select again. When user enters 0, the program should exit from the loop for
selection.
3) Use a switch statement to compute the amount due according to the product selection.
2. (40 points) Write a program to check if an input is a valid hashtag (starts with #, contains only
letters, numbers, and underscore, no space or special characters).
1) Name your program hashtag.c.
2) The user input ends with the user pressing the enter key (a new line character).
3) Library function isalpha(), isdigit(), and isalnum() are not allowed in this program.
4) Use getchar() to read in the input.
Example input/output:
Input: #cseUSF
Output: It is a valid hashtag
Input: #TBTimes_Opinion
Output: It is a valid hashtag
Input: #933FLZ
Output: It is a valid hashtag
Input: #60Minutes?
Output: It is an Invalid hashtag
Before you submit:
1. Compile with –Wall. –Wall shows the warnings by the compiler. Be sure it compiles on
student cluster with no errors and no warnings.
gcc –Wall berries.c
gcc –Wall hashtag.c
2. Be sure your Unix source file is read & write protected. Change Unix file permission on
Unix:
chmod 600 berries.c
chmod 600 hashtag.c
3. Test your programs with the shell script on Unix:
chmod +x try_berries
./try_berries
chmod +x try_hashtag
./try_hashtag
4. Download berries.c and hashtag.c from the student cluster and submit on Canvas.
Grading:
Total points: 100 (60 points problem 1 and 40 points problem 2)
1. A program that does not compile will result in a zero.
2. Runtime error and compilation warning 5%
3. Commenting and style 15%
4. Functionality requirement 80%
Programming Style Guidelines
The major purpose of programming style guidelines is to make programs easy to read and
understand. Good programming style helps make it possible for a person knowledgeable in the
application area to quickly read a program and understand how it works.
1. Your program should begin with a comment that briefly summarizes what it does. This
comment should also include your name.
2. In most cases, a function should have a brief comment above its definition describing
what it does. Other than that, comments should be written only needed in order for a
reader to understand what is happening.
3. Variable names and function names should be sufficiently descriptive that a
knowledgeable reader can easily understand what the variable means and what the
function does. If this is not possible, comments should be added to make the meaning
clear.
4. Use consistent indentation to emphasize block structure.
5. Full line comments inside function bodies should conform to the indentation of the code
where they appear.
6. Macro definitions (#define) should be used for defining symbolic names for numeric
constants. For example: #define PI 3.141592
7. Use names of moderate length for variables. Most names should be between 2 and 12
letters long.
8. Use either underscores or capitalization for compound names for variable: tot_vol,
total_volumn, or totalVolumn.