summaryrefslogtreecommitdiff
path: root/BlankConsoleLab
diff options
context:
space:
mode:
authorNathanturcas <[email protected]>2022-12-02 23:14:59 -0800
committerNathanturcas <[email protected]>2022-12-02 23:14:59 -0800
commit2badfd618b365de0f9acc8bbd4eef8c435e8dbb3 (patch)
tree0539fb6c7cfa9c5d8f43ccf64a0cc9ee90358e1b /BlankConsoleLab
parentSetting up GitHub Classroom Feedback (diff)
downloadcst116-lab3-nathanturcas-master.tar.xz
cst116-lab3-nathanturcas-master.zip
Diffstat (limited to 'BlankConsoleLab')
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp162
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj8
-rw-r--r--BlankConsoleLab/Lab3complete.cpp175
-rw-r--r--BlankConsoleLab/big.txt48
-rw-r--r--BlankConsoleLab/output.txt6
-rw-r--r--BlankConsoleLab/small.txt6
6 files changed, 396 insertions, 9 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index ed5f807..ebbdd32 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -1,16 +1,168 @@
-// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
-//
+//Lab 3 Nathan Turcas
#include <iostream>
+#include <iomanip>
+#include <fstream> // for files
+#include <string>
+#include <array>
using namespace std;
-
-using std::cout;
using std::cin;
+using std::cout;
using std::endl;
+using std::setw;
+using std::ios;
+using std::string;
+using std::ifstream;
+using std::ofstream;
+
+const int MAX = 50;
+
+int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int psgrCount[],
+ float distance[], float fare[], float toll[], float cpm[], int counter,
+ float totalFare[]);
+void WriteOutputFile(ofstream& outFile, int totalRecords, int psgr, int pick[], int drop[], int psgrCount[],
+ float distance[], float fare[], float toll[], float cpm[]);
+void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int psgr, int psgrCount[], float distance[],
+ float fare[], float toll[], float totalFare[], float cpm[], float paid);
int main()
{
- cout << "Hello World!\n";
+ int pick[MAX];
+ int drop[MAX];
+ int psgrCount[MAX];
+ float distance[MAX] = { 0 };
+ float fare[MAX];
+ float toll[MAX];
+ float totalFare[MAX] = { 0 };
+ float cpm[MAX] = { 0 };
+ int record_counter(0);
+ int psgr(0);
+ int counter = 0;
+ float paid = 0;
+ string file;
+
+ ifstream inFile; // write
+ ofstream outFile("output.txt"); //ouputs to this document
+ cout << "Enter file name including extensions: " << endl; //use big.txt
+ cin >> file;
+ inFile.open(file);
+
+ if (inFile.is_open())
+ {
+ record_counter = ReadData(inFile, outFile, pick, drop, psgrCount, distance, fare,
+ toll, cpm, counter, totalFare);
+ inFile.close();
+
+ if (outFile.is_open())
+ {
+ WriteOutputFile(outFile, record_counter, psgr, pick, drop, psgrCount, distance,
+ fare, toll, cpm);
+ PrintTotalsAndSummary(outFile, record_counter, psgr, psgrCount, distance, fare, toll,
+ totalFare, cpm, paid);
+ outFile.close();
+ }
+ else
+ {
+ cout << "Trouble Opening File";
+ cout << "\n\n\t\t ** About to EXIT NOW! ** " << endl;
+ }
+
+ }
+ else
+ {
+ cout << "Trouble Opening File";
+ cout << "\n\n\t\t ** About to EXIT NOW! ** " << endl;
+ }
+ return 0;
+
}
+int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int psgrCount[],
+ float distance[], float fare[], float toll[], float cpm[], int counter,
+ float totalFare[])
+{
+ //heading for table
+ cout << setiosflags(ios::left) << setw(10) << "Trip" <<
+ setw(15) << "PickUp" << setw(10) << "DropOff" <<
+ setw(10) << "# people" << setw(10) << "Distance" <<
+ setw(10) << "Fare" << setw(10) << "Toll" <<
+ setw(10) << "Total" << setw(10) << "Cost per mile" << endl;
+
+ inFile >> pick[counter] >> drop[counter] >> psgrCount[counter] >> distance[counter] >>
+ fare[counter] >> toll[counter]; //priming reading
+
+ while (!inFile.eof())
+ {
+ totalFare[counter] = fare[counter] + toll[counter]; //calculate total fare
+ cout << setiosflags(ios::left) << setw(10) << counter << setw(15) <<
+ pick[counter] << setw(10) << drop[counter] << setw(10) << psgrCount[counter] <<
+ setw(10) << distance[counter] << setw(10) << fare[counter] <<
+ setw(10) << toll[counter] << setw(15) << totalFare[counter] << setw(10) << endl;
+
+ if (distance[counter] == 0)
+ {
+ cpm[counter] = 0;
+ }
+ else
+ {
+ //calculates cost per mile
+ cpm[counter] = (toll[counter] + fare[counter]) / distance[counter];
+ }
+ cout << setprecision(2) << cpm[counter] << endl;
+ counter++;
+ inFile >> pick[counter] >> drop[counter] >> psgrCount[counter] >> distance[counter] >>
+ fare[counter] >> toll[counter];
+
+ }
+ return counter;
+}
+
+void WriteOutputFile(ofstream& outFile, int totalRecords, int psgr, int pick[], int drop[],
+ int psgrCount[], float distance[], float fare[], float toll[], float cpm[])
+{
+ outFile << "Here is the Output File" << endl;
+ for (int r = 0; r < totalRecords; r++)
+ {
+ outFile << setiosflags(ios::left) << setw(15) << pick[r] <<
+ setw(15) << drop[r] << setw(15) << psgrCount[r] << setw(15) <<
+ distance[r] << setw(15) << fare[r] << setw(15) << toll[r] << setw(15) <<
+ cpm[r] << endl;
+ }
+
+}
+
+void PrintTotalsAndSummary(ofstream& outFile, int totalrecords, int psgr, int passCount[],
+ float distance[], float fare[], float toll[], float totalFare[], float cpm[],
+ float paid)
+{
+ for (int i = 0; i < totalrecords; i++)
+ {
+ psgr += passCount[i];
+ float num = fare[i] + toll[i];
+ paid += num;
+ totalFare[i] = num;
+
+ if (distance == 0)
+ {
+ cpm[i] = 0;
+ }
+
+ else
+ {
+ cpm[i] = totalFare[i] / distance[i];
+ cout << cpm[i] << endl;
+ }
+ }
+
+ //to screen
+ cout << "\n\n\tAverage Cost Per Person: " << paid / psgr << "\n"
+ << "\n\n\t Number of People Transported: " << psgr << "\n"
+ << "\n\n\tTotal Cost: " << paid << "\n"
+ << "\t\t The End \n" << endl;
+ //to file
+ cout << "\n\n\tAverage Cost Per Person: " << paid / psgr << "\n"
+ << "\n\n\t Number of People Transported: " << psgr << "\n"
+ << "\n\n\tTotal Cost: " << paid << "\n"
+ << "\t\t The End \n" << endl;
+} \ No newline at end of file
diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj
index db2e734..d2e3ee2 100644
--- a/BlankConsoleLab/BlankConsoleLab.vcxproj
+++ b/BlankConsoleLab/BlankConsoleLab.vcxproj
@@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
diff --git a/BlankConsoleLab/Lab3complete.cpp b/BlankConsoleLab/Lab3complete.cpp
new file mode 100644
index 0000000..2d62003
--- /dev/null
+++ b/BlankConsoleLab/Lab3complete.cpp
@@ -0,0 +1,175 @@
+//Lab 3 Nathan Turcas
+
+#include <iostream>
+#include <iomanip>
+#include <fstream> // for files
+#include <string>
+#include <array>
+
+using namespace std;
+using std::cin;
+using std::cout;
+using std::endl;
+using std::setw;
+using std::ios;
+using std::string;
+using std::ifstream;
+using std::ofstream;
+
+const int MAX = 50;
+
+int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int psgrCount[],
+ float distance[], float fare[], float toll[], float cpm[], int counter,
+ float totalFare[]);
+void WriteOutputFile(ofstream& outFile, int totalRecords, int psgr, int pick[], int drop[], int psgrCount[],
+ float distance[], float fare[], float toll[], float cpm[]);
+void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int psgr, int psgrCount[], float distance[],
+ float fare[], float toll[], float totalFare[], float cpm[], float paid);
+
+int main()
+{
+ int pick[MAX];
+ int drop[MAX];
+ int psgrCount[MAX];
+ float distance[MAX] = { 0 };
+ float fare[MAX];
+ float toll[MAX];
+ float totalFare[MAX] = { 0 };
+ float cpm[MAX] = { 0 };
+ int record_counter(0);
+ int psgr(0);
+ int counter = 0;
+ float paid = 0;
+ string file;
+
+ ifstream inFile; // write C:\Users\turca\source\repos\cst116-lab3-nathanturcas\BlankConsoleLab \ (big.txt or small.txt) for the directory path.
+ ofstream outFile("output.txt");
+ cout << "Enter file name including extensions: " << endl;
+ cin >> file;
+ inFile.open(file);
+
+ if (inFile.is_open())
+ {
+ record_counter = ReadData(inFile, outFile, pick, drop, psgrCount, distance, fare,
+ toll, cpm, counter, totalFare);
+ inFile.close();
+
+ if (outFile.is_open())
+ {
+ WriteOutputFile(outFile, record_counter, psgr, pick, drop, psgrCount, distance,
+ fare, toll, cpm);
+ PrintTotalsAndSummary(outFile, record_counter, psgr, psgrCount, distance, fare, toll,
+ totalFare, cpm, paid);
+ outFile.close();
+ }
+ else
+ {
+ cout << "Trouble Opening File";
+ cout << "\n\n\t\t ** About to EXIT NOW! ** " << endl;
+ }
+
+ }
+ else
+ {
+ cout << "Trouble Opening File";
+ cout << "\n\n\t\t ** About to EXIT NOW! ** " << endl;
+ }
+ return 0;
+
+}
+int ReadData(ifstream& inFile, ofstream& outFile, int pick[], int drop[], int psgrCount[],
+ float distance[], float fare[], float toll[], float cpm[], int counter,
+ float totalFare[])
+{
+
+
+
+ cout << setiosflags(ios::left) << setw(10) << "Trip" <<
+ setw(15) << "PickUp" << setw(10) << "DropOff" <<
+ setw(10) << "# people" << setw(10) << "Distance" <<
+ setw(10) << "Fare" << setw(10) << "Toll" <<
+ setw(10) << "Total" << setw(10) << "Cost per mile" << endl;
+
+ inFile >> pick[counter] >> drop[counter] >> psgrCount[counter] >> distance[counter] >>
+ fare[counter] >> toll[counter];
+
+ while (!inFile.eof())
+ {
+ totalFare[counter] = fare[counter] + toll[counter];
+ cout << setiosflags(ios::left) << setw(10) << counter << setw(15) <<
+ pick[counter] << setw(10) << drop[counter] << setw(10) << psgrCount[counter] <<
+ setw(10) << distance[counter] << setw(10) << fare[counter] <<
+ setw(10) << toll[counter] << setw(15) << totalFare[counter] << setw(10) << endl;
+
+ if (distance[counter] == 0)
+ {
+ cpm[counter] = 0;
+ }
+ else
+ {
+
+ cpm[counter] = (toll[counter] + fare[counter]) / distance[counter];
+ }
+ cout << setprecision(2) << cpm[counter] << endl;
+ counter++;
+ inFile >> pick[counter] >> drop[counter] >> psgrCount[counter] >> distance[counter] >>
+ fare[counter] >> toll[counter];
+
+ }
+ return counter;
+}
+
+void WriteOutputFile(ofstream& outFile, int totalRecords, int psgr, int pick[], int drop[],
+ int psgrCount[], float distance[], float fare[], float toll[], float cpm[])
+{
+ outFile << "Here is the Output File" << endl;
+ for (int r = 0; r < totalRecords; r++)
+ {
+ outFile << setiosflags(ios::left) << setw(15) << pick[r] <<
+ setw(15) << drop[r] << setw(15) << psgrCount[r] << setw(15) <<
+ distance[r] << setw(15) << fare[r] << setw(15) << toll[r] << setw(15) <<
+ cpm[r] << endl;
+ }
+
+}
+
+void PrintTotalsAndSummary(ofstream& outFile, int totalrecords, int psgr, int passCount[],
+ float distance[], float fare[], float toll[], float totalFare[], float cpm[],
+ float paid)
+{
+ for (int i = 0; i < totalrecords; i++)
+ {
+ psgr += passCount[i];
+ float num = fare[i] + toll[i];
+ paid += num;
+ totalFare[i] = num;
+
+ if (distance == 0)
+ {
+ cpm[i] = 0;
+ }
+
+ else
+ {
+ cpm[i] = totalFare[i] / distance[i];
+ cout << cpm[i] << endl;
+ }
+ }
+
+
+
+
+
+ cout << "\n\n\tAverage Cost Per Person: " << paid / psgr << "\n"
+ << "\n\n\t Number of People Transported: " << psgr << "\n"
+ << "\n\n\tTotal Cost: " << paid << "\n"
+ << "\t\t The End \n" << endl;
+
+
+
+
+ cout << "\n\n\tAverage Cost Per Person: " << paid / psgr << "\n"
+ << "\n\n\t Number of People Transported: " << psgr << "\n"
+ << "\n\n\tTotal Cost: " << paid << "\n"
+ << "\t\t The End \n" << endl;
+} \ No newline at end of file
diff --git a/BlankConsoleLab/big.txt b/BlankConsoleLab/big.txt
new file mode 100644
index 0000000..d9fa1b1
--- /dev/null
+++ b/BlankConsoleLab/big.txt
@@ -0,0 +1,48 @@
+129 7 3 1.3 7.5 0
+36 69 1 11.41 32 5.76
+7 41 1 4.6 15 5.76
+150 61 2 6.75 23 0
+112 17 1 3.84 15 0
+80 112 6 1.64 9.5 0
+256 183 1 16.08 44.5 0
+138 166 2 7.4 24.5 6.12
+142 50 5 1.7 8 0
+107 163 0 3.6 17 0
+132 3 2 19.1 52 6.12
+48 41 1 4.07 18 4.36
+132 226 1 14.3 39 0
+229 151 1 3.96 14.5 4.58
+238 166 1 0.76 4.5 0
+151 238 2 0.64 5 2.2
+138 82 4 3 12 0
+264 231 3 10.74 32.5 0
+170 114 5 2.01 9 0
+186 87 2 3.45 12 0
+209 256 1 3.79 17 0
+132 107 1 17.2 52 6.12
+232 112 1 3.1 11 0
+164 141 3 2.85 10.5 0
+129 7 3 1.3 7.5 0
+36 69 1 11.41 32 5.76
+7 41 1 4.6 15 5.76
+150 61 2 6.75 23 0
+112 17 1 3.84 15 0
+80 112 6 1.64 9.5 0
+256 183 1 16.08 44.5 0
+138 166 2 7.4 24.5 6.12
+142 50 5 1.7 8 0
+107 163 0 3.6 17 0
+132 3 2 19.1 52 6.12
+48 41 1 4.07 18 4.36
+132 226 1 14.3 39 0
+229 151 1 3.96 14.5 4.58
+238 166 1 0.76 4.5 0
+151 238 2 0.64 5 2.2
+138 82 4 3 12 0
+264 231 3 10.74 32.5 0
+170 114 5 2.01 9 0
+186 87 2 3.45 12 0
+209 256 1 3.79 17 0
+132 107 1 17.2 52 6.12
+232 112 1 3.1 11 0
+164 141 3 2.85 10.5 0 \ No newline at end of file
diff --git a/BlankConsoleLab/output.txt b/BlankConsoleLab/output.txt
new file mode 100644
index 0000000..46d6ba5
--- /dev/null
+++ b/BlankConsoleLab/output.txt
@@ -0,0 +1,6 @@
+Here is the Output File
+129 7 3 1.3 7.5 0 5.76923
+36 69 1 11.41 32 5.76 3.30938
+7 41 1 4.6 15 5.76 4.51304
+150 61 2 6.75 23 0 3.40741
+112 17 1 3.84 15 0 3.90625
diff --git a/BlankConsoleLab/small.txt b/BlankConsoleLab/small.txt
new file mode 100644
index 0000000..840aa56
--- /dev/null
+++ b/BlankConsoleLab/small.txt
@@ -0,0 +1,6 @@
+129 7 3 1.3 7.5 0
+36 69 1 11.41 32 5.76
+7 41 1 4.6 15 5.76
+150 61 2 6.75 23 0
+112 17 1 3.84 15 0
+80 112 6 1.64 9.5 0 \ No newline at end of file