1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <fstream>
using namespace std;
int weightFunction(int, int);
int main()
{
//open input file
ifstream inFile;
inFile.open("Trucks.txt");
if(!inFile)
{
cout<<"Can't open file";
return 1;
}
//write to file
ofstream outFile;
outFile.open("TruckFines.txt");
//variables
string dayOfWeek[7];
int truckWeight;
int currentWeight, currentDays, currentTruck, currentTruckWeight, result;
int i, n, d/* day # */,t/* truck #*/, g;
//for loop for inFile
for (i = 0; i < 7; i++)
{
inFile >> dayOfWeek[i];
}
while (inFile)
{
for (n = 0; n < 7; n++)
{
inFile >> currentDays;
}
}
//for loop for day
for (d = 0; d < 7; d++)
{
outFile << "Data for " << dayOfWeek[d]<< ":" << endl;
outFile << "Trucks with Fines: " << endl;
//for loop for trucks
for (t = 0; t < truckWeight; t++)
{
currentTruckWeight = truckWeight;
//function call
result = weightFunction (d, t);
outFile << "Truck# " << currentTruck + 1 << " $" << result << endl;
outFile << "Trucks without fines: " << endl;
//goes through all trucks
for(g = 0; g < truckWeight; g++)
{
currentWeight = truckWeight;
//if current truck is less than or equal to the weight limit
if(currentWeight <= 80000)
{
outFile << "Truck# " << currentTruck + 1 << endl;;
}
}
outFile << endl;
}
}
getchar();
return 0;
}
//function for overweight limit
int weightFunction(int d, int t)
{
//variables
int currentDay, currentTruck, currentWeight, result;
//if current truck over limit (limit is 80,000)
if (d > 80000)
{
result <<((currentWeight - 80000) % 100) * 50;
}
return result;
}
|