Dear student
,
Please comment for any doubts or modifications...
Please upvote if the answer is helpful
.....thanks...
Program screenshot:
Sample output screenshot:
Sample output file screenshot:
Code to copy:
// Header files
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
struct ZipCode {
int romanZipCode;
string postnetCode;
};
// Function declarations
ZipCode fillZipCode(const string zip);
string romanToPOSTNET(const int r);
int postnetToRoman(const string p);
void printRomanZip(const ZipCode zip);
void printPOSTNET(const ZipCode zip);
void writeToFile(const ZipCode zip);
void processZip(int prompt);
int getInt(string str);
void printGraphicalPOSTNET(string postnet);
string get5BitBinary(int x);
// The following function is used to accepts both roman
// and barcode formats, fills both struct members.
ZipCode fillZipCode(ZipCode zip)
{
if (zip.postnetCode == "")
{
zip.postnetCode = romanToPOSTNET(zip.romanZipCode);
}
else
{
zip.romanZipCode = postnetToRoman(zip.postnetCode);
}
return zip;
}
// The following function is used to convert
// the roman zip code to bar code.
string romanToPOSTNET(const int r)
{
string postnet;
postnet = postnet + get5BitBinary(r);
return postnet;
}
// The following function is used to convert
// the bar code to roman zip code.
int postnetToRoman(const string p)
{
int i = 1;
int r = 0;
while (p.length() - i >= 5)
{
r = r * 10 + getInt(p.substr(i, 5));
i += 5;
}
return r;
}
// The following function is used to display
// the roman zip
void printRomanZip(const ZipCode zip)
{
cout << "\nYour Zip code is " << zip.romanZipCode;
}
// The following function is used to display
// the graphical representation.
void printPOSTNET(const ZipCode zip)
{
cout << ", and the bar code looks like this:\n" << endl;;
printGraphicalPOSTNET(zip.postnetCode);
}
// The following function is used to display
// the graphical post net representation.
void printGraphicalPOSTNET(string postnet)
{
int len = postnet.length();
int index = 0;
for (index = 0; index < len; index++)
{
if (postnet[index] == '1')
{
cout << "|";
}
else {
cout << " ";
}
}
cout << "\n";
index++;
for (; index < (2 * len) + 1; index++)
{
cout << "|";
}
cout << endl;
}
// The following function accepts the zipcode and
// this function returns its POSTNET code
string get5BitBinary(int x)
{
string binary[] = { "11000","00011","00101", "00110",
"01001","01010","01100", "10001",
"10010","10100" };
string str = "1";
while (x > 0)
{
int bit = x % 10;
str = binary[bit] + str;
x /= 10;
}
// when the zipcode has trailing 0's
// Ex : 02363
if (str.length() < 25)
{
str = binary[0] + str;
}
str = "1" + str;
return str;
}
// The following function accepts the string datatype input
// which contains 5 bits.
// This function returns its integer value
int getInt(string str)
{
string binary[] = { "11000","00011","00101", "00110",
"01001","01010","01100", "10001",
"10010","10100" };
for (int index = 0; index < 10; index++)
{
if (str.compare(binary[index]) == 0)
{
return index;
}
}
}
// The following method is used to convert the
// zip to postnet and display it on the screen
// and writes it to the file with zip as its name
// if the user selects option 1 and this function
// is used to convert the postnet to zip and then
// displays it on the screen and writes it to the
// file, if the user selectds option 2.
void processZip(int prompt)
{
struct ZipCode code;
if (prompt == 1)
{
cout << "\nEnter a zip code in roman format (#####): ";
cin >> code.romanZipCode;
code = fillZipCode(code);
printRomanZip(code);
printPOSTNET(code);
}
else
{
cout << "\nEnter a zip code in bar code format (1's and 0's): ";
cin >> code.postnetCode;
code = fillZipCode(code);
printRomanZip(code);
}
writeToFile(code);
}
// The following function is used to write the zip code in
// the file.
void writeToFile(const ZipCode zip)
{
string filename = "";// to_string(zip.romanZipCode)+".txt";
std::stringstream ss;
ss << zip.romanZipCode;
filename.append(ss.str());
filename += ".txt";
ofstream output(filename.c_str(), ios::out);
output << "Your Zip code is " << zip.romanZipCode;
output << ", and the bar code looks like this:\n";
int len = zip.postnetCode.length();
int i = 0;
for (i = 0; i < len; i++)
{
if (zip.postnetCode[i] == '1')
{
output << "|";
}
else
{
output << " ";
}
}
output << "\n";
i++;
for (; i < (2 * len) + 2; i++)
{
output << "|";
}
output << endl;
output.close();
cout << "\nYour zip code was saved in the file "<< filename
<<endl;
}
// Create a main method to execute the program.
int main()
{
int mainMenu;
cout << " This program is able to convert zip codes to a POSTNET format "
<< "and vice versa\n"
<< "\t 1. Convert zip code to POSTNET\n"
<< "\t 2. Convert POSTNET to zip code\n"
<< "\t 3. Quit\n";
do
{
cout << "Please make your selection: ";
cin >> mainMenu;
switch (mainMenu)
{
case 1:
case 2:
processZip(mainMenu);
break;
default:
if (mainMenu != 3)
cout << "Invalid choice...\n";
else
cout << "\n";
}
} while (mainMenu != 3);
return 0;
}
In the program, the zipcode will be represented by an integer and the corresponding barcode will...
1 Until 2009, the US Postal Service printed a bar code on every envelope that represented the zip code using a format called POSTNET. We will be doing the same with only 5-digit zip codes. POSTNET consists of long and short lines, as seen below: The POSTNET representation of 67260, WSU's zip code In the program, the zipcode will be represented by an integer and the corresponding barcode will be represented by strings of digits. The digit 1 will represent...
Please help me figure out why my code is not working properly.I had thought my logic was sound but later found it will run one time through fine however if the user opts to enter another value it will always be returned as an error. #include <iomanip> #include <iostream> #include <cstdlib> using namespace std; int const TRUE = 1; int const FALSE = 0; // declares functions void GetZipcode(); void RunAgain(); int GetSum(char d1, char d2, char d3, char d4,...
Instructions CheckZips.cs + >_ Terminal Write a program named CheckZips that is used by a package delivery service to check delivery areas. 1 using static System.Console; 2 class CheckZips 3 { 4 static void Main() 5 { 6 string[] zips = {"12789", "54012", "54481", "54982", "60007", "60103", "60187", "60188", "71244", "90210"}; CheckZips.cs(10,8): error CS002 9: Cannot implicitly convert ty pe 'string' to 'string[]' CheckZips.cs(18,5): error CS001 9: Operator '==' cannot be appl ied to operands of type 'string []' and...
Hey I really need some help asap!!!! I have to take the node class that is in my ziplist file class and give it it's own file. My project has to have 4 file classes but have 3. The Node class is currently in the ziplist file. I need it to be in it's own file, but I am stuck on how to do this. I also need a uml diagram lab report explaining how I tested my code input...
(c++) Write a program that converts a positive integer into the Roman number system.(c++) Roman numbers. Write a program that converts a positive integer into the Roman number system. The Roman number system has digits I 1 V 5 X 10 L 50 C 100 D 500 M 1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately....
Write C++ program T 1030 UUIII DUCOUL The bar code on an envelope used by the US Postal Service represents a five (or more) digit zip code using a format called POSTNET (this format is being deprecated in favor of a new system, OneCode, in 2009). The bar code consists of long and short bars as shown below: Illlllllllll For this program we will represent the bar code as a string of digits. The digit 1 represents a long bar...
Please Help. C++. Need 3 attributes and 3 methods added to the code below. Need the prototype added to the .h file......and the implementation in the .cpp file....thanks! edited: I just need the above and then I was told to use the methods in the main program; for the vehicle. Any 3 attributes and any three methofds. source.cpp file // Header Comment #include #include #include #include "Automobile.h" using namespace std; struct Address{ string street; string city; string state; string zip;...
In c programming . Part A: Writing into a Sequential File Write a C program called "Lab5A.c" to prompt the user and store 5 student records into a file called "stdInfo.txt". This "stdInfo.txt" file will also be used in the second part of this laboratory exercise The format of the file would look like this sample (excluding the first line) ID FIRSTNAME LASTNAME GPA YEAR 10 jack drell 64.5 2018 20 mina alam 92.3 2016 40 abed alie 54.0 2017...
Write the functions needed to complete the following program as described in the comments. Use the input file course.txt and change the mark of student number 54812 to 80. /* File: course.cpp A student's mark in a certain course is stored as a structure (struct student as defined below) consisting of first and last name, student id and mark in the course. The functions read() and write() are defined for the structure student. Information about a course is stored as a...
Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...