1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Veronika [31]
4 years ago
11

Write a zip code class that encodes and decodes 5-digit bar codes used by the U.S. Postal Service on envelopes. The class should

have two constructors. The first constructor should input the zip code as an integer, and the second constructor should input the zip code as a bar code string consisting of 0s and 1s, as described above. Although you have two ways to input the zip code, internally, the class should store the zip code using only one format (you may choose to store it as a bar code string or as a zip code number). The class should also have at least two public member functions, one to return the zip code as an integer, and the other to return the zip code in bar code format as a string. All helper functions should be declared private. Embed your class definition in a suitable test program. Your program should print an error message if an invalid bar code is passed to the constructor.
Computers and Technology
1 answer:
8_murik_8 [283]4 years ago
4 0

Answer:

#include<iostream>

#include<string>

using namespace std;

class zip_code

{

private:

int zipcode;

string get_string(int num)

{

string str="";

if(num == 0) return "11000";

if(num>7)

{

str.append("1");

num = num-7;

}

else

str.append("0");

if(num>4)

{

str.append("1");

num = num-4;

}

else

str.append("0");

if(num>2)

{

str.append("1");

num = num-2;

}

else

str.append("0");

if(num>1)

{

str.append("1");

num = num-1;

}

else

str.append("0");

str.append("0");

return str;

}

public:

zip_code(int barcode)

{

if(barcode<10000 || barcode>99999)

cout <<"Invalid Bar code passed to constructor." << endl;

else

zipcode = barcode;

}

zip_code(string barcode)

{

if(barcode.length()>27)

cout <<"Invalid Bar code passed to constructor." << endl;

else

{

int zipper = 0;

string str_local = barcode.substr(1,barcode.length()-2);

for(int i=0; i<str_local.length()-5; i+=5)

{

int local = 0;

local = 7*(str_local[i]-'0') +

       4*(str_local[i+1]-'0') +

       2*(str_local[i+2]-'0') +

       1*(str_local[i+3]-'0');

if(local == 11) local = 0;

       zipper = zipper*10 + local;

}

zipcode = zipper;

}

}

string getZipcode()

{

string str = "1";

int first = zipcode/10000;

int second = (zipcode - first*10000)/1000;

int third = (zipcode - first*10000-second*1000)/100;

int fourth = (zipcode - first*10000-second*1000-third*100)/10;

int fifith = (zipcode - first*10000-second*1000-third*100-fourth*10);

str.append(get_string(first));

str.append(get_string(second));

str.append(get_string(third));

str.append(get_string(fourth));

str.append(get_string(fifith));

str.append("1");

return str;

}

int get_zipCode()

{

return zipcode;

}

};

int main()

{

zip_code z1(123456);

zip_code z2(99504);

cout << z2.getZipcode() << endl;

system("pause");

return 0;

}

You might be interested in
Entering the formula =SUM(C5:C18) in cell C19 will result in which of the following?
frozen [14]
Well the result shown in C19 will show the sum of all cells from C5 to C18:
ie: C5 + C6+ C7+ C8+ C9+ C10+ C11+ C12+ C13+ C14+ C15+ C16+ C17+ C18

:)
3 0
3 years ago
Whatis NOT a key factor while designing a website?
Vaselesa [24]

Answer: Complexity

Explanation: Web designing is referred as the designing of a web page for different purposes such as online business,etc. The most important factor is usability for the improvement in performance of any site and keeping it successful.

It should be user friendly so that interaction and understanding between user and web page can easy.Consistency is also a feature which ensure that web page opened in any browser should have similar quick working.

But there should be no complexity present in the web design which can cause misunderstand with the user and functioning.

7 0
3 years ago
Your location has been assigned the 172.149.254.0 /24 network. You are tasked with dividing the network into 13 subnets with the
ira [324]
  • The subnet mask would be a 32-bit integer which is formed by assigning the host bits to all 0's and the networking bits to so many 1's.
  • In this method, the subnetting separates the IP address between host and network addresses.
  • The subnet mask covers an IP address with its 32-bit number, thus the term "mask".

Given:

Network IP address \bold{= 172.149.254.0 /24}

Subnet numbers \bold{= 13}

Calculating the borrow bits:

\to  \bold{= ceil(\log_{2} 13) = 4 \ bits}

a)

Calculating the dotted decimal value for the subnet mask:

\to \bold{11111111.11111111.11111111.00000000}\\\\\to \bold{255.255.255.240}\\\\

b)

The additional bits which will be needed to mask the subnet mask that is = 4.

Learn more: brainly.com/question/2254014

4 0
3 years ago
Do you think social media should affect presidential elections
Rina8888 [55]

No, not really cuz I think that would be too personal for the president.

5 0
3 years ago
Read 2 more answers
_______ is the protocol suite for the current Internet.
Gala2k [10]
A? not very sure sorry
8 0
3 years ago
Other questions:
  • Java languageThe cost to ship a package is a flat fee of 75 cents plus 25 cents per pound.1. Declare a constant named CENTS_PER_
    5·2 answers
  • When a person buys something from an app store, the cost of the item is charged to a credit card whose number often is known by
    5·1 answer
  • What type of social engineering attack uses email to direct you to their their website where they claim you need to update/valid
    6·2 answers
  • Tammy is preparing to give a presentation. she would like to view information that will remind her what to say to her audience b
    10·1 answer
  • How should font appear in a slide presentation compared to the font in a document
    7·1 answer
  • The small company where you work needs to implement a second server for its accounting system, but does not have the funds to pu
    11·1 answer
  • Project manager George is defining project management to his team. How should he define project management in one sentence?
    7·1 answer
  • True or false = the order of cannot be changed in slide shorter view ,true or false =menu bar is located just below the title ba
    8·2 answers
  • Which generation computer supported GUI operating system?​
    11·1 answer
  • Is orgenized maningful and useful data​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!