Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2.1 Computation (hw02a_base.c) [8 points] For this program, you will write a program to compute the total volume for a number of cylinders. A cylinder

image text in transcribed
2.1 Computation (hw02a_base.c) [8 points] For this program, you will write a program to compute the total volume for a number of cylinders. A cylinder may have different values for height and radius. Study the base code and make the following changes: . Add a prompt for the number of cylinders to sum. Make sure to use the control symbol for integers. [2 points] . Create a loop based on the number of cylinders the user enters. [1 points] . Within the loop, prompt for height and radius parameters (allow floating point numbers), and calculate the volume for that particular cylinder. [4 points] . Display the total volume sum back to the user. Make sure to use the right control symbol. [1 points] 2.2 Collatz (no base file) [8 points] For this program, consider the following pseudocode algorithm for checking if a particular positive integer satisfies the collatz conjecture: Algorithm 1 Collatz conjecture checker. termination (n) { //pre-condition : n is any integer while n not equal 1 do { if even (n) then n := n/2 else n := 3n+1 output (n) // post-condition : n=1 . Write a C program to implement the algorithm as a function called termination that is called from main. [4 points] . Call termination from main on an input integer given by the user. [2 points] . Count and display how many iterations are executed for the input. [2 points] 2.3 Decryption (hw02b_base.c) [14 points] For this program, you will write a chunk based decryption program. Study the base code and make the following changes: . Implement display_chunks(). Loop over each string in the array of message chunks (strings) and print it. Each chunk should be printed back to back, do not insert an extra newline. Do not print the first character in each string since it is only used to store the order of the chunks. (Hint: use pointer arithmetic to skip a character.) [2 points] . Implement decrypt_chunks(). Loop over each string in the array and shift the characters in it by subtracting DECRYPTION_SHIFT value from them. Use pointer arithmetic to access individual characters but array access to the strings. Remember that C-style strings have a null terminator at the end. Do not apply the shift to the terminator. (Hint: to avoid doing double pointer arithmatic, save a char* pointer to the active chunk[?] in the outer loop but before the inner loop. Then the inner loop is only concerned with a single array of characters rather than an array of strings.) [4 points] . Implement sort_chunks(). Using your favorite sorting algorithm, sort the array containing the message chunks. Sort based on the first character in the chunk - it will always be a number. We provide a swap_strings function that you may use. Example usage: swap_strings(chunks[0], chunks[1]) will swap the contents of the first and second string. [10 points]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions