CS136-Projects/PA07-1102/Project_7.c
cdez b547836f9f Modify Project 7
+- Project 7 Files
2022-11-09 18:10:32 -07:00

229 lines
5.7 KiB
C

// header files
#include <time.h>
#include <stdlib.h>
#include "Console_IO_Utility.h"
#include "File_Output_Utility.h"
#include "File_Input_Utility.h"
// global variables
const int MIN_RAND_COUNT = 1;
const int MAX_RAND_COUNT = 10;
const int MIN_RAND_LIMIT = 1;
const int MAX_RAND_LIMIT = 100000;
const int VALUES_IN_ONE_LINE = 5;
// function prototypes
void displayResults();
void generateRandomValues();
int calculateTotal(int *taxArray, int numValsTaxArray);
int getRandBetween(int minimumRandomLimit, int maximumRandomLimit);
void printTitle();
int saveData(int *fileName);
int main()
{
// initialize variables
int taxArray[MAX_RAND_COUNT];
char fileName[STD_STR_LEN];
int numIncomeSources, sumIncomeSources;
int counter;
bool fileOpen;
// show title of program
printTitle();
// get user input
// ask user for the filename of where their data is located.
promptForString("\nEnter the file name for random data generation: ",
fileName);
// do calculations
// seed rand
srand(time(NULL));
// check if the file exists, and if it doesn't, generate random values.
fileOpen = openInputFile(fileName);
if(fileOpen)
{
for (counter = 0; counter < MAX_RAND_COUNT; counter++) {
taxArray[counter] = readIntegerFromFile();
}
}
else
{
generateRandomValues(fileName, MIN_RAND_COUNT, MAX_RAND_COUNT);
}
// display results
displayResults(numIncomeSources, sumIncomeSources);
// end program
printf("\nEnd Program\n");
return 0;
}
/*
Name: displayResults
Process: display results, if found
Function Input/Parameters: numIncomeSourcesValue, sumIncomeSourcesValue
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: printf or Console IO Utilities
*/
void displayResults(int numIncomeSourcesValue, int sumIncomeSourcesValue)
{
// initialize variables
// get user input
// do calculations
// display results
printf("\nTotal Sources of Income: %d\n", numIncomeSources);
printf("\nTotal Income : %d\n", sumIncomeSources);
// return value
}
/*
Name: downloadRandomValues (not download, GENERATE)
Process: takes file, min/max vals, opens file and puts in rand vals generated.
Function Input/Parameters: fileName, minimumRandomCount, maximumRandomCount
Function Output/Parameters: fileName
Function Output/Returned: none
Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: getRandBetween
*/
void generateRandomValues(char *filename, int minimumRandomCount, int maximumRandomCount)
{
// initialize variables
bool fileOpen;
int numberOfValues;
// get user input
// input is passed in through parameters
// do calculations
// create a file.
fileOpen = openOutputFile(filename);
if(fileOpen)
{
for (numberOfValues = getRandBetween(minimumRandomCount,
maximumRandomCount); numberOfValues < count; numberOfValues++)
{
/* code */
}
}
else
{
//place
}
// display results
}
/*
Name: calculateTotal
Process: totals the array numbers, return the sum.
Function Input/Parameters: *taxArray, numValsTaxArray
Function Output/Parameters: none
Function Output/Returned: summedTaxArray
Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: ???
*/
int calculateTotal(int *taxArray, int numValsTaxArray)
{
// initialize variables
int summedTaxArray;
int iterator, counter;
iterator = 0;
// get user input
// passed in through function parameter
// do calculations
// need to total the array's values, and count up the array values.
// use a loop to iterate through the array.
for (counter = iterator; counter < numValsTaxArray; counter++)
{
summedTaxArray = summedTaxArray + taxArray[counter];
}
// display results
// none
// return value
return summedTaxArray;
}
/*
Name: getRandBetween
Process: generates a random number between a high and low value (inclusive)
Function Input/Parameters: minimumRandomLimit, maximumRandomLimit
Function Output/Parameters: randomly generated value
Function Output/Returned: none
Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: rand, srand
*/
int getRandBetween(int minimumRandomLimit, int maximumRandomLimit)
{
// initialize variables
int range;
// get user input
// none
// do calculations
range = maximumRandomLimit - minimumRandomLimit + 1
// display results
// none
// return value
return rand() % range + minimumRandomLimit;
}
/*
Name: printTitle
Process: prints the program title and double underline
Function Input/Parameters: none
Function Output/Parameters: none
Function Output/Returned: none
Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: printf and Console IO Utility
*/
void printTitle()
{
// initialize variables
// none
// get user input
// none
// do calculations
// none
// display results
// print the title of the program and the equals characters.
printf("\nTotal Income From File Calculator\n");
printCharacters(33, '=');
printf("\n");
// return value
// none
}
/*
Name: uploadData (not uploading, SAVING.)
Process: opens file, loads data into file, closes file, returns num values
Function Input/Parameters: fileName
Function Output/Parameters: none
Function Output/Returned: numberOfValues
Device Input/Keyboard: none
Device Output/Monitor: none
Dependencies: File IO Utilities
*/
int saveData(int *fileName)
{
// initialize variables
// get user input
// do calculations
// display results
// return value
}