Question
please write c++ (windows) in simple way and show all the steps with the required output
Write a C++ program that simulates the operation of a simple online banking system The program starts by displaying its main
2. When choice 2 (withdrawal money) is selected, the program should ask the user to enter withdrawal amount which should be v
Table 1. Credit card types based on the starting digit (left to right) Card Type American Express Visa MasterCard Discover Ca
The following credit card numbers can be used to test your program: Card Type Card Number 5278576018410707 Yes MasterCard 373
Write a C++ program that simulates the operation of a simple online banking system The program starts by displaying its main menu as shown in Figure1 splay Account nformatson verity Your credit Card elect vour choice Figure 1 Main menu of the program The menu is composed of the following choices 1. When choice 1 is selected (Display Account information), the program should display account information and account balance. This information (account information and account balance) is stored in two separate text files"accountinfo.txt and "balance.txt, respectively. Figure 2 Shows sample examples of these two files First Name: your first name ast Name: your last nane count Number: 99988811231 te of Birth: 12/4/2019 і1: yourNaneauaeu.ac.ae 5000 Ln6,Cal 100% Windows- winde d Lt. Cd . 100% Figure 2 Text files: accountinfo.txt and balance.brt Once choice 1 is selected, the content of these files should be displayed as shown in Figure 3. After that the program start over displaying the main menu again once the Enter Key is pressed. rst Nane: your first name ast Name: your last name ccount Number: 99988811231 ate of Birth: 12/4/2019 na1t: yourNameğuaeu.ac.ae The Balance is :AED 25000 Figure 3 Output of "Display Account Information" choice
2. When choice 2 (withdrawal money) is selected, the program should ask the user to enter withdrawal amount which should be validated (withdrawal amount should be positive and less than the account balance). This shown in Figure 4 rour current Balance: 1500 nter withdrawa1 Amount: 20000 rou Are About to withdraar From Your Account rour, Current Balance: is00 nter withdrawel Amount: -677 You Are About to withdrau From Your Account our current Balance: 1500 nter withdrawal Amount: Figure 4 Withdrawal selection and validation Once a valild value is entered, it should be subtracted from the balance value, which is stored in file 'balance.txt, and then the file should be updated with the new balance value. To update the file you need to open the file for output; the new balance value is then can be saved to the file removing the old value. This can be done in C++ using the following: fstream outFile; outFile.openc"balance.txt", ios:sout | ios::trunc); where: (ios: :out) for output mode, (ios::trunc) for removing the file content if it does exisafor combining both operaion opening as output fle and removing its old content. 3. When choice 3 (Deposit) is selected, the program should ask the user to enter deposit amount which should be validated as positive value only. Once a valid value is entered, it should be added to the balance value, which is stored in file "balance.txt and then the file should be updated with the new balance value. This also can be accomplished as explained in point 2 above. 4. When choice 4 (Verify Your Credit Card) is selected, the program should read your credit card (for example: 5278576818418787) and verify whether it is valid or not In addition, the program must display the type (i.e. name of the company that produced the card). Each credit card must start with a specific digit (starting digit: 1st digit from left to right), which also is used to determine the card type according Table 1.
Table 1. Credit card types based on the starting digit (left to right) Card Type American Express Visa MasterCard Discover Card Starting Digit 5 6 The total number of digits of a credit card number must be between 13 to 16 digits. In addition, your program should validate credit card numbers according to Luhn Rule that is basically can be described as follows (as an illustration, the rules will be applied to the credit card number 4388576018402626): A Double every even digit from right to left If the doubling results in two digits number, sunm the digits to get a single digit number 2 2 4 2 2 4 4*2-8 1 2-2 4-2 B. Compute the sum of single digit numbers obtained from step A above: C. Compute the sum of every odd digit from right to left: D. Compute the sum of the results from step B and step C: E. If the total sum from step D is divisible by 10, the card number is valid. Otherwise, it is Sum of even single-digits 4+4+8+2+3+1+7+8-37 Sum of odd digits -6+6 0+8+0+7+8+3-38 Total sum: 37 + 38 75 not valid Is 75 divisible by 10 (without remainder)? No, the card number in this example is Invalid. Sample examples of this menu choice is shown in Figure 5. he Credit Card Nusbe 1 vali the Cred t Card Nunber is Invalid Belongs ess Enter key To Start Over nter key To Start Figure 5 Credit Card Number Verification
The following credit card numbers can be used to test your program: Card Type Card Number 5278576018410707 Yes MasterCard 373800410401774 4388576018402626 601195764182 Valid? American Express Yes No No 5. When choice 5 (Quit Application) is selected, the program should stop. 6. After displaying each selection, you need to clear the screen. In windows, you can use the function call system("cls")i. But in MacOS using the xcode, the best way to do it is by using something like: cout
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<fstream>

#include<cstdlib>

