Answered step by step
Verified Expert Solution
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
- Make sure you appropriate add comments and code based on the information in these steps and the Code Conventions.
- Add a new section called Constants as follows:
- 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.
- Add a single line (heading type) comment on its own line: // Constants. Do NOT include the period at the end.
- Create a constant for tax rate as follows (see the Notes - Getting Started):
- Below the comment from 5b, add: #define. Do NOT include the period at the end.
- Add a single space, which is required to separate the preprocessor directive from the identifier.
- 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.
- Add a single space, which is required to separate the identifier from its value.
- 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.
- Add a new section called Prototypes as follows:
- Add a single blank line below the #define statement from step 5; see step 5a for more information.
- Add a single line (heading type) comment on its own line: // Prototypes. Do NOT include the period at the end.
- 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
- Create a prototype for the function in step 7 in the prototype section, see step 6, by doing the following:
- Copy the function header, i.e., the first line of the function, and paste it under the // Prototype comment.
- Replace the space and left brace at the end with a semicolon, e.g., double getNumber();.
- Immediately above the function definition, put a set of appropriate PPR comments; see the Template, Code Conventions, and Announcements for more information and examples.
- 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
- In main(), below the Variable section, add a heading type comment: // Input. Do NOT include the period at the end.
- 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();.
- Repeat step 12 for another number/variable. Do NOT use a loop.
- 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().
- Create a prototype for the function in step 14; see step 8 for more information. Make sure all prototypes are in alphabetical order.
- Create a set of PPR comments for the function in step 14; see step 9 for more information.
- In main(), below the Input section, add a heading type comment: // Calculations. Do NOT include the period at the end.
- 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.
- 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.
- 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().
- Create a prototype for the function in step 20; see step 8 for more information. Make sure all prototypes are in alphabetical order.
- Create a set of PPR comments for the function in step 20; see step 9 for more information.
- In main(), below the Input section, add a heading type comment: // Output. Do NOT include the period at the end.
- In main(), call the function from step 20 passing the numbers from steps 12 and 13, and 14 through 19 to the function.
- 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().
- Create a prototype for the function in step 25; see step 8 for more information. Make sure all prototypes are in alphabetical order.
- Create a set of PPR comments for the function in step 25; see step 9 for more information.
- 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.
- 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.
- Don't forget to include return 0; at the end of main().
- There should only be one return statement at the end of each function, if appropriate; see the Code Conventions, etc.
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started