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 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
/*CSC 134 80
Project 3 Postal Bar Code and Mailings List
Josh Krynock
This program displays a menu for single or multiple mailings. It will
ask the user what type of item is being mailed and for the item's weight.
The program will then calculate the postage and generate a mailing label
complete with barcode. If the user selects multiple mailings, the program
will read a file, Mailings.txt, and generate a list of postage costs and
mailing labels for each. */
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main()
{
//Variables for menu.
int choice;
//Variables for string input
string name, street, city, state;
// Variables for the zip code math.
int zip, check,
ones,
tens, tensA,
hund, hundA,
thou, thouA,
tenK, tenKA,
sum;
//Variables for Postage rates
int package, weight;
//These are the shipping rate variables
const double LETTER = 0.49,
LETTERplus = 0.22,
ENVELOPE = 0.98,
ENVELOPEplus = 0.22,
PARCEL = 2.54,
PARCELplus = 0.20,
WEIGHT_MIN = 0.0, WEIGHT_MAX = 1.0;
double postage;
//These are the variables to store the bar code.
string bar1, bar10, bar100, bar1k, bar10k, barcheck;
//Format numeric output.
cout << fixed << showpoint << setprecision(2);
do
{
cout << "Welcome to the Mailing Label System\n\n";
cout << "1 - Single Mailings\n";
cout << "2 - Multiple Mailings\n";
cout << "3 - Quit\n";
cout << "Enter your choice: ";
cin >> choice;
}
while (choice < 1 || choice > 3 );
/*Choice #1 procudure.
Validation of zip code, parcel selection, and weight
occur within the do-while loops.
*/
if (choice == 1)
{
cout << "Enter name: ";
getline(cin, name);
cout << "Enter street address: ";
getline(cin, street);
cout << "Enter City: ";
getline(cin, city);
cout << "Enter state: ";
getline(cin, state);
do
{
cout << "Enter zip code: ";
cin >> zip;
}
while (zip < 501 || zip > 99950);
do
{
cout << "Enter 1 for letter, 2 for envelope, 3 for parcel: ";
cin >> package;
}
while (package < 1 || package > 3);
do
{
cout << "Enter the weight in ounces: ";
cin >> weight;
}
while (weight <= 0);
//This part of the program calculates shipping charges.
if (package == 1)
{
if (weight <= WEIGHT_MAX && weight > WEIGHT_MIN)
postage = LETTER;
else
{ static_cast<int>(weight);
postage = (LETTER + (weight * LETTERplus));
}
}
else if (package == 2)
{
if (weight <= WEIGHT_MAX && weight > WEIGHT_MIN)
postage = ENVELOPE;
else
{ static_cast<int>(weight);
postage = (ENVELOPE + (weight * ENVELOPEplus));
}
}
else if (package == 3)
{
if (weight <= WEIGHT_MAX && weight > WEIGHT_MIN)
postage = PARCEL;
else
{ static_cast<int>(weight);
postage = (PARCEL + (weight * PARCELplus));
}
}
//This part of the program breaks the zipcode into single digits.
//First the ones,
ones = zip % 10;
//then tenths
tens = zip % 100;
tensA = (tens - ones) / 10;
//Hundreths
hund = zip % 1000;
hundA = (hund - tens) / 100;
//Thousandths
thou = zip % 10000;
thouA = (thou - hund) / 1000;
//Ten K
tenK = zip % 100000;
tenKA = (tenK - thou) / 10000;
//This part of the program calculates the check number.
check = (ones - tensA + hundA + thouA + tenKA);
check %= 10;
check = (10-check);
//This part of the program modifies the zip code to display
//it in true barcode form.
//This part of the program displays the postage label.
cout << "\n\n\n\n";
cout << left << "**********************************$";
cout << postage << "\n\n";
cout << name << "\n";
cout << street << "\n";
cout << city << ", " << state << " " << zip << "\n\n";
cout << "|" << bar10k << bar1k << bar100 << bar10 << bar1 << barcheck << "|";
//Line 127 is the last bracket for choice #1 if block.
}
else if (choice == 2)
{
ifstream mailingList;
mailingList.open("C:\\Users\\Josh\\Documents\\CPCC\\Spring 2016\\CSC 134 18\\Module 6\\Mailings.txt");
//Testing file opening
if (mailingList.fail())
{
cout << "Error opening file. ";
return 0;
}
else
{ //This section reads the info from the Mailings.txt file.
//Information should be processed and looped.
while (mailingList >> name)
{
mailingList >> street;
mailingList >> city;
mailingList >> state;
mailingList >> zip;
mailingList >> package;
mailingList >> weight;
//This section calculates postage charges. Line 328 - 356
if (package == 1)
{
if (weight <= WEIGHT_MAX && weight > WEIGHT_MIN)
postage = LETTER;
else
{ static_cast<int>(weight);
postage = (LETTER + (weight * LETTERplus));
}
}
else if (package == 2)
{
if (weight <= WEIGHT_MAX && weight > WEIGHT_MIN)
postage = ENVELOPE;
else
{ static_cast<int>(weight);
postage = (ENVELOPE + (weight * ENVELOPEplus));
}
}
else if (package == 3)
{
if (weight <= WEIGHT_MAX && weight > WEIGHT_MIN)
postage = PARCEL;
else
{ static_cast<int>(weight);
postage = (PARCEL + (weight * PARCELplus));
}
}
//This section calculates the check code and converts
//the zip code into bar code format. Lines 362 - 383
//First the ones,
ones = zip % 10;
//then tenths
tens = zip % 100;
tensA = (tens - ones) / 10;
//Hundreths
hund = zip % 1000;
hundA = (hund - tens) / 100;
//Thousandths
thou = zip % 10000;
thouA = (thou - hund) / 1000;
//Ten K
tenK = zip % 100000;
tenKA = (tenK - thou) / 10000;
//This part of the program calculates the check number.
check = (ones - tensA + hundA + thouA + tenKA);
check %= 10;
check = (10-check);
cout << "\n";
cout << left << "**********************************$";
cout << postage << "\n";
cout << name << "\n";
cout << street << "\n";
cout << city << ", " << state << " " << zip << "\n";
cout << "|" << bar10k << bar1k << bar100 << bar10 << bar1 << barcheck << "|";
}//Last bracket for reading mailing list
}
mailingList.close();
}
else if (choice == 3)
cout << "Thank you. Closing program.";
return 0;
}
|