summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/cst116-lab3-wilson.cpp
diff options
context:
space:
mode:
authorjacobdw22 <[email protected]>2022-11-28 15:05:09 -0800
committerjacobdw22 <[email protected]>2022-11-28 15:05:09 -0800
commit598e9d293db0f2305742fa39507185a1f031a803 (patch)
tree3d533109e687f21e6479ec1dd4b19aab71c2ed08 /BlankConsoleLab/cst116-lab3-wilson.cpp
parentdeleted useless comment (diff)
downloadcst116-lab3-jacobdw22-598e9d293db0f2305742fa39507185a1f031a803.tar.xz
cst116-lab3-jacobdw22-598e9d293db0f2305742fa39507185a1f031a803.zip
Infile fully working, plus added pseudo code for most of main and ReadData functions
Diffstat (limited to 'BlankConsoleLab/cst116-lab3-wilson.cpp')
-rw-r--r--BlankConsoleLab/cst116-lab3-wilson.cpp72
1 files changed, 36 insertions, 36 deletions
diff --git a/BlankConsoleLab/cst116-lab3-wilson.cpp b/BlankConsoleLab/cst116-lab3-wilson.cpp
index 858fc10..95d92d2 100644
--- a/BlankConsoleLab/cst116-lab3-wilson.cpp
+++ b/BlankConsoleLab/cst116-lab3-wilson.cpp
@@ -17,7 +17,7 @@ using std::ios;
using std::ifstream;
using std::ofstream;
-const int MAX = 60;
+const int MAX = 50;
int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int psgr[], float
dist[], float fare[], float toll[]);
@@ -43,51 +43,52 @@ int main()
ofstream outFile;
outFile.open("C:\\TEMP1\\lab3_Report.txt");
- char file = 'a';
- cout << "Please choose a file to open. Press 's' for small.txt, or press 'l' for large.txt: ";
- cin >> file;
- cout << endl;
- switch (file) {
- case 's':
- inFile.open("C:\\TEMP1\\small.txt");
- break;
- case 'l':
- inFile.open("C:\\TEMP1\\large.txt");
- break;
+ 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
+
+ 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 (inFile.is_open()) //If the infile is open
{
record_counter = ReadData(inFile, outFile, pick, drop, psgr, dist,
- fare, toll);
- inFile.close();
- if (outFile.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);
- PrintTotalsAndSummary(outFile, record_counter);
- outFile.close();
+ dist, fare, toll, record_counter); //Do the WriteOutptFile function
+ PrintTotalsAndSummary(outFile, record_counter); //Do the PrintTotalsAndSummary function
+ outFile.close(); //Close the output file
}
- else
+ else //Otherwise, do this
{
- cout << "Trouble Opening Output File";
- cout << "\n\n\t\t ** About to EXIT NOW! ** ";
+ cout << "Trouble Opening Output File"; //Print text
+ cout << "\n\n\t\t ** About to EXIT NOW! ** "; //Print text
}
}
- else
+ else //Otherwise, do this
{
- cout << "Trouble Opening Input File";
- cout << "\n\n\t\t ** About to EXIT NOW! ** ";
+ cout << "Trouble Opening Input File"; //Print text
+ cout << "\n\n\t\t ** About to EXIT NOW! ** "; //Print text
}
- return 0;
+ 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[])
+ dist[], float fare[], float toll[]) //Function to ReadData from the input file
{
- int counter = 0;
+ int counter = 0; //Set variable counter
inFile >> pick[counter] >> drop[counter] >> psgr[counter] >>
- dist[counter] >> fare[counter] >> toll[counter]; // Priming Read
- while (!inFile.eof())
+ 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)
@@ -100,18 +101,17 @@ int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int ps
<< setw(14) << fare[counter] <<
resetiosflags(ios::left)
<< setw(14) << toll[counter]
- << endl;
- counter++;
+ << endl; //Print infile data as a table
+ counter++; //Add 1 to counter
inFile >> pick[counter] >> drop[counter] >> psgr[counter]
>> dist[counter] >> fare[counter] >> toll[counter];
}
- return counter;
+ return counter; //Return variable counter
}
void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int
- psgr[], float dist[], float fare[], float toll[],
- int counter)
+ psgr[], float dist[], float fare[], float toll[], int counter) //Function to write the output file
{
- outFile << " Here is the Output File" << endl;
+ outFile << " Here is the Output File" << endl; //Print text to the out file
for (int r = 0; r <= counter - 1; r++)
{
outFile << setiosflags(ios::left) << setw(5)