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
In the program below, which two variables have the same scope?
bagirrra123 [75]

Answer:

rhymeWord

Explanation:

correct answer edge 2020

3 0
3 years ago
Read 2 more answers
The encapsulating security ______ protocol provides secrecy for the contents of network communications as well as system-to-syst
Goshia [24]

Answer:

payload

Explanation:

Cyber security can be defined as preventive practice of protecting computers, software programs, electronic devices, networks, servers and data from potential theft, attack, damage, or unauthorized access by using a body of technology, frameworks, processes and network engineers.

The encapsulating security payload (ESP) protocol is a standard protocol that provides secrecy for the contents (data) transmitted via network communications, as well as system-to-system authentication and data integrity verification so as to prevent unauthorized access.

Basically, the encapsulating security payload (ESP) protocol is a transport layer protocol that provides data confidentiality, integrity and authentication in IPv6 and IPv4 protocols.

5 0
3 years ago
Travis sends Suri what purports to be a link to an e-birthday card, but when she clicks on the link, software is downloaded to h
12345 [234]

Answer:

Identity Theft

Explanation:

Identity theft is the act of someone who obtains details about someone else illegally.  This is done to find personal and financial information such  name, address,social security number, passwords, and credit card number, phone number, e-mail, etc. Then the hacker can use this information to control bank accounts, e-mails, computers, portray himself as you are, or sell information to someone else.

3 0
3 years ago
QUESTION 2
Len [333]

Answer:

Group of answer choices.

A. Apply numbering to the list.

B. Apply bullets to the list.

C. Apply multilevel numbering to the list.

D. Manually enter a ">" character at the beginning of each item in the list.

Answer:

B. Apply bullets to the list.

Explanation:

Formatting is a feature found in a lot of word processing software applications such as Microsoft Word, Notepad, etc., which is designed to avail end users the ability to apply specific formatting options such as cut, bold, italics, underline, list, etc., to texts based on certain criteria defined by an end user.

Microsoft Word refers to a word processing software application or program developed by Microsoft Inc. to enable its users type, format and save text-based documents.

In Microsoft Word, a list can be formatted using a numbered or bulleted arrangement style. A numbered style (1, 2, 3, 4, etc) is typically used for an ordered list while a bullet is designed to be used for an unordered list.

Hence, the best way to format a document containing a list of items that appear in no particular order is to apply bullets to the list.

For example, a bulleted list of my favorite subjects arranged in no particular order would appear as this;

English language

Mathematics

Geography

Biology

Chemistry

Physics

Computer technology

8 0
3 years ago
To instruct Oracle11 g to sort data in ascending order, enter ____ after the column name in the ORDER BY clause.
Paha777 [63]

Answer:

A. ASC

Explanation:

In Oracle11 g ORDER BY clause is used to sort data andit is also used in mysql ,ms access.Though we not to mention ASC to sort in increasing order because by default it sorts the data in ascending order if we do not mention ASC or DESC.To sort in descending order we have to mention DESC.

So the correct answer to this question is ASC.

7 0
3 years ago
Read 2 more answers
Other questions:
  • What statement needs to be included below to retrieve all rows from the Invoices table with InvoiceTotal greater than 100?
    9·1 answer
  • Which of the following is least likely checked by the comprehensive component monitor?
    7·1 answer
  • What is credibility in the often-used framework of quality criteria?
    9·1 answer
  • Who is involved in helping shape the emotional impact of a film? (Select all that apply.)
    8·2 answers
  • Www.microsoft.com is an example of this (two words) (last letter is e) and has to be (10 letters)
    10·1 answer
  • The mouse pointer becomes different shapes depending on the pointer s location and locations you click on the screen. true false
    6·1 answer
  • To update a bibliography field that is not contained in a ____, right-click the bibliography, and then click Update Field on the
    10·1 answer
  • PLEASE HELP ASAP
    13·2 answers
  • The<br>tool can lighten the part of an<br>image.*<br>Your answer​
    13·1 answer
  • Question 1 (1 point)
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!