Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Statement Did you know that the first six digits of the credit card number encode the card type/issuer? For example, Visa credit cards in

Problem Statement

Did you know that the first six digits of the credit card number encode the card type/issuer? For

example, Visa credit cards in the US begin with the number 4. Although the mapping is a little more sophisticated, for lab 2, write a program that determines the type of credit for an input account number using the following list:

Card Type

Card Number Prefix

American Express

34,37

Discover

65

MasterCard

50-55

Visa

40-49

Write a program that prompts for the account number. Parse off the first two digits. Use the

if-statement to determine the type of credit card. Your program should work on all test cases.

Requirements:

1.Create a script named HW2_yourname.m

2. Follow the algorithm to implement your program.

3. Instead of comparing the prefix as character string, convert and compare the extracted prefix as numbers.

Input Data:

Credit card number, read in as character array

Output Data:

Credit card number and type of credit card

Algorithm:

*Step 1~2 are the same as Lab #2.

Begin you program with clc; clear;

Prompt the user for a 16 digits credit card number.

Determine if the account number is exactly 16 digits. If it is, parse off the first 2 digits. Else output an error message: Invalid card number.

*Hint: 1. Read in the account number as a character array using input() function.

2. Get the length of a string using length() function.

3. Extract first two digits with digits=str(1:2);

4. Convert the extracted digits to a number with str2num();

*Note: For this assignment, you are NOT allowed to use strcmp() function. Compare the extracted digits as a number can greatly reduce the complexity of the logical expressions in if-statement.

Use another set of if-statement to determine the type of credit card. If the credit card type is not in the list, output an error message: Unknown card type.

Use AND(&&), OR(||) operators to evaluate multiple logical expressions at the same time.

Use only one fprintf() function to output the results.

Sample outputs:

Test cases:

Account #

Credit card type

6555160016001600

Discover

5455160016001600

MasterCard

7700160016001600

Unknown

54551234123412341234

Invalid

4555160016001600

Visa

Bonus point:

1. Identify 4A~4Z as Visa Premium card type.

e.g 4X00111122223333, is valid, the card type is Visa Premium.

2. Again, You are not allowed to use the strcmp() function.

Notes

Before each significant step, provide a comment explaining the step (do not comment every line of code). e.g %Extract first two digits

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

Oracle PL/SQL Programming Database Management Systems

Authors: Steven Feuerstein

1st Edition

978-1565921429

More Books

Students also viewed these Databases questions

Question

Be familiar with the integrative servicescape model.

Answered: 1 week ago

Question

Determine the roles of spatial layout and functionality.

Answered: 1 week ago