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
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
//global constant declarations
const char LOW_PLAN = 'L';
const char MID_PLAN = 'M';
const char HI_PLAN = 'H';
const char UNL_PLAN = 'U';
const double TAX = .081;
const double LOW_BASE = 4.99;
const double MID_BASE = 49.99;
const double HI_BASE = 74.99;
const double UNL_BASE = 99.99;
const double LOW_TEXT = .1;
const double MID_TEXT = .08;
const double HI_TEXT = .07;
const double MID_DATA = 2.88;
const double HI_DATA = 1.78;
const double SERVICE = 1.44;
const int SM_LIMIT = 500;
const int BIG_LIMIT = 1000;
const int MAX_LIMIT = 2000;
const string INPUT = "BILLDATA.TXT";
const string OUTPUT = "ACCOUNTS.TXT";
const string USAGE = "USAGE.TXT";
//function prototypes, functions described in detail at declaration
void getData(ifstream&, ofstream&, ofstream&);
double getLineCharge(char, int, int, double);
int main() {
ifstream inData;
ofstream outData;
ofstream usage;
inData.open(INPUT.c_str());
outData.open(OUTPUT.c_str());
usage.open(USAGE.c_str());
if(!inData) {
cout << "Error: Could not open " << INPUT << " Program will exit now" << endl;
cout << "(press any key to exit)";
cin.get();
return 1;
}
else {
cout << "Getdata will run";
getData(inData, outData, usage);
inData.close();
}
return 0;
}
void getData(ifstream& input, ofstream& output, ofstream& usage) {
double grandTotal;
do {
cout << "\nFirst do loop is running";
int numberPhones = 0;
int displayLines;
int accountNumber;
char planType;
double planTotal = 0;
char checkLine = 'A';
input >> accountNumber;
input >> planType;
checkLine = input.peek();
cout << checkLine;
while ((checkLine != '\n') && (input)) {
cout << "\nWhile loop is running";
string phoneNumber;
int minutes;
int texts;
double data;
double total;
input >> phoneNumber;
cout << phoneNumber;
input >> minutes;
input >> texts;
input >> data;
total = getLineCharge(planType, minutes, texts, data);
usage << phoneNumber << " ";
usage << planType << " ";
usage << total << "\n";
planTotal += total;
numberPhones++;
}
} while(input);
return;
}
double getLineCharge(char type, int minutes, int texts, double data) {
double total = 0;
switch (type) {
case 'L':
total = (minutes * LOW_TEXT) + (texts * LOW_TEXT) + LOW_BASE;
break;
case 'M':
if (minutes > SM_LIMIT)
total += ((minutes - SM_LIMIT) * MID_TEXT);
if (texts > SM_LIMIT)
total += ((texts - SM_LIMIT) * MID_TEXT);
if (data > SM_LIMIT)
total += ((data - SM_LIMIT) / SM_LIMIT) * MID_DATA;
total += MID_BASE;
break;
case 'H':
if (minutes > BIG_LIMIT)
total += ((minutes - BIG_LIMIT) * HI_TEXT);
if (texts > BIG_LIMIT)
total += ((texts - BIG_LIMIT) * HI_TEXT);
if (data > MAX_LIMIT)
total += ((data - MAX_LIMIT) / BIG_LIMIT) * HI_DATA;
total += HI_BASE;
break;
case 'U':
total = UNL_BASE;
break;
}
return total;
}
|