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
You need to design an online login form in which users have to type their name and password to log into an application. The pass
katrin2010 [14]

The string data type is most suited for password fields.

<h3 /><h3>What is the string data type?</h3>

A string data type is often used in programming to specify that a field can contain any sequence of characters such as a combination of numbers and letters which may be repeated. A typical string data type could also contain a maximum limit of characters.

You can learn more from a similar question about string data types here brainly.com/question/5871492

#SPJ1

4 0
2 years ago
Pls answer dis question when i'm not connected and i open bluestacks 5 it will be working but if i am connected it wil not work
SVEN [57.7K]
Maybe try uninstalling and reinstalling it?
8 0
3 years ago
Documenting Business Requirements helps developers control the scope of the system and prevents users from claiming that the new
tiny-mole [99]

Answer:

The answer is "True".

Explanation:

Industry demands documentation enables developers to monitor the system's range and protects users claims, that somehow the new system will not accomplish their business goals.

  • The main goal of this report is to offer everyone to be transparent, about what should be accomplished and when.  
  • It is the new business plan, that should be outlined in detail, that's why the given statement is true.
3 0
3 years ago
Lost passwords set for documents in Microsoft® Word® documents can be retrieved in the backstage view. True False
Nat2105 [25]

Answer:

True

Explanation:

Hope this helped!

3 0
3 years ago
Read 2 more answers
What predefined match policy allows viewers to watch a claimed video but does not allow ads to display on the video
Alona [7]

Answer:

The correct response is "Track".

Explanation:

  • Tracks encourage the individual that listens to that same music video to miss or ignore that same starting of almost any soundtrack at a certain moment.
  • It might also impact an individual who accompanies a facility that implements or obeys guests.

For obvious reasons, a digital ad service can track client's internet search engine behavior patterns to continue providing accurate recommendations.

6 0
3 years ago
Other questions:
  • (Game Design) Which of the following is NOT a name of a popular digital sculpting application?
    13·1 answer
  • On the Excel Ribbon, click the Data tab in the Sort &amp; Filter Group, and then click the Sort button to conduct a _____ sort.
    8·1 answer
  • In the code that follows, window is a/an ____________________________. window.prompt("enter your name");
    5·1 answer
  • 7. Four more than negative eleven times a number is 26.​
    7·2 answers
  • Write the SQL query that would search a table called Movies and return the titles of movies that were made in 1975.
    7·1 answer
  • What are the types of micro computer?​
    14·2 answers
  • Instruction: weird I know (~ ̄³ ̄)~
    5·1 answer
  • What is another term used for next generation firewalls
    12·1 answer
  • 10. Site-to-Site VPN architecture is also known as
    6·1 answer
  • A diminished triad can be indicated by
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!