Question

I need it in c++ The U.S. Banking System The code assigned to a bank is...

I need it in c++

The U.S. Banking System

The code assigned to a bank is an eight digit number plus a ninth check
digit. To check for validity, the first eight digits are assigned weights
(left to right) of 7, 3, and 9 repetitively. Each digit is multiplied by
its weight and the products summed. The resulting sum (mod 10) should
equal the check digit.  The assigning of weights insures that all single
digit errors and most transposition errors are detected.

You should run the program twice, once using a valid bank number, and once
using an invalid bank number.

   103000648  Chase 
   103000846  Chase with a transposition error
   103000703  Interbank
   103001469  Kirkpatrick Bank
   103002251  Citizens Bank of Edmond 
   103002521  Citizens Bank of Edmond with a transposition error 
   103002691  First Fidelity
   103002795  First Commercial Bank with an error
   103003632  Banc First
   103003687  First Commercial Bank 
   103013062    "
   103013101    "
   103013266  PRIME BANK  1016 W Covell Road
   103112594  RCB Edmond Road
   103112976  Arvest
   303085230  Allegiance Credit Union
   303085829  Tinker Federal Credit Union 
   303087995  Mid First 
   300387995  Mid First with a transposition error
   103900036  Bank of Oklahoma
   081904808  Bank of America  2145 W Edmond Rd
              Spirit Bank  3823 S Boulevard
              Farmers & Merchants 121 E Waterloo
              Legacy  1289 E 15
              Bank of Nichols Hills



Sample Logic:
  read in a bank number
  write the bank number, and the multipliers 
  compute the checksum
    loop 8 times using i as a control variable
      pick off the i'th digit
        ch = bank number[i] 
        digit[i]  = ch-48;
      multiply it by the appropriate weight
      print the product
      add the product to the subtotal
      save the subtotal in an array (in subtotal[i]) 
    end loop
  loop 8 times printing the subtotals
  print the last subtotal computed
  compute the check digit
  print the check digit 
  if the subtotal % 10 == the last digit
  then
    write 'the check code is valid'
  else
    write 'the check code is invalid'


Sample output:
  - print these numbers - -     don't print these words
  1  0  3  0  0  0  6  4  8     bank number
  7  3  9  7  3  9  7  3        multipliers
  7  0 27  0  0  0 42 12        products
  7  7 34 34 34 34 76 88        subtotals
  88                            sum
  8                             check digit
  the check code is valid

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The above problem can be solved in the following steps-

STEP 1- Read the algorithm carefully given in question and then write C++ code accrodingly.

STEP 2- Read bank number from user and store it in string variable. Store the 8 digit multiplier as constant 73973973. Then create two arrays to store digits and subtotals of size 8.

STEP 3- Write the bank numbers and multipliers as output.

STEP 4-Loop 8 times with i as control variable and do the following-

  • pick the i'th digit from bankNumber and store it in digit array by changing it to integer.
  • store the weight also for corresponding index i.
  • compute the product by multiplying the weight and digit. And print the product.
  • compute and store subtotals in subtotal array.

STEP 5- Loop 8 times and print the subtotals.

STEP 6-Print the last subtotal. Then compute the check digit and then print this check digit.

STEP 7-Finally, using if-else check if last subtotal%10 is equal to check digit. If yes then print valid check code otherwise print invalid check code.

C++ CODE-

//include neccessary header files
#include <iostream>
using namespace std;
//driver method
int main()
{
//variable to store bankNumber
string bankNumber;
//read bank number from user
cin>>bankNumber;
//from here on everything is part of output
cout<<"\n-------OUTPUT-----------\n";
//store the multipliers in a variable
//multipliers is always fixed that is why its store as constant here
string multipliers = "73973973";
//arrays to store the digits and subtotal
int digit[8];
int subtotal[8];
//write the bank number
cout<<bankNumber<<endl;
//write the multipliers
cout<<multipliers<<endl;
//loop 8 times using i as control variable
for(int i=0;i<8;i++){
//pick of i'th digit
char ch = bankNumber[i];
digit[i] = ch - 48;
  
//store weight by converting multipliers character to integer
int weight = multipliers[i]-48;
//multiply it by the appropriate weight
int product = digit[i] * weight;
//print the product
cout<<product<<" ";
//adding product to subtotal
//if its first subtotal, then put product directly to 0th index
if(i==0){
subtotal[i] = product;
}
//otherwise, subtotal is equal to product + previous index subtotal
else{
subtotal[i] = subtotal[i-1] + product;
}
}
//newline
cout<<endl;
//loop 8 times printing the subtotals
for(int i=0;i<8;i++){
cout<<subtotal[i]<<" ";
}
//newline
cout<<endl;
//print the last subtotal computed
//since subtotal array is of size 8
//last subtotal will be at index 7 of subtotal array
cout<<subtotal[7]<<endl;
  
//compute the check digit
int checkDigit = bankNumber[8]-48; //since last character in bankNumber string is checkDigit
//print the checkDigit
cout<<checkDigit<<endl;
  
//as per algorithm
//if subtotal%10 == checkDigit
if(subtotal[7]%10 == checkDigit){
//then print that check code is valid
cout<<"Check code is valid\n";
}
//otherwise
else{
//print check code is invalid
cout<<"Check code is invalid";
}
return 0;
}