#include<string>

using namespace std;

// Calls the method to read data from file and store it in respective variable

// Returns information using call by reference

void readFile(string &firstName, string &lastName, long long int &accNum, string &dob, string &email,

double &balance)

{

// ifstream object declared to read data from files

ifstream fReadOne;

// To store '\n' character

string newLine;

// To store heading

string heading;

// Opens the file for reading

fReadOne.open("accountInfo.txt");

// Checks if the the file unable to open for reading display's error message and stop

if(!fReadOne)

{

cout<<"\n ERROR: Unable to open the file for reading.";

exit(0);

}// End of if condition

// Loops till end of the file

while(!fReadOne.eof())

{

// Reads first name heading split by ':' symbol

getline(fReadOne, heading, ':');

// Reads first name

fReadOne>>firstName;

// Reads new line character

getline(fReadOne, newLine, '\n');

// Reads last name heading split by ':' symbol

getline(fReadOne, heading, ':');

// Reads last name

fReadOne>>lastName;

// Reads new line character

getline(fReadOne, newLine, '\n');

// Reads account number heading split by ':' symbol

getline(fReadOne, heading, ':');

// Reads account number

fReadOne>>accNum;

// Reads new line character

getline(fReadOne, newLine, '\n');

// Reads date of birth heading split by ':' symbol

getline(fReadOne, heading, ':');

// Reads date of birth

fReadOne>>dob;

// Reads new line character

getline(fReadOne, newLine, '\n');

// Reads email heading split by ':' symbol

getline(fReadOne, heading, ':');

// Reads email

fReadOne>>email;

// Reads new line character

getline(fReadOne, newLine, '\n');

}// End of while loop

// Close the file

fReadOne.close();

// Re opens the file for reading balance.txt file

fReadOne.open("balance.txt");

// Checks if the the file unable to open for reading display's error message and stop

if(!fReadOne)

{

cout<<"\n ERROR: Unable to open the file for reading.";

exit(0);

}// End of if condition

// Reads the balance

fReadOne>>balance;

// Close the file

fReadOne.close();

}// End of function

// Function to display customer information with current balance

void show(string firstName, string lastName, long long int accNum, string dob, string email,

double balance)

{

cout<<"\n First name: "<<firstName<<"\n Last Name: "<<lastName<<"\n Account Number: "<<accNum

<<"\n Date of Birth: "<<dob<<"\n Email: "<<email<<"\n The balance is: "<<balance<<endl;

}// End of function

// Function to withdraw money

// Update the balance and writes it to balance.txt file

void withdrawMoney(double &balance)

{

// To store withdraw amount

double amt;

// fstream object declared

fstream outFile;

// Opens the file for writing with deleting previous data

outFile.open("balance.txt", ios::out | ios::trunc);

// Loops till valid withdrawal amount entered by the user

do

{

// Displays current balance

cout<<"\n You are about to withdraw from your account...";

cout<<"\n Your current balance: $"<<balance;

// Accepts the withdrawal amount

cout<<"\n Enter withdrawal amount: $";

cin>>amt;

// Checks for negative or zero

if(amt <= 0)

cout<<"\n Negative amount not allowed.";

// Checks for over drawn

else if(amt > balance)

cout<<"\n Overdrawn not allowed.";

// Otherwise valid amount

else

{

// Update the balance by subtracting withdrawal amount from current balance

balance -= amt;

// Writes current balance to file

outFile<<balance;

// Come out of the loop

break;

}// End of else

}while(1); // End of do while loop

// Close the file

outFile.close();

}// End of function

// Function to deposit money

// Update the balance and writes it to balance.txt file

void depositMoney(double &balance)

{

// To store deposit amount

double amt;

// fstream object declared

fstream outFile;

// Opens the file for writing with deleting previous data

outFile.open("balance.txt", ios::out | ios::trunc);

// Loops till valid withdrawal amount entered by the user

do

{

// Displays current balance

cout<<"\n You are about to withdraw from your account...";

cout<<"\n Your current balance: $"<<balance;

// Accepts the deposit amount

cout<<"\n Enter deposit amount: $";

cin>>amt;

// Checks for negative or zero

if(amt <= 0)

cout<<"\n Negative amount not allowed.";

// Otherwise valid amount

else

{

// Update the balance by adding deposit amount from current balance

balance += amt;

// Writes current balance to file

outFile<<balance;

// Come out of the loop

break;

}// End of else

}while(1); // End of do while loop

// Close the file

outFile.close();

}// End of function

void validCreditCard()

