


#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
Please write c++ (windows) in simple way and show all the steps with the required output
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 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 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 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 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 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 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 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 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 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...