View the step-by-step solution to:

// // // // // // // // // // // Example 3-9 This program shows the use of library function calls. Several libraries of functions ship with your...

You should write a batch (file input) program that reads this data in this format (laid out as you see it above, on four lines) from a textfile, then produces a report (sent to a disk file) that displays it along with the current ratio for each year. Assume 2010, 2011, and 2012 are the three years in question. Here's sample output for the data you see above:

Hi-Tech Leisure Products. ex39 is data file and ex43 is example. in d previous answer u dint use d current Ratio formula to get d current ratio. now plz use Ratio n A average formula to get d Current Ratio n Average. 







Current Ratio Report

                Current           Current          Current
Year            Assets            Liabilities      Ratio
----------------------------------------------------------
2010              47900             31007             1.54
2011              34500              9100             3.79
2012              57984             14822             3.91
----------------------------------------------------------
Average           46795             18310             3.08

This report produced by Raul Jimenez.

 

The data will allows be whole values (no cents), but may run into the millions. No cents are to be displayed. The current ratio will always be displayed rounded to two decimal digits, and could be up to 9999.99. The averages are rounded to the nearest whole dollar. 

You must create the data file in the manner discussed in the lecture.

Note that the various asset and liability numbers could be 5 digit, 4 digit, or even 3 digit or 6 digit. The numeric formats you use to print should not vary based on what you see for this particular set of sample data. Your program should be able to consistently produce a properly aligned report with all different sizes of numbers without changing the code!

Please be careful in noting how things are aligned. The "t" in "Current" is over the last digit of each number. Proper and exact alignment of all elements of the report will be part of your score.

The program must be written using modularity (voided functions), which is this week’s topic. If you do not build this program using void functions, major points will be deducted.

Replace Raul Jimenez with your name. You can “hard-code” this into the statement; it won’t be necessary to use a defined constant for this.

Warning: Be careful with your calculations. The average current ratio (at the bottom of the table) is the average of the three current ratios, not the quotient of the average assets and average liabilities. The wrong algorithm will cost you major points. 

Hint

You will need to use fgets() instead of fscanf() for the name of the company. fscanf() cannot read a string with embedded spaces.

What You Are Expected To Submit

For this assignment, I want you to develop (but not turn in) a full top-down design including a Hierarchy Chart, and a Nassi-Schneiderman Chart for each module box. 

You will submit only the source code file (.c) and the unaltered (ahem!) output file (.txt) from your run of the program. Place your name in the comments of the source code file and make sure your program prints your name in the last line of the report in the output file. Do not zip the files. And please, use .c for the source code and .txt for the output file. No Word documents or other such formats.



// Example 3-9 // // This program shows the use of library function calls. // Several libraries of functions ship with your compiler, and most // companies have also generated their own set of custom functions. // The purpose of a function as used below is to take some information, // perform some calculations, and return a value to the expression where // the function is "invoked". The floor() function takes a numeric // value and returns the highest integer contained in the value. // For positive numbers, this essentially truncates the decimal portion. // This function is located in the math.h library. #include <stdio.h> #include <math.h> char name[15]; int empnum; float amount; float SalesTax; float total; int dollars; int cents; // This could be int, but read about the "quirk" in the lecture notes and below main() { printf("**Mini Register Program**\n\n"); printf("Please enter your name: "); gets(name); printf("%s, please enter your employee number: ", name); scanf("%d", &empnum); printf("Please enter amount of sale: $"); scanf("%f", &amount); SalesTax = amount * .09; total = amount + SalesTax; printf("\n"); printf("Cashier: %s\n", name); printf("Employee #%d\n\n", empnum); printf("Amount of sale: $%8.2f\n", amount); printf("CA Sales Tax: $%8.2f\n", SalesTax); printf("-------------------------\n"); printf("Total: $%8.2f\n", total); dollars = floor(total); cents = floor((total-dollars) * 100); printf("\n"); printf("Pay %d dollars and %d cents.\n", dollars, cents); return 0; } // Why doesn't cents = floor((total-dollars) * 100) and printf("Pay %d dollars and %d cents.\n", dollars, cents); // not work? See the lecture notes for a hint. You can also swap these two statements for their counterparts above and run a few tests // to see what happens. I wouldn't expect you to pay too much attention to this since you are first starting // but it's a good example that often complexities get the best of you in
Background image of page 1
programming.
Background image of page 2
// // Example 4-3 Mini-Register Program developed using a more modular approach // // In this example, we see a divide-and-conquer approach to the program // structure which utilizes functions which do not return values (void). // // C Libraries Used #include <stdio.h> #include <math.h> // Constant definitions const float TAXRATE = 0.09; // Current Sales Tax Rate // Global Variable declarations char name[16]; // name of the cashier int empnum; // employee number float amount; // amount of the sale float SalesTax; // calculated sales tax float total; // total including tax int dollars; // dollar portion of total float cents; // cents portion of total // Function Prototypes // // These are the functions that will be called during the execution of the // program. This section is required by the C compiler. It wants to know about // the basic structure of everything before any particular element is used. // This enables the main function to call any of the other functions, and each // of the other functions can call any of the other functions. void GetInfo(void); // Prototype for GetInfo function void DoCalcs(void); // Prototype for DoCalcs function void Report(void); // Prototype for Report function //***************************************************************************** //**************************************************************************** // M A I N F U N C T I O N //**************************************************************************** //**************************************************************************** int main(void){ printf("**Mini Register Program**\n\n"); GetInfo(); // Prompt user for information DoCalcs(); // Calculate tax and total, dollars and cents Report(); // Display the final report return 0; } //**************************************************************************** // The GetInfo function prompts the user for three pieces of information: // their name, their employee number, and the amount of sale. // This function relies on global variables and returns no values. //**************************************************************************** void GetInfo(void){ printf("Please enter your name: ");
Background image of page 1
scanf("%s", &name); printf("%s, please enter your employee number: ", name); scanf("%d", &empnum); printf("Please enter amount of sale: $"); scanf("%f", &amount); } //**************************************************************************** // The DoCalcs function calculates the sales tax and total, based on the // amount read in during GetInfo and the tax rate constant. It also determines // the dollar portion of the total and the cents portion of the total. // This function relies on global variables and returns no values. //**************************************************************************** void DoCalcs(void) { // Calculate tax and total SalesTax = amount * TAXRATE; total = amount + SalesTax; // Separate dollars and cents dollars = floor(total); cents = (total-dollars) * 100; } //**************************************************************************** // The Report function prints an on screen report summarizing the calculations // performed in the DoCalcs function. // This function relies on global variables and returns no values. //**************************************************************************** void Report(void) { printf("\n"); printf("Cashier: %s\n", name); printf("Employee #%d\n\n", empnum); printf("Amount of sale: $%8.2f\n", amount); printf("CA Sales Tax: $%8.2f\n", SalesTax); printf("-------------------------\n"); printf("Total: $%8.2f\n", total); printf("\n"); printf("Pay %d dollars and %0.0f cents.\n", dollars, cents); }
Background image of page 2
Sign up to view the entire interaction

Top Answer

Here's the explanation you needed for... View the full answer

ex39.c

// C Libraries Used
#include &lt;stdio.h&gt;
#include &lt;math.h&gt;
// Global Variable declarations
FILE *inputFile;
// input file pointer
char companyName[30];
// company name
int currentAssets;...

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online