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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <conio.h>
using namespace std;
//Declaring Methods
void Heading();
void printCityTotal(string,int&, int&, int);
void printCountyTotal (string,int&, int &, int);
void printDistrictTotal (string,int&, int &, int);;
int main()
{
//Initializing all data types
string strFill1;
string strDistrictNumber;
string strCountyNumber;
string strCityNumber;
string strAccountNumber;
string strAccountName;
int BondAmount=0;
char ch;
int s;
int cityTotal=0;
int countyTotal=0;
int districtTotal=0;
int finalTotal=0;
string strDistrictNumberOld;
string strCityNumberOld;
string strCountyNumberOld;
//Opens the file
ifstream inFile;
inFile.open("FBRKUNSORT2.TXT", ios::in);
Heading();
//Begin the loop
if (!inFile.eof())
{
//getting the first line
getline(inFile, strDistrictNumber, '#');
getline(inFile, strCountyNumber, '#');
getline(inFile, strCityNumber, '#');
getline(inFile, strFill1, '#');
getline(inFile, strFill1, '#');
getline(inFile, strFill1, '#');
getline(inFile, strFill1, '#');
getline(inFile, strAccountNumber, '#');
getline(inFile, strFill1, '\n');
//setting everything to old
strDistrictNumberOld=strDistrictNumber;
strCountyNumberOld=strCountyNumber;
strCityNumberOld=strCityNumber;
while (!inFile.eof())
{
//Adding the BondAmount to city total
cityTotal+=BondAmount;
//Made a new variable called s(For Switch) to take in AccountNumber so there is a variable getting passed into the switch
s=(atoi(strAccountNumber.c_str()));
//begin the switch statement
switch(s)
{
case 1: {
strAccountName = "HIGHWAY CONTRSTUCTION";
BondAmount = 300000;
break;}
case 2:{
strAccountName = "PARKS & RECREATION";
BondAmount = 270000;
break;}
case 3:{
strAccountName = "MENTAL HEALTH";
BondAmount = 150000;
break;}
case 4:{
strAccountName = "SECONDARY SCHOOLS";
BondAmount = 450000;
break;}
case 5:{
strAccountName = "COLLEGE & UNIVERSITY";
BondAmount = 325000;
break;}
case 6:{
strAccountName = "POLICE-FIRE";
BondAmount = 450000;
break;}
}
//Begin the Control Breaks
if (strDistrictNumberOld != strDistrictNumber)
{
//Calling the Print Functions
printCityTotal(strCityNumberOld,countyTotal, cityTotal, BondAmount);
printCountyTotal (strCountyNumberOld, districtTotal,countyTotal,BondAmount);
printDistrictTotal (strDistrictNumberOld,finalTotal,districtTotal,BondAmount);
//resetting old to new
strDistrictNumberOld=strDistrictNumber;
strCountyNumberOld=strCountyNumber;
strCityNumberOld=strCityNumber;
}
else if (strCountyNumberOld != strCountyNumber)
{ // "
printCityTotal(strCityNumberOld,countyTotal, cityTotal, BondAmount);
printCountyTotal (strCountyNumberOld, districtTotal,countyTotal,BondAmount);
//"
strCountyNumberOld=strCountyNumber;
strCityNumberOld=strCityNumber;
}
else if (strCityNumberOld != strCityNumber)
{ //"
printCityTotal(strCityNumberOld,countyTotal, cityTotal, BondAmount);
//"
strCityNumberOld=strCityNumber;
};
//prints
cout.imbue(locale( ""));
cout <<left
<< setw(10) << strDistrictNumber
<< setw(10) << strCountyNumber
<< setw(10) << strCityNumber
<< setw(10) << strAccountNumber
<< setw(25) << strAccountName << "$"
<< setw(13) << BondAmount
<< endl;
//Gets Line
getline(inFile, strDistrictNumber, '#');
getline(inFile, strCountyNumber, '#');
getline(inFile, strCityNumber, '#');
getline(inFile, strFill1, '#');
getline(inFile, strFill1, '#');
getline(inFile, strFill1, '#');
getline(inFile, strFill1, '#');
getline(inFile, strAccountNumber, '#');
getline(inFile, strFill1, '\n');
}
cout <<right << "\n"<< setw(25) << "CITY" << setw(10) <<"#"<< strCityNumberOld << setw(9) << "TOTAL"<< setw(15) <<"$"<< cityTotal <<"*"<<"\n\n";
cout <<right << "\n"<< setw(25) << "COUNTY" << setw(10) <<"#"<< strCountyNumberOld << setw(10) << "TOTAL"<< setw(15) <<"$"<<countyTotal <<"**"<<"\n\n";
cout <<right << "\n"<< setw(25) << "DISTRICT" << setw(10) <<"#"<< strDistrictNumberOld << setw(10) << "TOTAL"<< setw(15) <<"$"<< districtTotal<<"***" <<"\n\n";
cout <<right<< "\n"<< setw(25) << "FINAL" << setw(22) << "TOTAL"<< setw(15) <<"$"<< finalTotal <<"\n\n";
//End of while loop
//Closes open file
inFile.close();
}
else
cout << "Could not read the file";
cout << endl;
cout << " END OF REPORT" << endl;
system("PAUSE");
ch = _getch();
return 0;
}
//Print Functions
void printCityTotal (string strCityNumberOld,int &countyTotal, int &cityTotal, int BondAmount)
{
cout <<right << "\n"<< setw(25) << "CITY" << setw(10) <<"#"<< strCityNumberOld << setw(9) << "TOTAL"<< setw(15) <<"$"<< cityTotal<<"*"<<"\n\n";
//strCityNumberOld=strCityNumber;
countyTotal+=cityTotal;
cityTotal=0;
};
void printCountyTotal (string strCountyNumberOld, int &districtTotal, int &countyTotal, int BondAmount)
{
//printCityTotal (string strCityNumberOld, int &cityTotal, int BondAmount);
cout <<right << "\n"<< setw(25) << "COUNTY" << setw(10) <<"#"<< strCountyNumberOld << setw(10) << "TOTAL"<< setw(15) <<"$"<<countyTotal<<"**" <<"\n\n";
//strCountyNumberOld=strCountyNumber;
districtTotal+=countyTotal;
countyTotal=0;
};
void printDistrictTotal (string strDistrictNumberOld, int &finalTotal, int &districtTotal, int BondAmount)
{
cout <<right << "\n"<< setw(25) << "DISTRICT" << setw(10) <<"#"<< strDistrictNumberOld << setw(10) << "TOTAL"<< setw(15) <<"$"<< districtTotal<<"***" <<"\n\n";
//strDistrictNumberOld=strDistrictNumber;
finalTotal+=districtTotal;
districtTotal=0;
};
//Header
void Heading()
{
cout << setw(33) << "MICHAEL MELENDEZ CIS PROJECT 1"<<"\n\n";
cout << setw(49) << "PROPOSED BOND ISSUES" << endl;
cout << " " << endl;
cout <<left
<<setw(10) << "DISTRICT"
<< setw(10)<<"COUNTY"
<< setw(10)<<"CITY"
<< setw(10)<<"ACCOUNT"
<< setw(25)<<"ACCOUNT"
<< setw(13)<<"BOND"<<endl;
cout <<left
<<setw(10) << "NUMBER"
<< setw(10)<<"NUMBER"
<< setw(10)<<"NUMBER"
<< setw(10)<<"NUMBER"
<< setw(25)<<"NAME"
<< setw(13)<<"AMOUNT";
cout << " " << endl;
}
|