{

string creditCardNumber;// = "5278576018410707";

int finalSum = 0, sumEven = 0, sumOdd = 0, evenDigit = 0, oddDigit = 0;

cout<<"\n Enter credit card number: ";

cin>>creditCardNumber;

// Repeats once for each digit for the creditCardNumber.

// digit position decrements by one on each pass from last position to first position

for (int digitPos = creditCardNumber.length(); digitPos > 0; digitPos--)

{

// Checks if digit position is even

if (digitPos % 2 == 0)

{

// Extracts odd digit by converting digit position character to integer

oddDigit = (int) creditCardNumber[digitPos - 1] - '0';

// Calculates sum

sumOdd = sumOdd + oddDigit;

}// End of if condition

// Otherwise odd digit

else

{

// Extracts even digit by converting digit position character to integer

evenDigit = ((int) creditCardNumber[digitPos - 1] - '0') * 2;

evenDigit = evenDigit % 10 + evenDigit / 10;

// Calculates sum

sumEven = sumEven + evenDigit;

}// End of else

}// End of for loop

// Calculates final sum of odd and even sum

finalSum = sumOdd + sumEven;

// Checks if final sum is divisible by 10

if (finalSum % 10 == 0)

{

// Extracts the first digit convert it to integer

int digit = (int)creditCardNumber[0] - '0';

cout<<"\n The credit card number is ";

// Checks if digit is 3 then display American Express

if(digit == 3)

cout<<"valid it belongs to American Express."<<endl;

// Checks if digit is 4 then display Visa

else if(digit == 4)

cout<<"valid it belongs to Visa."<<endl;

// Checks if digit is 5 then display MasterCard

else if(digit == 5)

cout<<"valid it belongs to MasterCard."<<endl;

// Checks if digit is 6 then display Discover Card

else if(digit == 6)

cout<<"valid it belongs to Discover Card."<<endl;

// Otherwise invalid card

else

cout<<"\n The credit card number is in valid."<<endl;

}// End of if condition

// Otherwise final sum is not divisible by 10

else

cout<<"\n The credit card number is in valid."<<endl;

}// End of function

// Function to display menu, accept user choice and return user choice

int menu()

{

// To store user choice

int ch;

// Displays menu

cout<<"\n \t--------------------------------------------------------------";

cout<<"\n \t| Welcome to Online Banking System |";

cout<<"\n \t--------------------------------------------------------------";

cout<<"\n\n 1. Display Account Information";

cout<<"\n 2. Withdraw money";

cout<<"\n 3. Deposit money";

cout<<"\n 4. Verify your Credit Card";

cout<<"\n 5. Quit Application";

// Accept user choice

cout<<"\n Select your Choice:";

cin>>ch;

// Return user choice

return ch;

}// End of function

// main function definition

int main()

{

// To store first, last name, date of birth and email read from file

string firstName, lastName, dob, email;

// To store account number

long long int accNum;

// Tot store current balance

double balance;

// Calls the method to read data from file and store it in respective variable

readFile(firstName, lastName, accNum, dob, email, balance);

// Loops till user choice is not 5

do

{

// Calls the function to accept user choice

// calls appropriate method based on return user choice

switch(menu())

{

case 1:

show(firstName, lastName, accNum, dob, email, balance);

system("pause");

system("cls");

break;

case 2:

withdrawMoney(balance);

system("pause");

system("cls");

break;

case 3:

depositMoney(balance);

system("pause");

system("cls");

break;

case 4:

validCreditCard();

system("pause");

system("cls");

break;

case 5:

exit(0);

break;

default:

cout<<"\n Invalid choice.";

}// End of switch case

}while(1);// End of do - while loop

}// End of main function

Sample Output:

--------------------------------------------------------------

| Welcome to Online Banking System |

--------------------------------------------------------------

1. Display Account Information

2. Withdraw money

3. Deposit money

4. Verify your Credit Card

5. Quit Application

Select your Choice:1

First name: Pyari

Last Name: Sahu

Account Number: 99988811231

Date of Birth: 12/4/2019

Email: pyarimohan@uaeu.ac.in

The balance is: 25000

Press any key to continue . . .

--------------------------------------------------------------

| Welcome to Online Banking System |

--------------------------------------------------------------

1. Display Account Information

2. Withdraw money

3. Deposit money

4. Verify your Credit Card

5. Quit Application

Select your Choice:2

You are about to withdraw from your account...

Your current balance: $25000

Enter withdrawal amount: $-1000

Negative amount not allowed.

You are about to withdraw from your account...

Your current balance: $25000

Enter withdrawal amount: $26000

Overdrawn not allowed.

You are about to withdraw from your account...

Your current balance: $25000

Enter withdrawal amount: $2000

Press any key to continue . . .

--------------------------------------------------------------

| Welcome to Online Banking System |

--------------------------------------------------------------

1. Display Account Information

2. Withdraw money

3. Deposit money

4. Verify your Credit Card

5. Quit Application

Select your Choice:1

First name: Pyari

Last Name: Sahu

Account Number: 99988811231

Date of Birth: 12/4/2019

Email: pyarimohan@uaeu.ac.in