Image of Code to better understand the indentation and comments-

OUTPUT-

Valid Bank number - 103000648

Invalid Bank number - 103000148

If this answer helps, please give an up vote and feel free to comment for any query.

Add a comment
Know the answer?
Add Answer to:
I need it in c++ The U.S. Banking System The code assigned to a bank is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please I need help with this c++ code. please show all steps , write comments and...

    Please I need help with this c++ code. please show all steps , write comments and show sample runs. Thank you. 1. The Federal Bureau of Investigation (FBI) has recently changed its Universal Control Numbers (UCN) for identifying individuals who are in the FBI's fingerprint database to an eight-digit base 27 value with a ninth check digit. The digits used are: 0123456789ACDE FHJKLMNPRTVWX Some letters are not used because of possible confusion with other digits: B->8, G->C, I- >1, 0->0,...

  • Please write the code in C++. This is all one question with multiple requirements. 1) Create...

    Please write the code in C++. This is all one question with multiple requirements. 1) Create an enumerated data type called CrdCard The types of Credit Cards to create are all 16 digits long except American Express: American Express (34 or 37), Visa (Starts with a 4), MasterCard (Starts with 51-55), Discover (Starts with 6011). 2) Create a function that takes in the enumerated type and returns a valid credit card number using the Luhn Algorithm (also called the Modulus...

  • Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================")...

    Need help writing this code in python. This what I have so far. def display_menu(): print("======================================================================") print(" Baseball Team Manager") print("MENU OPTIONS") print("1 - Calculate batting average") print("2 - Exit program") print("=====================================================================")    def convert_bat(): option = int(input("Menu option: ")) while option!=2: if option ==1: print("Calculate batting average...") num_at_bats = int(input("Enter official number of at bats: ")) num_hits = int(input("Enter number of hits: ")) average = num_hits/num_at_bats print("batting average: ", average) elif option !=1 and option !=2: print("Not a valid...

  • Banks issue credit cards with 16 digit numbers. If you've never thought about it before you...

    Banks issue credit cards with 16 digit numbers. If you've never thought about it before you may not realize it, but there are specific rules for what those numbers can be. For example, the first few digits of the number tell you what kind of card it is - all Visa cards start with 4, MasterCard numbers start with 51 through 55, American Express starts with 34 or 37, etc. Automated systems can use this number to tell which company...

  • C PROGRAM A barcode scanner for Universal Product Codes (UPCs) verifies the 12-digit code scanned by...

    C PROGRAM A barcode scanner for Universal Product Codes (UPCs) verifies the 12-digit code scanned by comparing the code’s last digit (called a check digit) to its own computation of the check digit from the first 11 digits as follows: 1. Calculate the sum of the digits in the odd-numbered positions (the first, third… eleventh digits) and multiply this sum by 3. 2. Calculate the sum of the digits in the even-numbered positions (the second, fourth… tenth digits) and add...

  • Java Help Please: I'm doing something wrong with my while loop. I want my code to...

    Java Help Please: I'm doing something wrong with my while loop. I want my code to check the phone number that is input to make sure it matches. If it doesn't I want it to print out Error! and I want my While loop to ask the user to try again by inputting another phone number. When the user puts in a phone number that matches I want the program to continue to output my tokens. When I run this...

  • Using python 3.6 How do I incorporate 0 or negative input to raise an error and...

    Using python 3.6 How do I incorporate 0 or negative input to raise an error and let the user try again? like <=0 #loop to check valid input option. while True: try: choice = int(input('Enter choice: ')) if choice>len(header): print("Invalid choice!! Please try again and select value either:",end=" ") for i in range(1,len(header)+1): print(i,end=",") else: break choice = int(input('\nEnter choice: ')) except ValueError as ve:print('Invalid response, You need to select the number choice from the option menu') # Catch your...

  • PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP...

    PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP AND FORMAT: #include <iostream> using namespace std; int main() { //variables here    do { // program here             }while (true);    } Objectives To learn to code, compile and run a program containing SELECTION structures Assignment Write an interactive C++.program to have a user input the length of three sides of a triangle. Allow the user to enter the sides...

  • 12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try...

    12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try the code and catch the errors. The other paradigm is 'Look before you leap' which means test conditions to avoid errors. This can cause race conditions. 1.Write the output of the code here: class MyError(Exception): pass def notZero(num): if num == 0: raise MyError def run(f): try: exec(f) except TypeError: print("Wrong type, Programmer error") except ValueError: print("We value only integers.") except Zero Division Error:...

  • I need a code and its java Blue jay please its almost due Week 8 Quiz...

    I need a code and its java Blue jay please its almost due Week 8 Quiz Submitting a file upload File Types pdf Due Friday by 11:30am Points 10 Available after Oct 25 at 10:45am With your team, write a program that inputs a 3-digit integer, like 731. Then the program should multiply the number by 1001, which would make 731 become 731731. Next, write a for loop with the following header: for (int i =7;i<=13; i+=2) In the for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT