i need a C++ programming project

profileABDUL95Shr
project_1.pdf

1

CPSC 120

Fall 2015

Project #1 — UPC check digits

Introduction

In this project you will write a C++ program that calculates the check digit

for a 12-digit UPC code.

Background

A Uniform Product Code (UPC) is a 12-digit number that identifies a product

sold at a grocery store. UPC codes are often called bar codes because they

are printed as an arrangement of bars:

The digits are grouped into a single digit to the left of the bars; then five

digits together; then another five; then the final digit t o the right of the

bars. In the example above, the 12 digits are 9 87654 32109 8.

The final digit ( 8 in the example above) is a check digit. The first eleven

digits describe what the product is. The last digit is calculated based on

2

the values of the first digits. This is a way of checking whether the code

is valid and has been transcribed properly. Checkout machines can verify

that a UPC code was scanned correctly by confirming whether the check

digit matches what it should be.

Let the first eleven digits be called d1, d2, d3, . . . d11. Then the check digit

may be calculated according to the following expression:

10 − [(3 · (d1 + d3 + d5 + d7 + d9 + d11) + d2 + d4 + d6 + d8 + d10) mod 10]

where mod represents the modulo operator, written as % in C++.

What to do

The program

Write a program that does the following:

1. Asks the user to enter 11 individual digits. Read each digit as a separate

number; do not read a single 11-digit number, as that would not fit in

an int.

2. Print out the digits. Insert a space after the first and sixth digit, so that

the digits appear grouped as they do on a UPC code (see examples,

below).

3. Calculate the check digit. It is OK if a check digit o f 0 gets printed

as 10. (Avoiding this requires if statements, which we haven’t quite

covered yet.)

You can assume that the user enters a valid, n o n -negative, single-digit

number for each input.

3

Pseudocode Before writing C++ code, draw a flowchart or complete your pseudocode for the process. This will help you understand how to break up the program into smaller, manageable parts. Your Pseudocode/Flowcharts should include steps for reading each digit of input, calculating the check code, and printing the check code. Think about whether any of those steps need to be broken into smaller steps.

Examples

The following is an example of correct input and output for the example

UPC code printed earlier: Enter 11 digits:

9

8

7

6

5

4

3

2

1

0

9

11 digits: 9 87654 32109

check digit: 8

Note that the check digit, 8, matches the last digit printed along with the

bar code on page 1.

Another example, from a can of coffee:

4

Enter 11 digits:

0

4

3

0

0

0

0

2

9

4

1

11 digits: 0 43000 02941

check digit: 1

What to turn in

Your submission will be a written report, submitted electronically as a PDF

file through TITANium. Your report should include

1. Your Pseudocode 2. Your C++ source code

3. Input and output for the first example, 9 87654 32109.

4. Input and output for the second example, 0 43000 02941.

5. A third set of inputs and outputs, for a different UPC code. Find a real

world product and use its bar code.

6. Answer the following short-answer questions:

(a) What product does your UPC code come from?

(b) Does the final digit printed on the bar code match the check digit

that your program computed?

5

(c) The check digit system makes bar code scanners more reliable, by

double-checking their work. Can you think of another system that

would benefit from a similar mechanism?

(d) Can you think of any disadvantages to using check digits?

The first page must include your names and a title. Do not forget to list

both partner’s names, and turn in only one submission.

Hint: capturing input and output

This project requires that you print out the input/output of three runs of

your program.

Please take a screen capture with the Print Screen button on the

keyboard. That copies an image of the screen to the clipboard. Then, you

should be able to Paste (CTRL-V) the image into a word processor such as

Microsoft Word or LibreOffice Write.

Hint: creating PDF files

You are required to submit your project report as a single PDF file. One way of

doing this is to prepare the entire report in a word processor, such as Microsoft

Word or LibreOffice Write. Both can produce PDF files seam- lessly. LibreOffice

is a free office suite that may be downloaded from http:

//www.libreoffice.org/. Another option is to produce your report on paper, then

scan the whole thing in. There are other options as well.

Due date

Due Thursday 10/09

Late submissions will not be accepted.

ONLY ONE SUBMISSION PER GROUP (Include both names)