summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMusa Ahmed <[email protected]>2022-11-30 17:46:37 -0800
committerMusa Ahmed <[email protected]>2022-11-30 17:46:37 -0800
commitaf7d9b8c748d5382a389f76cfc9e582e161f3f4d (patch)
tree63d6546e79cddea5fb3d15119b0ca2eb215adedd
parentformatted properly (diff)
downloadcst116-lab3-m005a-af7d9b8c748d5382a389f76cfc9e582e161f3f4d.tar.xz
cst116-lab3-m005a-af7d9b8c748d5382a389f76cfc9e582e161f3f4d.zip
added pseudocode and output files
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj4
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj.filters8
-rw-r--r--BlankConsoleLab/CST116-Lab3-Output.txt91
-rw-r--r--BlankConsoleLab/CST116-Lab3-Pseudocode.txt73
-rw-r--r--BlankConsoleLab/Lab3-Ahmed.cpp67
5 files changed, 213 insertions, 30 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj
index e775e18..4d48773 100644
--- a/BlankConsoleLab/BlankConsoleLab.vcxproj
+++ b/BlankConsoleLab/BlankConsoleLab.vcxproj
@@ -141,6 +141,10 @@
<ItemGroup>
<ClCompile Include="Lab3-Ahmed.cpp" />
</ItemGroup>
+ <ItemGroup>
+ <Text Include="CST116-Lab3-Output.txt" />
+ <Text Include="CST116-Lab3-Pseudocode.txt" />
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters
index e357aea..2dfd9f0 100644
--- a/BlankConsoleLab/BlankConsoleLab.vcxproj.filters
+++ b/BlankConsoleLab/BlankConsoleLab.vcxproj.filters
@@ -19,4 +19,12 @@
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
+ <ItemGroup>
+ <Text Include="CST116-Lab3-Output.txt">
+ <Filter>Source Files</Filter>
+ </Text>
+ <Text Include="CST116-Lab3-Pseudocode.txt">
+ <Filter>Source Files</Filter>
+ </Text>
+ </ItemGroup>
</Project> \ No newline at end of file
diff --git a/BlankConsoleLab/CST116-Lab3-Output.txt b/BlankConsoleLab/CST116-Lab3-Output.txt
new file mode 100644
index 0000000..9ae6094
--- /dev/null
+++ b/BlankConsoleLab/CST116-Lab3-Output.txt
@@ -0,0 +1,91 @@
+OUTPUT FOR LARGE TEXT
+
+Please enter the input file name including extension:
+large.txt
+Trip Pick Drop # ppl Distance Fare Toll Total Cost per Mile
+0 129 7 3 1.3 7.5 0 7.5 5.77
+1 36 69 1 11.4 32 5.76 37.8 3.31
+2 7 41 1 4.6 15 5.76 20.8 4.51
+3 150 61 2 6.75 23 0 23 3.41
+4 112 17 1 3.84 15 0 15 3.91
+5 80 112 6 1.64 9.5 0 9.5 5.79
+6 256 183 1 16.1 44.5 0 44.5 2.77
+7 138 166 2 7.4 24.5 6.12 30.6 4.14
+8 142 50 5 1.7 8 0 8 4.71
+9 107 163 0 3.6 17 0 17 4.72
+10 132 3 2 19.1 52 6.12 58.1 3.04
+11 48 41 1 4.07 18 4.36 22.4 5.49
+12 132 226 1 14.3 39 0 39 2.73
+13 229 151 1 3.96 14.5 4.58 19.1 4.82
+14 238 166 1 0.76 4.5 0 4.5 5.92
+15 151 238 2 0.64 5 2.2 7.2 11.2
+16 138 82 4 3 12 0 12 4
+17 264 231 3 10.7 32.5 0 32.5 3.03
+18 170 114 5 2.01 9 0 9 4.48
+19 186 87 2 3.45 12 0 12 3.48
+20 209 256 1 3.79 17 0 17 4.49
+21 132 107 1 17.2 52 6.12 58.1 3.38
+22 232 112 1 3.1 11 0 11 3.55
+23 164 141 3 2.85 10.5 0 10.5 3.68
+24 129 7 3 1.3 7.5 0 7.5 5.77
+25 36 69 1 11.4 32 5.76 37.8 3.31
+26 7 41 1 4.6 15 5.76 20.8 4.51
+27 150 61 2 6.75 23 0 23 3.41
+28 112 17 1 3.84 15 0 15 3.91
+29 80 112 6 1.64 9.5 0 9.5 5.79
+30 256 183 1 16.1 44.5 0 44.5 2.77
+31 138 166 2 7.4 24.5 6.12 30.6 4.14
+32 142 50 5 1.7 8 0 8 4.71
+33 107 163 0 3.6 17 0 17 4.72
+34 132 3 2 19.1 52 6.12 58.1 3.04
+35 48 41 1 4.07 18 4.36 22.4 5.49
+36 132 226 1 14.3 39 0 39 2.73
+37 229 151 1 3.96 14.5 4.58 19.1 4.82
+38 238 166 1 0.76 4.5 0 4.5 5.92
+39 151 238 2 0.64 5 2.2 7.2 11.2
+40 138 82 4 3 12 0 12 4
+41 264 231 3 10.7 32.5 0 32.5 3.03
+42 170 114 5 2.01 9 0 9 4.48
+43 186 87 2 3.45 12 0 12 3.48
+44 209 256 1 3.79 17 0 17 4.49
+45 132 107 1 17.2 52 6.12 58.1 3.38
+46 232 112 1 3.1 11 0 11 3.55
+47 164 141 3 2.85 10.5 0 10.5 3.68
+
+
+ ** Avg Cost Per Person: 10.5 **
+
+
+ ** People Transported: 100 **
+
+
+ ** Total Cost: 1052 **
+ The End
+
+
+OUTPUT FOR SMALL TEXT
+
+
+Please enter the input file name including extension:
+small.txt
+Trip Pick Drop # ppl Distance Fare Toll Total Cost per Mile
+0 129 7 3 1.3 7.5 0 7.5 5.77
+1 36 69 1 11.4 32 5.76 37.8 3.31
+2 7 41 1 4.6 15 5.76 20.8 4.51
+3 150 61 2 6.75 23 0 23 3.41
+4 112 17 1 3.84 15 0 15 3.91
+5 80 112 6 1.64 9.5 0 9.5 5.79
+
+
+ ** Avg Cost Per Person: 8.11 **
+
+
+ ** People Transported: 14 **
+
+
+ ** Total Cost: 113.52 **
+ The End
+
+C:\Users\macho\source\repos\cst116-lab3-M005A\x64\Debug\BlankConsoleLab.exe (process 9692) exited with code 0.
+To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
+Press any key to close this window . . . \ No newline at end of file
diff --git a/BlankConsoleLab/CST116-Lab3-Pseudocode.txt b/BlankConsoleLab/CST116-Lab3-Pseudocode.txt
new file mode 100644
index 0000000..059fda7
--- /dev/null
+++ b/BlankConsoleLab/CST116-Lab3-Pseudocode.txt
@@ -0,0 +1,73 @@
+Initialize a constant int MAX for the maximum amount of records, set to 50
+
+START MAIN
+
+initialize function ReadData, with input file, arrays, and counters
+initialize function WriteOutputFile with output file, counters, and arrays
+initialize PrintTotalsAndSummary with output file, counters, and arrays
+
+Initialize an array for each needed value, with the length being equal to max
+initialize record counter
+initialize people counter
+initialize payment counter
+
+initialize filename
+initialize input file
+initialize output file
+
+prompt the user to input a filename wiht extension
+ set the input equal to filename
+
+open the file
+
+if the file is open
+ call the function ReadData and have its return value be set into record_counter
+
+ close the input file
+
+ if the output file is open
+ call the functions writeoutputfile and printotalsummary
+ close the output file
+
+ else
+ print an error message
+else
+ print an error message
+
+return 0
+
+END MAIN
+
+ReadData
+
+ prints out headers corresponding to each array
+ read in the first line of data from the input file and have it set to the first of each array
+
+ while it is not the end of the file
+ the totalfare at the current index is equal to the far + toll
+ print out the arrays at the current index, formatting into a table
+
+ if the distance at the current index is 0, the cost per mile is 0
+ otherwise the cost per mile is equal to the total cost over the distance
+
+ increment the index
+ read data again
+
+ return counter
+
+
+WriteOutputFile
+
+ enter a for loop which goes until the end of the total records in the file
+ print out all the modified data to the output file at the current index
+
+PrintTotalsAndSummary
+
+ enter a for loop which goes until the end of the total records in the file
+ set the total amount of people to the array of passCount at the index added together
+ set a double temp equal to the far + toll at the current index
+ paid += temp
+ the totalFare at the current index is equal to temp
+
+ print out the avg cost per person, # people transported, and the total cost to both
+ the screen and the output file.
diff --git a/BlankConsoleLab/Lab3-Ahmed.cpp b/BlankConsoleLab/Lab3-Ahmed.cpp
index a78d875..72076d7 100644
--- a/BlankConsoleLab/Lab3-Ahmed.cpp
+++ b/BlankConsoleLab/Lab3-Ahmed.cpp
@@ -13,48 +13,60 @@ using std::ios;
using std::string;
using std::ifstream;
using std::ofstream;
-using namespace std;
+using std::setprecision;
+// The max amount of records in one file
const int MAX = 50;
-int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float costPMile[], int counter, float totalFare[]);
-void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float costPMile[]);
-void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int passCount[], float distance[], float fare[], float toll[], float totalFare[], float costPMile[], float paid);
+// initialize all functions
+int ReadData(ifstream& inFile, int pick[], int drop[], int passCount[], double distance[], double fare[], double toll[], double costPMile[], int counter, double totalFare[]);
+void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], double distance[], double fare[], double toll[], double costPMile[]);
+void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int passCount[], double distance[], double fare[], double toll[], double totalFare[], double costPMile[], double paid);
+
int main()
{
+ // initialize all arrays and counters
int pick[MAX];
int drop[MAX];
int passCount[MAX];
- float distance[MAX];
- float fare[MAX];
- float toll[MAX];
- float totalFare[MAX] = { 0 };
- float costPMile[MAX] = { 0 };
+ double distance[MAX];
+ double fare[MAX];
+ double toll[MAX];
+ double totalFare[MAX] = { 0 };
+ double costPMile[MAX] = { 0 };
int record_counter(0);
int people(0);
int counter = 0;
- float paid = 0;
+ double paid = 0;
+ // initialize files
string filename;
ifstream inFile;
-
- // Notice how this automatically opens the file
ofstream outFile("out.txt");
+
+
cout << "Please enter the input file name including extension: " << endl;
cin >> filename;
+
+ // open the requested file
inFile.open(filename);
if (inFile.is_open())
{
- record_counter = ReadData(inFile, outFile, pick, drop, passCount, distance, fare, toll, costPMile, counter, totalFare);
+ // read the data from the file, and output the total number of records (store into arrays)
+ record_counter = ReadData(inFile, pick, drop, passCount, distance, fare, toll, costPMile, counter, totalFare);
+
+ // close the read file
inFile.close();
if (outFile.is_open())
{
+ // write the new data to the output file
WriteOutputFile(outFile, record_counter, people, pick, drop, passCount, distance, fare, toll, costPMile);
+ // output the summary both to screen and to file
PrintTotalsAndSummary(outFile, record_counter, people, passCount, distance, fare, toll, totalFare, costPMile, paid);
outFile.close();
}
@@ -71,10 +83,10 @@ int main()
}
return 0;
}
-int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float costPMile[], int counter, float totalFare[])
+int ReadData(ifstream& inFile, int pick[], int drop[], int passCount[], double distance[], double fare[], double toll[], double costPMile[], int counter, double totalFare[])
{
-
+ // print headers
cout << setiosflags(ios::left) << setw(10) << "Trip" << setw(15)
<< "Pick" << setw(10) << "Drop" << setw(10)
<< "# ppl"
@@ -85,6 +97,7 @@ int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int pa
<< setw(10) << "Cost per Mile" << endl;
inFile >> pick[counter] >> drop[counter] >> passCount[counter] >> distance[counter] >> fare[counter] >> toll[counter]; // Priming Read
+ // read all of the data into arrays
while (!inFile.eof())
{
totalFare[counter] = fare[counter] + toll[counter];
@@ -96,9 +109,11 @@ int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int pa
<< fare[counter]
<< setw(10) << toll[counter] << setw(15)
<< totalFare[counter] << setw(10);
+ // if distance is 0 then there is no cost per mile
if (distance[counter] == 0) {
costPMile[counter] = 0;
}
+ // cost per mile = (toll + fare) / distance
else {
costPMile[counter] = (toll[counter] + fare[counter]) / distance[counter];
}
@@ -111,10 +126,10 @@ int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int pa
return counter;
}
-void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], float distance[], float fare[], float toll[], float costPMile[])
+void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[], int drop[], int passCount[], double distance[], double fare[], double toll[], double costPMile[])
{
-
+ // write the same data to the output files
outFile << " Here is the Output File" << endl;
for (int r = 0; r < totalRecords; r++)
{
@@ -130,31 +145,23 @@ void WriteOutputFile(ofstream& outFile, int totalRecords, int people, int pick[]
}
}
-void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int passCount[], float distance[], float fare[], float toll[], float totalFare[], float costPMile[], float paid)
+void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int people, int passCount[], double distance[], double fare[], double toll[], double totalFare[], double costPMile[], double paid)
{
+ // do the calculations for all of the totals.
for (int i = 0; i < totalRecords; i++) {
people += passCount[i];
- float temp = fare[i] + toll[i];
+ double temp = fare[i] + toll[i];
paid += temp;
totalFare[i] = temp;
- if (distance == 0) {
- costPMile[i] = 0;
- }
-
- else {
- costPMile[i] = totalFare[i] / distance[i];
- // cout << costPMile[i];
- }
}
- // To screen
+ // print ot screen
cout << "\n\n\t** Avg Cost Per Person: " << paid/people << " **\n"
<< "\n\n\t** People Transported: " << people << " **\n"
<< "\n\n\t** Total Cost: " << setprecision(5) << paid << " **\n"
<< "\t\t The End \n";
-
- // To file
+ // print to output file
outFile << "\n\n\t** Avg Cost Per Person: " << paid/people << " **\n"
<< "\n\n\t** People Transported: " << people << " **\n"
<< "\n\n\t** Total Cost: " << paid << " **\n"