Algorithm for the following homework

You need an algorithm for reading on one balance of the client’s account at the beginning of the month, in total all withdrawals per month, as well as all deposits made during the month. A federal fee of 1% applies to all transactions completed within a month. The program should calculate the account balance at the end of the month by (1) subtracting the total withdrawal from the account balance at the beginning of the month, (2) adding all deposits to the new balance sheet, (3) calculating the federal tax (1% of the total transaction amount, i.e. e. Total withdrawal + amount of deposits) and (4) deduction of this federal tax from the new balance. After these calculations, print the final balance of the end of the month.

+3
source share
3 answers

This will be a simple translation into pseudocode. Since this is homework, you will have to deal with legalization yourself. Just evaluate each step in turn:

input: accountBalanceStart, totalDeposits, totalWithdrawals
output: accountBalanceEnd

Take the first step:

accountBalanceEnd <-- accountBalanceStart - totalWithdrawals

Now the second:

accountBalanceEnd <-- accountBalanceEnd + totalDeposits

Then calculate the tax and subtract it:

accountBalanceEnd <-- accountBalanceEnd - (totalWithdrawals + totalDeposits) * 0.01

Finally, show the result:

print accountBalanceEnd
+1
source

This is the problem of homework at www.palinfonet.com/hw_java2008.pdf, due on April 17, 2008, issue No. 3.

0
source

, , . , , .

, , :

PL/SQL

SQL Quickref

, , - . , mssql.

    CREATE OR REPLACE FUNCTION Calculate_Balance(account_id long, account_balance float, date datetime) RETURNS float AS
    DECLARE
    transactions_sum float;
    fed_tax float;
    new_account_balance float;              
BEGIN
    transactions_sum = SELECT SUM(amount) from transactions 
        WHERE transactions.account_id = account_id 
        AND month(transactions.date) = month(date) 
        AND year(transactions.date) = year(date);

    fed_tax = transactions_sum * 0,01;
    transactions_sum = transactions_sum - fed_tax;
    new_account_balance = transactions_sum + account_balance;

    RETURN new_account_balance;
END;            
0

Source: https://habr.com/ru/post/1704790/


All Articles