Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Purpose To practice UDP programming, including the use of the socket, bind, sendto, and recvfrom system calls. Assignment Write a C++ program that will validate

Purpose

To practice UDP programming, including the use of the socket, bind, sendto, and recvfrom system calls.

Assignment

Write a C++ program that will validate (imaginary) credit card transaction information by querying to a UDP server. You will be writing the client, and the servers address and port information will be provided to you.

Program

Implement a C++ program that prompts the user for the details of a credit card transaction. These details include the name of the card holder, the credit card number, the expiration date, and the dollar amount to be authorized. The card holder name is a string. The card number must be a 15 or 16 digit number. The expiration date is of the form MM/YYYY (eg. 12/2019). The amount will be a number with two digits after the decimal point.

Your program will send the information to a UDP server in a single datagram containing all of the information spec- ified. The server will respond with a single datagram, containing whether the credit card transaction is valid, and an authorization code.

The UDP datagram sent to the server must contain the card number, expiration date, amount, and card holder name in a colon separated list, for example: 6011 1234 4321 1234:12/2016:543.21:John Doe.

UDP Server Details

The details for the UDP Server will be listed in the assignment listing on BlackBoard.

Error Checking

Your program must check whether the name, credit card, expiration date, and amount are well formed. If they are not, prompt the user for them again.

Name can be any string less than 64 characters. Credit card number must be either 15 or 16 digits, with the possibil- ity that spaces may be used between numbers to separate them into groups. The expiration date must be of the form MM/YYYY (obviously MM should be between 01 and 12). The amount can be any number digits followed by a decimal point and then two more digits.

Example Run

% ./assign7 Welcome to the Credit Card transaction verification utility: Enter card holder name (or quit): John Doe Enter CC number: 3724 531039 23000 Enter expiration: 10/2016 Enter amount: 12.00 Wed Nov 14 10:34:05 CST 2012: American Express: 3715 199624 21012 is valid: authorization code: 198806 for $12.00 Enter card holder name (or quit): Susan Maloney Enter CC number: 6011 1234 4321 1234 Enter expiration: 12/16

... expiration date invalid, try again: 12/2014 Enter amount: 1234.56 Wed Nov 14 10:35:45 CST 2012: Discover: 6011 1234 4321 1234 is valid: authorization code: 386489 for $1234.56 Enter card holder name (or quit): Manny Diaz Enter CC number: 6011432112344321 Enter expiration: 01/2018 Enter amount: forty

 ... amount invalid, try again: 44 

... amount invalid, try again: 44.44 Wed Nov 14 10:36:33 CST 2012: Discover: 6011432112344321: checksum incorrect Enter card holder name (or quit): quit %

1

Hints

You can assume that user input is less than 64 characters long.

If any of the UDP system calls fail, print out the error message with perror and exit the program.

You can write your own functions to validate each of the fields, or you can use regular expressions (see regcomp and regexec functions) to do the check.

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

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions