Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C PROGRAMMING Make sure you appropriate add comments and code based on the information in these steps and the Code Conventions . Add a

IN C PROGRAMMING

  1. Make sure you appropriate add comments and code based on the information in these steps and the Code Conventions.
  2. Add a new section called Constants as follows:
    1. Add a single blank line below the last #include statement. You should end up with a single blank line between the last #include statement and the comment in step 5b.
    2. Add a single line (heading type) comment on its own line: // Constants. Do NOT include the period at the end.
    3. Create a constant for tax rate as follows (see the Notes - Getting Startedimage text in transcribed):
      1. Below the comment from 5b, add: #define. Do NOT include the period at the end.
      2. Add a single space, which is required to separate the preprocessor directive from the identifier.
      3. Add a name as one continuous identifier using all caps and separating words with underscores, e.g., TAX_RATE. Do NOT include the period at the end.
      4. Add a single space, which is required to separate the identifier from its value.
      5. Add the tax rate, i.e., 0.065. Do NOT include a semicolon at the end, because this is a preprocessor directive, NOT a C statement. The end of the line, i.e., the Enter key, determines the end of a preprocessor directive.
  3. Add a new section called Prototypes as follows:
    1. Add a single blank line below the #define statement from step 5; see step 5a for more information.
    2. Add a single line (heading type) comment on its own line: // Prototypes. Do NOT include the period at the end.
  4. Below the entire main() function, create a function called getNumber(), which gets any number from the user and returns it to the calling function. There are no parameters. Include heading type comments as necessary. Please note: Don't forget to include heading type comments, e.g., // Variables, // Input, etc., follow good programming practices, see step 10 below, put a single blank line between the different parts, and the prompt for the user should have them enter the number at the end of the prompt, for example (the bolded number is an example of what would be entered by the user):
    Enter a number: 5.5
  5. Create a prototype for the function in step 7 in the prototype section, see step 6, by doing the following:
    1. Copy the function header, i.e., the first line of the function, and paste it under the // Prototype comment.
    2. Replace the space and left brace at the end with a semicolon, e.g., double getNumber();.
  6. Immediately above the function definition, put a set of appropriate PPR comments; see the Template, Code Conventions, and Announcements for more information and examples.
  7. In main(), add all variables, see the steps below, as needed to the Variables section and initialize them appropriately, e.g., to zeros. Here are some good programming practices:
    • Put all variables at the top of a function, so you know where they are defined and can quickly find them, if necessary
    • Initialize all variables appropriately, e.g., double num = 0.0; to replace any garbage with good initial values
  8. In main(), below the Variable section, add a heading type comment: // Input. Do NOT include the period at the end.
  9. In main(), in the Input section, call the function from step 7 and catch/store the returned value to a variable, e.g., num1 = getNumber();.
  10. Repeat step 12 for another number/variable. Do NOT use a loop.
  11. Below main(), create another function called add(), which takes two numbers and returns the result, i.e., the addition of the two numbers, e.g., double add(double num1, double num2) { ... }. Make sure all function definitions are put in alphabetical order below main().
  12. Create a prototype for the function in step 14; see step 8 for more information. Make sure all prototypes are in alphabetical order.
  13. Create a set of PPR comments for the function in step 14; see step 9 for more information.
  14. In main(), below the Input section, add a heading type comment: // Calculations. Do NOT include the period at the end.
  15. In main(), in the Calculations section, call the function from step 14 with the numbers/variables from steps 12 and 13, and catch/store the returned value to a variable, e.g., sum.
  16. Repeat the steps 14 through 18 as needed to create and use the following functions: subtract(), multiply(), and divide(). You do not need to do any validating or displaying any errors.
  17. Below main(), create another function called displayResults(), which takes the two numbers, see steps 12 and 13, and the various results, see steps 14 through 19, and displays them to the user/screen to three decimal places in a well formatted manner, e.g., 1.000 + 2.000 = 3.000, etc. lining up the numbers on their decimal points as appropriate. It should also include a label, e.g., Answers:, before displaying the results. This function does not return anything. Make sure all function definitions are put in alphabetical order below main().
  18. Create a prototype for the function in step 20; see step 8 for more information. Make sure all prototypes are in alphabetical order.
  19. Create a set of PPR comments for the function in step 20; see step 9 for more information.
  20. In main(), below the Input section, add a heading type comment: // Output. Do NOT include the period at the end.
  21. In main(), call the function from step 20 passing the numbers from steps 12 and 13, and 14 through 19 to the function.
  22. Create a function called calcTax(), which takes the addition of the two numbers from step 14, i.e., the subtotal, and the tax rate from step 5, and returns the tax, i.e., subtotal * taxRate. Do NOT use the constant or a function call to add() inside this function. Make sure all function definitions are put in alphabetical order below main().
  23. Create a prototype for the function in step 25; see step 8 for more information. Make sure all prototypes are in alphabetical order.
  24. Create a set of PPR comments for the function in step 25; see step 9 for more information.
  25. In main(), call the function in step 25 using the results from step 14 and constant from step 5, and catch/store the returned value to a variable.
  26. In main(), use printf() statements to appropriately display the subtotal, tax, and total to the user/screen; see the Sample Run from the A3 assessment. Feel free to create another function and prototype like the ones from steps 20 through 22.
  27. Don't forget to include return 0; at the end of main().
  28. There should only be one return statement at the end of each function, if appropriate; see the Code Conventions, etc.
  29. All output should be formatted professionally, e.g., put a single blank line between the different parts, e.g., between getting the input and displaying the results, etc.

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

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions