Bar Code programing

已完成 已发布的 Apr 27, 2015 货到付款
已完成 货到付款

Write a program that prompts the user for a postal bar code and prints out a message with the zip code that the bar code represents, if it is a valid bar code. If it's not a valid code, your program should print out an error message stating that the bar code is invalid. A bar code can be invalid if it's not bound by two frame bars, if any of the 5-bar combinations don't represent a valid digit, or the correction character isn't correct.

Because we can't display the half and full bars with a standard keyboard, use a vertical line (|) to represent a full bar and a colon (:) to represent a half bar. For instance, the zip code 95014 becomes:

||:|:::|:|:||::::::||:|::|:::|||

You should decompose your program into at least two separate functions: one to convert a 5-bar combination into a digit and one to check that the correction character is correct.

4 Files

For this programming exercise, you are only required to turn-in two files. The first file contains your source code and is called barcode.cpp. Be sure to save your file under this name with no capitalization. Files not named this will have points deducted. The other file you should submit is your README file, which should have no file extension. Again, points will be deducted for README files named incorrectly.

To compile your source code, you should use the provided makefile. Simply copy the makefile into your ec directory and type make on the command-line. This command will compile your file and create an executable file called barcode, assuming there are no compilation errors.

5 Sample Output

For your program to work properly, it must execute using the following syntax:

./barcode

Your program should then prompt the user and wait for a bar code. After the user enters a bar code and presses enter, your program should output a message with the postal code, if the bar code is a valid one. For instance:

Enter a postal bar code: ||:|:::|:|:||::::::||:|::|:::||| The zip code is 95014.

If the bar code doesn't represent a zip code, your program should print out the following message and exit:

The bar code is invalid.

So you won't have to reenter a postal bar code each time, you can save the bar code in a plain text file and use input redirection to read the data from the file. For instance, if you save the above postal bar code in a file called [url removed, login to view], you can execute your program like this:

./barcode < [url removed, login to view]

and your program will output this prompt and your message with the zip code:

Enter a postal bar code: The zip code is 95014.

Note that the bar code won't be displayed and a carriage return won't be inserted on the command line.

C++编程

项目ID: #7561128

关于项目

2个方案 远程项目 活跃的Apr 27, 2015

授予:

virus336

A proposal has not yet been provided

$15 USD 在1天内
(0条评论)
0.0

有2名威客正在参与此工作的竞标,均价$23/小时

shantailarry

I am confident that i can deliver in this meeting all the stated requirements. I am a programmer pursuing computer science, both detailed and result oriented, seeking to deliver a fully functional and robust code. You 更多

$30 USD 在7天内
(0条评论)
0.0