n the case of a deposit, the server should increment the bank account’s balance
ID: 3782893 • Letter: N
Question
n the case of a deposit, the server should increment the bank account’s balance field by the deposit amount and then return a message to the client stating the new balance. In the case of a withdrawal, assuming sufficient funds exist, the server should decrement the bank account’s balance field by the withdrawal amount and then return a message to the client stating the new balance. If sufficient funds do not exist to cover the withdrawal amount, then the server should return a message to the client indicating this. In the case of “Balance,” the server should simply respond to the client with the balance of the account. In all cases, the socket should be closed immediately after the transaction is complete.
Can someone help? I'm new to this. Thanks
Directions: The following programming assignment should be completed in Cor C++ using the standard socket libraries that come with your operating system. It is highly recommended that you complete this assignment in Unix/Linux as this is what will be utilized in the solutions (and is also what is used in the textbook). If you are using a Windows machine, then I highly recommend installing Cygwin, which is a utility that allows you to run Linux on top of Windows not the fasting thing in the world, but it will get the job done 1.Write a server application that represents an online banking utility. Let your server maintain an array of"bank accounts," which will be objects of the following struct type struct bank account int acct num char password[8] max password length is 8 characters double balance You should create a set of 3 or 4 test accounts with made-up values to populate this array Your application should use a server socket to listen in to incoming client connections. As soon as a client ogs on, it should present the client with the following prompt Welcome to [Choose A Namel Bank: Please enter an account number: After an account number is received from the client through the socket connection, the server program should check ifthe corresponding bank account exists. If not, return an error message to the client and close the connection. If the account does exist, then present the client with the following prompt Please enter password The server program should then wait until the client responds with a password. Once this occurs, the servershould validate the password. Ifthe password is incorrect, return an error to the client and close the connection. If the password is correct, then present the client with the following prompt: Please enter a transaction: The server program should then expect a command o on the following forms This deposits $123.45 into the selected account Deposit 123.45 This withdraws $98.76 from the account (if the amount is available) Withdraw 98.76 This displays the balance BalanceExplanation / Answer
class Account {
double balance;
double add(double sum) {
balance += sum;
return sum;
}
double withdraw(double sum) {
if (sum > balance) {
balance -= 5;
return -5; // this will come in handy in Prob. 6
} else {
balance -= sum;
return balance; // Notice: always >= 0 (never < 0)
}
}
double inquire() { return balance; }
Account() { balance = 0; }
Account(double sum) { balance = sum; }
double interest (double rate) {
return rate * balance;
}
}
Implement four instance methods:
deposit(double amount, String account)
withdraw(double amount, String account)
transfer(double amount, String account)
printBalances()
For the deposit or withdrawal, it indicates which account is affected. For a transfer it indicates the account from which the money is taken; the money is automatically transferred to the other account.
class Bank {
Account checking;
Account savings;
void deposit(double amount, String account) {
if (account.equals("C")) checking.add(amount);
else // my default
savings.add(amount);
}
void withdraw(double amount, String account) {
if (account.equals("C")) checking.withdraw(amount);
else // my default
savings.withdraw(amount);
}
void transfer (double amount, String account) {
if (account.equals("C"))
if (checking.withdraw(amount) >= 0)
savings.add(amount);
else checking.add(5); // somewhat fault-tolerant
else // default
if (savings.withdraw(amount) >= 0)
checking.add(amount);
else savings.add(5); // no penalty for transfers
}
void printBalances() {
System.out.println(
"Checking: " + checking.inquire() +
" Savings: " + savings.inquire()
);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.