Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#Don't use Cout or Cin Don't use #include Use #Include HomeWork1: //Complet.e a program that saves user input into an array, computes the //average, and

#Don't use Cout or Cin

Don't use #include

Use #Include

HomeWork1:

//Complet.e a program that saves user input into an array, computes the //average, and prints the values of the elements of the array to the screen //in opposite order.////You do not have to use functions or creat.e attractive output.#include //STEP 1 - Creat.e a symbolic constant for the number 5.intmain(void){int index;int total=0;double average;//**************************************************//STEP 2 - Createe an array of five integers here, using the symbolic constantdefined in Step 1.//STEP 3 - Finish the loop below that gets data from the user//You need to add 3 things:// 1) the starting index value in the for statement// 2) the ending index value in the for statement (use the symbolic constant!)// 3) the correct subscripted variable in the scanf statement (don't forgetthe &)for (index = ; index 

HomeWork2:

Week5

#include int main (void){ float purchase_amount, discount_rate, discount, original_purchase_amount, tax, new_purchase_amount, final_total; char spirit_wear;// function to compute discount amountfloat computeDiscount(float purchase_amount, float discount_rate){ return purchase_amount * discount_rate;}// function to compute new purchase amount after discountfloat computePurchase(float original_purchase_amount, float discount){ return original_purchase_amount - discount;}// function to compute sales taxfloat computeTax(float purchase_amount){ return purchase_amount * 0.05;}// function to compute final total purchase amountfloat computeTotalPurchaseAmount(float new_purchase_amount, float tax){ return new_purchase_amount + tax;} // Prompt user for purchase amount printf("Enter the purchase amount> "); scanf("%f", &purchase_amount); fflush(stdin); // Prompt user for Spirit Wear printf("Does this purchase include Spirit Wear (Y/N) ?> "); scanf("%c", &spirit_wear); fflush(stdin); if (spirit_wear == 'Y' || spirit_wear == 'y') { // determine discount rate based on purchase amount if (purchase_amount >= 100) { discount_rate = 0.10; } else { discount_rate = 0.07; } // calculate discount amount and new purchase amount original_purchase_amount = purchase_amount; discount = computeDiscount(purchase_amount, discount_rate); new_purchase_amount = computePurchase(original_purchase_amount, discount); // display original purchase amount, discount amount, and new purchase amount printf(" Purchase amount \t\t $%.2f ", original_purchase_amount); printf("Discount (%.0f%%) \t\t\t $%.2f ", discount_rate * 100, discount); printf("Purchase amount after discount \t $%.2f ", new_purchase_amount); } else if (spirit_wear == 'N' || spirit_wear == 'n') { // No discount applied printf(" Purchase amount \t\t $%.2f ", purchase_amount); } else { // Error message for invalid input printf("Invalid input. Please enter Y or N. "); return 0; } // calculate sales tax and final total purchase amount tax = computeTax(new_purchase_amount); final_total = computeTotalPurchaseAmount(new_purchase_amount, tax); // display sales tax and final total purchase amount printf("Sales tax (5%%) \t\t\t $%.2f ", tax); printf("Total purchase \t\t\t $%.2f ", final_total); return 0;}

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Refactor your program from Week 05 to use parallel arrays as noted below. Learning Objectives In this assignment, you will practice: Refactoring (restructuring) existing code . Using parallel arrays to store related data Requirements This version of the program will appear slightly different to the user. In this version, the user will be prompted for the purchase amount and the answer to the spirit wear question repeatedly. The output will be displayed after all data has been entered, and will include information on every transaction, as noted below. Refer to the instructions for the week 03 homework for the overall idea of what this project is about. Remember to use fflush(stdin) after every scanf. Since there will be numeric and character data entered repeatedly, this is even more important for correct functionality. Requirements for the main Function 1. Prompt the user for the number of transactions to be entered. Remember that counts are always integers. 2. Create two arrays using that value: a. One array will store the purchase amounts. Use the appropriate data type and a meaningful name. b. The other array will store the replies to the spirit wear question. Use the appropriate data type and a meaningful name. 3. Using a counter-controlled loop:3. Using a counter-controlled loop: a. Prompt the user for the purchase amount and store their reply in the appropriate element of the purchase amount array. b. Prompt the user about spirit wear and store their reply in the appropriate element of the spirit wear array. 4. After the first loop completes, call the print_headers function. 5. Then set up a second counter-controlled loop. This loop will read one element from each array, and pass those values to the calculate_final_purchase function. 6. The calculate_final_purchase function also requires the transaction ID as input. The transaction ID is an integer. The first transaction entered is transaction 1, the 20 transaction is transaction 2, etc. Do not prompt the user for these values or save these values in an array. Requirements for the calculate_final_purchase FunctionRequirements for the calculate_final_purchase Function This function handles calculating the following values: 1. The amount of the transaction after any discount has been applied. 2. The amount of tax 3. The final transaction amount after tax has been applied. These calculations should already be set up in functions from homework 5. Just call those functions! The calculate_final_purchase function should then call the print_current_transaction function. Requirements for the print_headers Function This function prints the column headings in the output. See the sample run for how these headers should look. Hint: In order to get the headings and the data to line up neatly, you will need to use format control strings for the headers. Remember the headers are all strings, and strings are automatically right-aligned within the space allocated for them in a format control string. If you want to left-align, include the negative sign in the fcs. Requirements for the print_current_transaction Function This function prints one line of data. All data must line up neatly as shown in the sample run. All dollar values must be right-aligned under the appropriate column header and display two values after the decimal.Sample Run How many transactions? 3 Enter the purchase amount> 50.00 Does this purchase include Spirit Wear (Y/N) ?> N Enter the purchase amount> 50.00 Does this purchase include Spirit Wear (Y/N) ?> y Enter the purchase amount> 150 Does this purchase include Spirit Wear (Y/N) ?> Y Transaction ID Purchase Spirit Wear? Furchase After Discount Tax Final Purchase 50.00 50.00 2.50 52.50 50.00 46.50 2. 35 150.00 195.00 6.75 141.75 NOTE: I had to make the output small so it would fit on one line in this document. Your output does not need to be this small. Feel free to adjust the column widths, as long as the numbers below are right-aligned neatly.COMPLETE AND ACCURATE - Your program must compile, execute, and give accurate output. FOLLOW ALL REQUIREMENTS ACCORDING TO THE INSTRUCTIONS - Follow the instructions as written for completing this project, even if you [think you] know a "better" way to do something. COMMENTS - Include comments in your code. There must be a comment at the top of your program that includes your name, the program number, and a description of the program. There must be comments at each important step in your program that describes that step. Every variable must include a comment describing its purpose. BEST PRACTICES - Follow best practices in C programming as discussed in class and in the textbook, including, but not limited to, appropriate use of white space, indenting, alignment, meaningful identifier names, etc. Points will be deducted for sloppy code that is hard to read, even if it works, so pay attention to these details. SUBMIT ONLY .c SOURCE CODE - Pay attention to the file extension of the source code file you submit. I will deduct points for not following this requirement

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

Step: 3

blur-text-image

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