Added Lab07 Files
++ Lab 7 Files Signed-off-by: cdez <cdez@cdezselfhosted.pw>
This commit is contained in:
parent
b4a2c14805
commit
7db9595edf
9 changed files with 2842 additions and 0 deletions
120
Lab07/Lab_07.c
Normal file
120
Lab07/Lab_07.c
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
// header files
|
||||
#include "StandardConstants.h"
|
||||
#include "Console_IO_Utility.h"
|
||||
#include "File_Input_Utility.h"
|
||||
#include "File_Output_Utility.h"
|
||||
|
||||
// function prototypes
|
||||
|
||||
/*
|
||||
Name: calculateNetRevenue
|
||||
Process: opens input file calculates net revenue based on expenses and
|
||||
gross revenue; uses total years to iterate over expenses file;
|
||||
makes sure expenses are negative number before adding/subtracting
|
||||
Function input/parameters: file name (const char *), grossRevenue and totalYears
|
||||
Function output/parameters: none
|
||||
Function output/returned: net revenue (grossRevenue - expenses)
|
||||
Function input/keyboard: none
|
||||
Device output/file: none
|
||||
Dependencies: File Output Utility tools
|
||||
*/
|
||||
double calculateNetRevenue( const char *expensesDataFile,
|
||||
double grossRevenue,
|
||||
int totalYears);
|
||||
|
||||
|
||||
// main program
|
||||
int main()
|
||||
{
|
||||
// initialize variables, functions
|
||||
char expensesDataFile[ STD_STR_LEN ];
|
||||
double grossRevenue, netRevenue;
|
||||
int totalYears;
|
||||
|
||||
// show title
|
||||
// function: printf
|
||||
printf( "\nSimple Accountant Script\n" );
|
||||
printf( "==========================\n\n" );
|
||||
|
||||
// get input
|
||||
grossRevenue = promptForDouble("Enter gross revenue: ");
|
||||
totalYears = promptForInteger("Enter number of years: ");
|
||||
//printf("Enter file name containing expenses information: ");
|
||||
//scanf("%c\n", expensesDataFile);
|
||||
promptForString("Enter file name containing expenses information: ",
|
||||
expensesDataFile);
|
||||
|
||||
|
||||
// processing
|
||||
netRevenue =
|
||||
calculateNetRevenue(expensesDataFile, grossRevenue, totalYears);
|
||||
|
||||
// display results
|
||||
printf("\nThe total revenue in %d years is: $%.2f.\n\n",
|
||||
totalYears, netRevenue);
|
||||
|
||||
// end program
|
||||
printf("End Program\n");
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// supporting functions
|
||||
double calculateNetRevenue( const char *expensesDataFile,
|
||||
double grossRevenue,
|
||||
int totalYears)
|
||||
{
|
||||
// initialize variables
|
||||
int iterateNumber;
|
||||
int forCounter;
|
||||
double saveTotalNumberExpenses;
|
||||
double capturedOutput;
|
||||
iterateNumber = 0;
|
||||
saveTotalNumberExpenses = 0;
|
||||
capturedOutput = 0;
|
||||
|
||||
// get input
|
||||
// input passed in from function parameters
|
||||
|
||||
// do calculations
|
||||
// functions: openInputFile, readDoubleFromFile, checkForInputFileOpen,
|
||||
// checkForEndOfInputFile, closeInputFile
|
||||
// open the file
|
||||
openInputFile(expensesDataFile);
|
||||
|
||||
// use a loop to iterate over the file given number of years.
|
||||
for(forCounter = iterateNumber; forCounter < totalYears; forCounter++)
|
||||
{
|
||||
// capture output number
|
||||
capturedOutput = readDoubleFromFile();
|
||||
|
||||
// check if captured output number is negative
|
||||
if(capturedOutput < 0)
|
||||
{
|
||||
// total the number of expenses
|
||||
saveTotalNumberExpenses = saveTotalNumberExpenses - capturedOutput;
|
||||
}
|
||||
else
|
||||
{
|
||||
// if the data is positive, subtract it twice.
|
||||
capturedOutput = capturedOutput - capturedOutput - capturedOutput;
|
||||
saveTotalNumberExpenses = saveTotalNumberExpenses - capturedOutput;
|
||||
}
|
||||
|
||||
}
|
||||
// close input file
|
||||
closeInputFile(expensesDataFile);
|
||||
|
||||
|
||||
|
||||
// display results
|
||||
// no displayed output, returns only.
|
||||
|
||||
// return results
|
||||
// returns grossRevenue - saveTotalNumberExpenses
|
||||
return grossRevenue - saveTotalNumberExpenses;
|
||||
|
||||
// end function
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue