CSE 1310 Tarleton State University Computer Science Project

User Generated

nxnexv1234

Computer Science

CSE 1310

Tarleton State University

CSE

Description

Unformatted Attachment Preview

Homework 4-part1 (75 points) Total points: 75 Topics: functions, switch instruction, if-else if – else, strings (read, printed, passed as argument to function) All the solution files should include your name and program description at the top. This information will be included as a comment. When your program runs it must look identical as mine (including printing the description text and the Bye at the end). Suggested approach in working on the homework: 1. Review the relevant lectures, slides and book chapters. Practice on your own AT LEAST what we did in class. Ideally practice other problems from the book. 2. Pick a task (the easiest). 3. Identify smaller components. Task 1 (25 pts) - switch File: hw4_shapes.c The program should have a function void print_shape(int edgesNo) that has an integer argument, and prints the name of the polygon with that many edges: - If edgesNo is 3 it prints triangle - If edgesNo is 4 it prints rectangle - If edgesNo is 5 it prints pentagon - If edgesNo is 6 it prints hexagon - For any other value it will print “Shape not known recognized.”. In main() you should call this function 3 times: - in the first call pass hardcoded value 4 as an argument - in the second call pass the hardcoded value 7 as an argument - next, still in main() , print a message and read a number, N, from the user and call the print_shape() passing N as an argument. The user input is shown in red. --- Sample run: This is a rectangle. Shape not recognized. How many edges does your polygon have? 6 This is a hexagon. --- Sample run: This is a rectangle. Shape not recognized. How many edges does your polygon have? 3 This is a triangle. 1 --- Sample run: This is a rectangle. Shape not recognized. How many edges does your polygon have? -2 Shape not recognized. Grading: 3 pts – indentation (1pt), good variable names (1pt), program description at top (1pt). 7 pts – correct function definition: 4 pts - uses the value of the argument passed at function call, 3 pts – matches the required function signature 5 pts – every one of the 5 branches of the switch is correct 4 pts – correctness and the program produces the same output as in the sample run (with correct code, not hardcoded in main() ) 6 pts – main() is correct: - 1 pt – 1st function call 1 pt – 2nd function call 2 pts – print message and read N 2 pts – 3rd function call Task 2 (25 pts.) Files to submit: hw4_grade_a.c and hw4_grade_b.c Provided file: hw4_grade.c a) (12 pts) Modify program hw4_grade.c, attached, is a clean-up version of the grades program we did in class. Modify it so that it recognizes lowercase letters for grades as well: it prints for the lowercase grade the same message as it does for the uppercase one. See in the sample runs below that it printed the same messages for grades b and B (and also for a and A). Name the program hw4_grade_a.c . If you complete and submit the version from part b) you will be graded based on that one, but you should still submit this version as well as a back-up. Sample run 1: Enter student grade (uppercase or lowercase): b Your grade is b Well done Function finished Enter student grade (uppercase or lowercase): B Your grade is B Well done Function finished Enter student grade (uppercase or lowercase): A Your grade is A Excellent! Function finished Sample run 2: Enter student grade (uppercase or lowercase): T Your grade is T Invalid grade 2 Function finished Enter student grade (uppercase or lowercase): a Your grade is a Excellent! Function finished Enter student grade (uppercase or lowercase): D Your grade is D You passed, but remember that you need C or higher to enroll in CSE 1320. Function finished b) (13 pts) Modify the program from task a) to take the message it prints for grade A . Modify the function run_switch() to take a string argument and print that string as the message for A. New declaration: void run_switch ( char messageA[] ); Hint: Remember that the function declaration, definition and call all work together. main() will now be: int main () { run_switch("Keep up the excellent work!\n"); run_switch("Awesome! You made an A!\n"); run_switch("Way to go!\n"); return 0; } Name the program hw4_grade_b.c . Sample run 1: Enter student grade (uppercase or lowercase): a Your grade is a Keep up the excellent work! Function finished Enter student grade (uppercase or lowercase): A Your grade is A Awesome! You made an A! Function finished Enter student grade (uppercase or lowercase): a Your grade is a Way to go! Function finished Sample run 2: Enter student grade (uppercase or lowercase): a Your grade is a Keep up the excellent work! Function finished Enter student grade (uppercase or lowercase): b Your grade is b Well done Function finished Enter student grade (uppercase or lowercase): c Your grade is c 3 Well done Function finished Grading: a) (12 pts) 1 pt – indentation 11 pts – each letter (A,a,B,b,C,c,D,d,F,f) works correct and also the default case. (1 pt each) b) (13 pts) 3 pts – indentation (1pt), good variable names (1pt), program description at top (1pt). 3 pts – correctness/matches the sample output 7 pts – function displays the message passed as argument for grade A (and a) 4 pts - uses the value of the argument passed at function call, 3 pts – matches the required function signature Task 3 (25 pts) - Multiple choice File: hw4_steak.c You are given a starter program below: #include void print_info(int temp); int main(){ int temp1,temp2,temp3,temp4,temp5; printf("This program will call 5 times a function that prints a message about the doneness level of steak given the internal temperature.\n"); printf("Enter 5 temperatures (int) separated by spaces: "); scanf("%d%d%d%d%d", &temp1,&temp2,&temp3,&temp4,&temp5); print_info(temp1); print_info(temp2); // add the other three calls (for temp3, temp4 and temp5) return 0; } // write the definition for print_info()) Write the definition of the function void print_info(int temp); It should first print temp (e.g. see in the sample run The measured meat temperature is 132. ) Then, using the information from the picture “Steak doneness and levels” from this page, the function should print, depending on the value of temp, the corresponding message:       Rare Medium Rare Medium Medium Well Well What have you done?! 4 For completeness, add message “Start the fire!” when temp is below 120 (this case is not included in the image). The function main() already has code to read 5 integers and calls print_info() twice. Add 3 more calls to it (with temp3, temp4 and temp5). Notes: 1. Note in main() how you can read 5 integers with a single call to scanf(). 2. Note the ambiguity of the information given in the image for the end/start of range values. For example 130 is the end temperature for Rare, but also the start temperature for Medium Rare . I chose to use them as the star value. See for example that for temperature 130 my output is Medium Rare, not Rare. Use my convention. Sample run 1: This program will call 5 times a function that prints a message about the doneness level of steak given the internal temperature. Enter 5 temperatures (int) separated by spaces: 132 110 140 170 120 The measured meat temperature is 132. Medium Rare The measured meat temperature is 110. Start the fire! The measured meat temperature is 140. Medium The measured meat temperature is 170. What have you done?! The measured meat temperature is 120. Rare Sample run 2: This program will call 5 times a function that prints a message about the doneness level of steak given the internal temperature. Enter 5 temperatures (int) separated by spaces: 130 135 145 155 165 The measured meat temperature is 130. Medium Rare The measured meat temperature is 135. Medium The measured meat temperature is 145. Medium Well The measured meat temperature is 155. Well The measured meat temperature is 165. What have you done?! Grading: 25 pts total 2 pts - program style: indentation (1pt), comments, info at the top of the program ( 1 pt) 3 pts – the 3 remaining calls in main() 5 4 pts – the function prints:   the measured meat temperature message 14 pts – program handles all 7 cases of temperatures (“Start the fire!”, “What have you done?!”, and the 5 levels of doneness) 2 pts – the program handles the border cases as given here (e.g. for 130 prints Medium Rare, not Rare). The reason for being “picky” about this is because when you implement a program you must be able to implement the exact behavior that the client wants/needs. What to submit All solution files (.c) should be placed in a folder called hw4_Lastname. Zip this folder and submit it on Canvas. Penalties 1. **** Code using elements we had not covered at the time the homework was due, receives no credit. 2. CODE THAT DOES NOT RUN due to a SYNTAX ERROR 25%-80% penalty per task. Notice that this penalty is up to 80% now. At this point we expect you are able to understand the syntax and fix such problems. I prefer that you submit a program that does not do everything it needs to do, but compiles and runs, rather than one that attempts all, but does not even compile. 3. RUN-TIME ERROR FOR INPUT SPECIFICALLY SHOWED AS AN EXAMPLE: 20% of task grade. Runtime-error for grader’s input: 5-20% of task grade (depending on the reason of why it fails). 4. Up to 10 points will be lost for non-compliance with the submission requirements: folder name, all files in a folder, zipped folder, the compressed file is a zip, the program files have extension .c, ... 5. Each program must have: o description and your name at the top o comments o meaningful variable names o correct indentation If the grading criteria does not explicitly give points for this, a program missing some or all of these will lose the up to 10% of the points for that task. 6
Purchase answer to see full attachment
Explanation & Answer:
2 pages
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

View attached explanation and answer. Let me know i...


Anonymous
Just what I was looking for! Super helpful.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Similar Content

Related Tags