diff options
| author | jacobdw22 <[email protected]> | 2022-11-28 17:12:05 -0800 |
|---|---|---|
| committer | jacobdw22 <[email protected]> | 2022-11-28 17:12:05 -0800 |
| commit | 54f23e759ed5cb9b702b71820584741b175eb25d (patch) | |
| tree | 8bf4f07341e270d8c57feac704a0674cc2336388 | |
| parent | Now also prints to output file (diff) | |
| download | cst116-lab3-jacobdw22-54f23e759ed5cb9b702b71820584741b175eb25d.tar.xz cst116-lab3-jacobdw22-54f23e759ed5cb9b702b71820584741b175eb25d.zip | |
Added total_fare, which adds the fare and toll together. I also completed the pseudo code comments throughout the currently complete code.
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.vcxproj | 2 | ||||
| -rw-r--r-- | BlankConsoleLab/BlankConsoleLab.vcxproj.filters | 1 | ||||
| -rw-r--r-- | BlankConsoleLab/cst116-lab3-wilson.cpp | 144 |
3 files changed, 79 insertions, 68 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj index db75489..55c9f54 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj @@ -24,6 +24,7 @@ <ProjectGuid>{3cecade6-3e15-4852-bd24-65bfe5d3a3aa}</ProjectGuid> <RootNamespace>BlankConsoleLab</RootNamespace> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + <ProjectName>cst116-lab3-wilson</ProjectName> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> @@ -145,6 +146,7 @@ <Text Include="..\..\..\..\..\..\TEMP1\lab3_Report.txt" /> <Text Include="..\..\..\..\..\..\TEMP1\large.txt" /> <Text Include="..\..\..\..\..\..\TEMP1\small.txt" /> + <Text Include="..\LabResults.txt" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters index 11fd168..71df60b 100644 --- a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters +++ b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters @@ -23,5 +23,6 @@ <Text Include="..\..\..\..\..\..\TEMP1\small.txt" /> <Text Include="..\..\..\..\..\..\TEMP1\large.txt" /> <Text Include="..\..\..\..\..\..\TEMP1\lab3_Report.txt" /> + <Text Include="..\LabResults.txt" /> </ItemGroup> </Project>
\ No newline at end of file diff --git a/BlankConsoleLab/cst116-lab3-wilson.cpp b/BlankConsoleLab/cst116-lab3-wilson.cpp index 95d92d2..dd587b4 100644 --- a/BlankConsoleLab/cst116-lab3-wilson.cpp +++ b/BlankConsoleLab/cst116-lab3-wilson.cpp @@ -3,92 +3,93 @@ help ALOT!!! Not many comments shown in order to require students to think Use an input file with 6 columns of numbers as required in Lab 3 Write up. Place file in correct path. -Name it lab3_data.txt */ -#include <iostream> -#include <fstream> // For the files!!!! -#include <iomanip> // For manipulators & formatting options -using std::cin; -using std::cout; -using std::endl; -using std::setw; -using std::ios; -using std::ifstream; -using std::ofstream; +#include <iostream> //For printing to the screen +#include <fstream> //For the files +#include <iomanip> //For manipulators & formatting options +using std::cin; //Allows use of cin +using std::cout; //Allows use of cout +using std::endl; //Allows end line +using std::setw; //Allows set width +using std::ios; //Allows inut/output stream commands -const int MAX = 50; +using std::ifstream; //Allows input file stream +using std::ofstream; //Allows output file stream + +const int MAX = 50; //Adds a constant int of 50, for the maximum number of records int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int psgr[], float - dist[], float fare[], float toll[]); + dist[], float fare[], float toll[]); //Defines function that reads data from the input file void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], - int counter); -void PrintTotalsAndSummary(ofstream& out, int totalRecords); + int counter); //Defines function that prints the data from input to output file +void PrintTotalsAndSummary(ofstream& out, int totalRecords); //Defines function that prints total records to screen and output file -int main() +int main() //Function main { - int pick[MAX]; - int drop[MAX]; - int psgr[MAX]; - float dist[MAX]; - float fare[MAX]; - float toll[MAX]; - int record_counter(0); + int pick[MAX]; //Defines array for pick up + int drop[MAX]; //Defines array for drop off + int psgr[MAX]; //Defines array for passengers + float dist[MAX]; //Defines array for distance + float fare[MAX]; //Defines array for fare + float toll[MAX]; //Defines array for toll + int record_counter(0); //Defines an int that tracks the number of records taken - ifstream inFile; + ifstream inFile; //Adds an infile to be used later - // Notice how this automatically opens the file + //Notice how this automatically opens the file - ofstream outFile; + ofstream outFile; //Adds an outfile to be used later outFile.open("C:\\TEMP1\\lab3_Report.txt"); - char file = 'a'; //sets variable to change input file - cout << "Please choose a file to open. Press 's' for small.txt, or press 'l' for large.txt: "; //Prompts user for nput file choice - cin >> file; //Reads in users choice for input file - cout << endl; //Prints new line + char file = 'a'; //sets variable to change input file + cout << "Please choose a file to open. Press 's' for small.txt" + << ", or press 'l' for large.txt: "; //Prompts user for input file choice + cin >> file; //Reads in users choice for input file + cout << endl; //Prints new line - switch (file) { //switch statement for variable file - case 's': //case when user inputs s for small - inFile.open("C:\\TEMP1\\small.txt"); //open small.txt - break; //end case - case 'l': //case when user inputs l for large - inFile.open("C:\\TEMP1\\large.txt"); //open large.txt - break; //end case + switch (file) { //switch statement for variable file + case 's': //case when user inputs s for small + inFile.open("C:\\TEMP1\\small.txt"); //open small.txt + break; //end case + case 'l': //case when user inputs l for large + inFile.open("C:\\TEMP1\\large.txt"); //open large.txt + break; //end case } - if (inFile.is_open()) //If the infile is open + if (inFile.is_open()) //If the infile is open { record_counter = ReadData(inFile, outFile, pick, drop, psgr, dist, - fare, toll); //Do the ReadData function and set it as new variable record_counter - inFile.close(); //Close the input file - if (outFile.is_open()) //If the output file is open + fare, toll); //Do the ReadData function and set it as new variable record_counter + inFile.close(); //Close the input file + if (outFile.is_open()) //If the output file is open { WriteOutputFile(outFile, pick, drop, psgr, - dist, fare, toll, record_counter); //Do the WriteOutptFile function - PrintTotalsAndSummary(outFile, record_counter); //Do the PrintTotalsAndSummary function - outFile.close(); //Close the output file + dist, fare, toll, record_counter); //Do the WriteOutptFile function + PrintTotalsAndSummary(outFile, record_counter); //Do the PrintTotalsAndSummary function + outFile.close(); //Close the output file } - else //Otherwise, do this + else //Otherwise, do this { - cout << "Trouble Opening Output File"; //Print text - cout << "\n\n\t\t ** About to EXIT NOW! ** "; //Print text + cout << "Trouble Opening Output File"; //Print text + cout << "\n\n\t\t ** About to EXIT NOW! ** "; //Print text } } - else //Otherwise, do this + else //Otherwise, do this { - cout << "Trouble Opening Input File"; //Print text - cout << "\n\n\t\t ** About to EXIT NOW! ** "; //Print text + cout << "Trouble Opening Input File"; //Print text + cout << "\n\n\t\t ** About to EXIT NOW! ** "; //Print text } - return 0; //Return empty value and end stream + return 0; //Return empty value and end stream } int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int psgr[], float - dist[], float fare[], float toll[]) //Function to ReadData from the input file + dist[], float fare[], float toll[]) //Function to ReadData from the input file { - int counter = 0; //Set variable counter + int counter = 0; //Set variable counter inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> - dist[counter] >> fare[counter] >> toll[counter]; //Priming Read - while (!inFile.eof()) //While not the end of the in file + dist[counter] >> fare[counter] >> toll[counter]; //Priming Read + while (!inFile.eof()) //While not the end of the in file { cout << setiosflags(ios::left) << setw(5) << pick[counter] << resetiosflags(ios::left) @@ -101,18 +102,22 @@ int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int ps << setw(14) << fare[counter] << resetiosflags(ios::left) << setw(14) << toll[counter] - << endl; //Print infile data as a table - counter++; //Add 1 to counter + << endl; //Print infile data as a table + + float total_fare = fare[counter] + toll[counter]; //Adds float total_fare + cout << "Total fare: " << total_fare << "\n\n"; //Prints total_fare to the screen + + counter++; //Add 1 to counter inFile >> pick[counter] >> drop[counter] >> psgr[counter] - >> dist[counter] >> fare[counter] >> toll[counter]; + >> dist[counter] >> fare[counter] >> toll[counter]; //Sets all of the arrays values to the new counter value } - return counter; //Return variable counter + return counter; //Return variable counter } void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int - psgr[], float dist[], float fare[], float toll[], int counter) //Function to write the output file + psgr[], float dist[], float fare[], float toll[], int counter) //Function to write the output file { - outFile << " Here is the Output File" << endl; //Print text to the out file - for (int r = 0; r <= counter - 1; r++) + outFile << " Here is the Output File" << endl; //Print text to the out file + for (int r = 0; r <= counter - 1; r++) //Loop while there is still data in the input file { outFile << setiosflags(ios::left) << setw(5) << pick[r] << resetiosflags(ios::left) @@ -125,15 +130,18 @@ void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int << setw(14) << fare[r] << resetiosflags(ios::left) << setw(14) << toll[r] - << endl; + << endl; //Print in file data as a table in the out file + + float total_fare = fare[r] + toll[r]; //Adds variable total_fare + outFile << "Total fare: " << total_fare << "\n\n"; //Prints total_fare to the out file } } -void PrintTotalsAndSummary(ofstream& outFile, int totalRecords) +void PrintTotalsAndSummary(ofstream& outFile, int totalRecords) //Function to print the total records { // To screen - cout << "\n\n\t** Total Records: " << totalRecords << " **\n" - << "\t\t The End \n"; + cout << "\n\n\t** Total Records: " << totalRecords << " **\n" //Prints the total records to the screen + << "\t\t The End \n"; //Prints The End to the screen // To file - outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" - << "\t\t The End \n"; + outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" //Prints the total records to the out file + << "\t\t The End \n"; //Prints The End to the out file }
\ No newline at end of file |