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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
//declaring the variables
int i = 0;
int Option = 0;
string Date[8];
string RegionalCop[8];
char Typeog[8] = {};
double Weightin[8];
double Weightout[8];
double ArimaToT = 0.0;
double Arima = 0.0;
//asking the user to enter and option
cout<<"Please choose an option:\n1.Option1\n2.Option2"<<endl;
cin>>Option;
//association the object logs with the file named Data.txt
ifstream Logs;
Logs.open("Data.txt");
if(!Logs.is_open()){cerr<<"Sorry file could not be opened";}//error message if file is not opened
else{
while(!Logs.eof()){//for loop to read all the contents of the file
//storing all the information in the appropriate array
getline(Logs,Date[i],',');
getline(Logs,RegionalCop[i],',');
Logs>>Typeog[i];
Logs.ignore(1);
Logs>>Weightin[i];
Logs.ignore(1);
Logs>>Weightout[i];
// Logs.ignore(1);
++i;
}
Logs.close();
//Switch statements for options
switch (Option){
case 1:
//if user chooses option 1 all the contentes of the file will be place in a table under its category and then displayed on the screen
cout<<setw(9)<<"Date"<<setw(26)<<" Regional corporation"<<setw(20)<<"Type of Garbage"<<setw(10)<<"weigtIn"<<setw(10)<<"weigtOut"<<endl;
for (i=0; i<=7; i++){
cout<<setw(9)<<Date[i]<<setw(25)<<RegionalCop[i]<<setw(20)<<Typeog[i]<<setw(10)<<setprecision(2)<<fixed<<Weightin[i]<<setw(10)<<Weightout[i]<<fixed;
}
}
//if user chose option 2 the program is suppose to compare the two arrays if array regionalCop and Typeofgarbage are met the program is suppose to
//get the total amount of recycleble garbage for the given corporation this is done by subtracting weightin - weightour of the given corporation
//this calculation has to be repeated four times each time changing the given corporation and at the end the program is suppose to display the total amount of recyclyclabel
//garbage for each corporation
if (Option==2){
while((RegionalCop[i] == "Arima") && (Typeog[i] == 'r')){
Arima== Weightin[i] - Weightout[i];
ArimaToT ==Arima +
++i;
}
cout<<"Arima"<<ArimaToT<<endl;
}
}
return 0;
}//endif
|
Contents of Data.txt
November24,Tunapuna-Piarco,r,3000.00,2500.00
November25,Armia,g,4000.00,3500.00
November04,San Juan-Laventille,r,4500.00,3500.00
November11,Chaguanus,r,4500.00,3000.00
November22,Tunapuna-Piarco,g,2000.00,1000.00
November25,Armia,r,5000.00,6000.00
November01,San Juan-Laventille,r,3000.00,3400.00
November11,Chaguanus,g,4700.00,3900.00
|
|