The balance is: 23000

Press any key to continue . . .

--------------------------------------------------------------

| Welcome to Online Banking System |

--------------------------------------------------------------

1. Display Account Information

2. Withdraw money

3. Deposit money

4. Verify your Credit Card

5. Quit Application

Select your Choice:3

You are about to withdraw from your account...

Your current balance: $23000

Enter deposit amount: $-1000

Negative amount not allowed.

You are about to withdraw from your account...

Your current balance: $23000

Enter deposit amount: $1000

Press any key to continue . . .

--------------------------------------------------------------

| Welcome to Online Banking System |

--------------------------------------------------------------

1. Display Account Information

2. Withdraw money

3. Deposit money

4. Verify your Credit Card

5. Quit Application

Select your Choice:4

Enter credit card number: 5278576018410707

The credit card number is valid it belongs to MasterCard.

Press any key to continue . . .

--------------------------------------------------------------

| Welcome to Online Banking System |

--------------------------------------------------------------

1. Display Account Information

2. Withdraw money

3. Deposit money

4. Verify your Credit Card

5. Quit Application

Select your Choice:5

balance.txt file contents

24000

accountInfo.txt file contents

First Name: Pyari

Last Name: Sahu

Account Number: 99988811231

Date of Birth: 12/4/2019

Email: pyarimohan@uaeu.ac.in

Add a comment
Know the answer?
Add Answer to:
Please write c++ (windows) in simple way and show all the steps with the required output
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
  • I want it in C++ 4. When choice 4 (Verify Your Credit Card) is selected, the...

    I want it in C++ 4. When choice 4 (Verify Your Credit Card) is selected, the program should read your credit card (for example: 5278576018410787) and verify whether it is valid or not. In addition, the program must display the type (i.e. name of the company that produced the card). Each credit card must start with a specific digit (starting digit: 1st digit from left to ight), which also is used to detemine the card type according Table 1. Table...

  • Please do it in c++ please show steps as much as possible to help me understand...

    Please do it in c++ please show steps as much as possible to help me understand the code thank you Credit Card error detection check -> Luhn Algorithm, (http://www.freeformatter.com/credit-card-number-generator-validator.html#cardFormats) From the rightmost digit, which is the check digit, moving left, double the value of every second digit; if the product of this doubling operation is greater than 9 (e.g., 7 * 2 = 14), then sum the digits of the products (e.g., 10: 1 + 0 = 1, 14: 1...

  • 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...

  • 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,...

  • Write java program to check that a (16-digit) credit card number is valid. A valid credit...

    Write java program to check that a (16-digit) credit card number is valid. A valid credit card number will yield a result divisible by 10 when you: Form the sum of all digits. Add to that sum every second digit, starting with the second digit from the right. Then add the number of digits in the second step that are greater than four. The result should be divisible by 10. For example, consider the number 4012 8888 8888 1881. The...

  • Please answer in Visual Studio 2019 c# format. Not python. Thank you. Q. Write a program...

    Please answer in Visual Studio 2019 c# format. Not python. Thank you. Q. Write a program that works as described in the following scenario: The user enters a credit card number. The program displays whether the credit card number is valid or invalid. Here are two sample runs: Enter a credit card number as a long integer: 4388576018410707 4388576018410707 is valid Enter a credit card number as a long integer: 4388576018402626 4388576018402626 is invalid To check the validity of the...

  • 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...

  • Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit...

    Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit card number and determines whether it is valid or not. (Much of this assignment is taken from exercise 6.31 in the book) Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits, and must start with: 4 for Visa cards 5 for Master cards 6 for Discover cards 37 for American Express cards The algorithm for determining...

  • The Language is for Java ------ Input ------- credit-cards-2.dat //////////////////// Output//////////// Enter a filename\n Credit card...

    The Language is for Java ------ Input ------- credit-cards-2.dat //////////////////// Output//////////// Enter a filename\n Credit card number: 3056 9309 0259 04\n Checksum: 50\n Card status: VALID\n Credit card number: 3852 0000 0232 37\n Checksum: 40\n Card status: VALID\n Credit card number: 6011 1111 1111 1117\n Checksum: 30\n Card status: VALID\n Credit card number: 6011 0009 9013 9424\n Checksum: 50\n Card status: VALID\n Credit card number: 3530 1113 3330 0000\n Checksum: 40\n Card status: VALID\n Credit card number: 3566 0020 2036...

  • Using the above described algorithm, create a program that: (IN PYTHON) 1.Asks the user which type...

    Using the above described algorithm, create a program that: (IN PYTHON) 1.Asks the user which type of credit card he/she would like to find the checksum for. 2. Based on the user's choice of credit card, asks the user for the n digits of the credit card. [Get the input as a string; it's easier to work with the string, so don't convert to an integer.] 3. Using the user's input of the n digits, finds the last digit of...

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