Question

In: Computer Science

Using Perl language: Write a program that reads a string from the standard input, and uses...

Using Perl language:
Write a program that reads a string from the standard input, and uses a Perl regular expression to test whether the string looks like a valid credit card number. The card numbers of four major companies follow the following formats:
 

Visa

13 or 16 digits, starting with 4.

MasterCard

16 digits, starting with 51 through 55.

Discover

16 digits, starting with 6011 or 65.

American Express

15 digits, starting with 34 or 37.

 
You should test your script with following numbers:
 
(1)4941 5968 0539 2447
(2) 371642190784801
(3) ‎5168441223630339

(4) 6011988461284820

Please include screenshots for your output.

Solutions

Expert Solution

program

OUTPUT 1

OUTPUT 2

OUTPUT 3

​​​​​​​OUTPUT 4

PROGRAM IN DOCUMENT FORMAT

print "Enter card number please\n";
$card = <>; #variable to hold card number
chomp $card; #remove \n value from string variable
print "Entered card number is",$card;
$cardlen = length($card); #found length of card number
$card = $card*1; #convertion from string to integer
while($card>0)
{
$n=int($card%10);
$rev=int($rev*10)+$n; #while loop to find reverse of card number
$card=int($card/10);
  
}
$temp2=$rev%100;
while($temp2>0)
{
$n=int($temp2%10);
$rev2=int($rev2*10)+$n; #while loop for extracting first 2 digits from card number
$temp2=int($temp2/10);
  
}

$temp4=$rev%10000;
while($temp4>0)
{
$n=int($temp4%10);
$rev4=int($rev4*10)+$n; #while loop for extracting first 4 digits from card number
$temp4=int($temp4/10);
  
}

if($cardlen==13) #if condition to check whether card number length is 13
{
if($rev%10==4) #if condition to check whether the first digit of card number is 4
{
print "\n You entered a valid Visa card number.\nThankyou\n";
}
else
{
print "\n Invalid card number.";
}
}
elsif($cardlen==16) #if condition to check whether card number length is 16
{

if($rev%10==4) #if condition to check whether the first digit of card number is 4
{
print "\n You entered a valid Visa card number.\nThankyou\n";
}
elsif($rev2>=51 && $rev2<=55) #if condition to check whether the first 2 digit of card number is 51 through 55
{
print "\n You entered a valid Master card number.\nThankyou\n";
}
elsif($rev4==6011 || $rev4==65)#if condition to check whether the first 4 digit of card number is 6011 or it is equalto 65
{
print "\n You entered a valid Discover card number.\nThankyou\n";
}
else
{
print "\n Invalid card number.";
}
}
elsif($cardlen==15) #if condition to check whether card number length is 15
{
if($rev2==34 || $rev2==37) #if condition to check whether the first digit of card number is 34 or 37
{
print "\n You entered a valid American express card number.\nThankyou\n";
}
else
{
print "\n Invalid card number.";
}
}
else
{
print "\n Invalid card number.";
}

NOTE:

If this solution is helpful to you please thumbs up(like)

Thankyou


Related Solutions

Write a JAVA program that reads in a string from standard input and determines the following:...
Write a JAVA program that reads in a string from standard input and determines the following: - How many vowels are in the string (FOR THE PURPOSE OF THIS PROGRAM 'Y' is NOT considered a vowel)? - How many upper case characters are in the string? - How many digits are in the string? - How many white space characters are in the string? - Modify the program to indicate which vowel occurs the most. In the case of a...
Using Java: Write a program that uses hash tables and reads in a string from the...
Using Java: Write a program that uses hash tables and reads in a string from the command line and a dictionary of words from standard input, and checks whether it is a "good" password. Here, assume "good" means that it (i) is at least 8 characters long, (ii) is not a word in the dictionary, (iii) is not a word in the dictionary followed by a digit 0-9 (e.g., hello5), (iv) is not two words separated by a digit (e.g.,...
Q20. Using C++ style string to write a program that reads a sentence as input and...
Q20. Using C++ style string to write a program that reads a sentence as input and converts each word of the sentence following the rule below: For every word in the sentence, the first letter is relocated the end of the word. Then append the string “KPU” to the word. More requirements: All letters in the output should be uppercase. More assumptions: The input sentence contains no non-alphabetic letters Sample Run: Please enter the original sentence: i LOVE to program...
Q20. Using C++ style string to write a program that reads a sentence as input and...
Q20. Using C++ style string to write a program that reads a sentence as input and converts each word of the sentence following the rule below: For every word in the sentence, the first letter is relocated the end of the word. Then append the string “KPU” to the word. More requirements: All letters in the output should be uppercase. More assumptions: The input sentence contains no non-alphabetic letters Sample Run: Please enter the original sentence: i LOVE to program...
Write a Java program (name it PasswordTest) that reads from the user a string input (representing...
Write a Java program (name it PasswordTest) that reads from the user a string input (representing a password) and determines whether the password is “Valid Password” or “Invalid Password”. A valid password has at least 7 characters and includes at least one lower-case letter, at least one upper-case letter, at least one digit, and at least one character that is neither a letter nor a digit. Your program will need to check each character in the string in order to...
Write an assembly language program to input a string from the user. Your program should do...
Write an assembly language program to input a string from the user. Your program should do these two things: ***** I AM POSTING THIS QUESTION FOR THE THIRD TIME NOW,I WANT IT DONE USING INCLUDE IRVINE32.INC***** 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be:...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
Write a short main program that reads an integer n from standard input and prints (to...
Write a short main program that reads an integer n from standard input and prints (to standard output) n lines of * characters. The number of *’s per line should double each time, starting with 1. E.g., if n = 5, the output should be as follows: * ** **** ******** ****************
Write a program called x.c that reads an integer n from standard input, and prints an...
Write a program called x.c that reads an integer n from standard input, and prints an nxn pattern of asterisks and dashes in the shape of an "X". You can assume n is odd and >= 5. Solve this problem using only while loop. Solution: ./x Enter size: 5 *---* -*-*- --*-- -*-*- *---* ./x Enter size: 9 *-------* -*-----*- --*---*-- ---*-*--- ----*---- ---*-*--- --*---*-- -*-----*- *-------* ./x Enter size: 15 *-------------* -*-----------*- --*---------*-- ---*-------*--- ----*-----*---- -----*---*----- ------*-*------ -------*------- ------*-*------...
Write a program called distance_square.c that reads an integer n from standard input, and prints an...
Write a program called distance_square.c that reads an integer n from standard input, and prints an nxn pattern of integers. Each integer is the minimum number of steps required to reach the centre of the square. Steps can only be up, down, left or right (no diagonal movement). the question should be allowed to use only while loop 4 3 2 3 4 3 2 1 2 3 2 1 0 1 2 3 2 1 2 3 4 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT