Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would I go about constructing a c++ program that inputs sequences of digits from a data file? Emphasis on: Arrays, Character Input, Arithmetic, Loops,

How would I go about constructing a c++ program that inputs sequences of digits from a data file?

image text in transcribedimage text in transcribed
Emphasis on: Arrays, Character Input, Arithmetic, Loops, and Decisions Most values which consist of a sequence of digits, such as credit card numbers and the bar codes used on most products, include a check digit {the last digit in the bar code), which allows checking for transmission errors by the credit card or bar code reader. The reader compares the check digit in the transmitted number to a digit calculated by a method similar to this, which treats the sequence of digits as an array containing one digit per element: 1. Add up all the digits with odd-numbered subscripts (posiljons 1, 3, ...] in the anay, excluding the check digit. For example, for the W you would calculate 3 + ? + 3 = 13 2. Multiply each array value with an even-numbered subscript, excluding the check digit, by 2. If the result of the multiplication exceeds 9, add its two digits. Add the sum of these results to the sum calculated in Step 1. For example, using the same sequence 134-?83, F1 2 m 2*4 = a and rs = 15 16 is 3-. 9, so calculate 1+6 = 1' Then 13 (from step 1) + 2 + B + F = 30. 3. Divide the result of Step 2 by 10 and subtract the remainder from 10. If the result is less than 1!], the result should equal the check digit; otherwise, the check digit should be zero. For example, using the same sequence 134?83, 30 ,r' 10 = 3 with remainder II} ID D is 1t]; 1t] is not at 10;, Wthe check digit should be I]. So the check digit for this sequence is correct. Write a program which inputs sequences of digits {one sequence per line with no spaces between the digits] from the data le DigitSeq.txt. You can assume that a previous pro-gram has validated the data to make sure that each sequence consists only of valid digits. Print the input sequence to the screen or to a le, then print the value of what you calculate the check digit should be. Then print 'v'ALID or INVAIJD to indicate whether the check digit is correct or not. "re digit sequences may be of different lengths, but you may assume that there will be no sequence longer than 2D characters. Requirements: 1) The sequence must be stored and manipulated as an array or string. 2) You must use at least 3 functions in addition to main. Some suggestions: - input the sequence, convert a character into an integer, du star: 1 calculations do step 2 calculations, do step 3 calculations, determine the correct check digit [this function could call the previous three functions) and return the calculated check digit. 3) At least one function must return a value with a return statement, at least one funcljon must have a value parameter, and at least one function must have a reference parameter. 4) I recommend printing the results of your calculations so that you can code a little at a time and make sure that what you've coded so far is correct. 111is will also malce is easier for me kualuatlon Checklist Identication (name, mt, W10 points) Purpose of program WE points) Comments within program [10 points] Meaningful identiers (5 points] Indentationfprogram style (10 points) No global variables [10 points} Used at least one arrayfvector or string (15 points] Reads from the le [10 points} Calculates the correct check digit and correctly identies the sequence as being valid or not [25 points} DIgItSeg.txt le 350460614622 123456?89? 930630133 96?583?865?5451 30023493 4?3401133641 BS?6095435450 908?B?834500023 459021

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions