C# Program Create an inheritance hierarchy that a bank might use to represent the customer’s bank accounts.

C# Program Create an inheritance hierarchy that a bank might use to represent the customer’s bank accounts.

C# Program Create an inheritance hierarchy that a bank might use to represent the customer's bank accounts.

Object:

C# Program Create an inheritance hierarchy that a bank might use to represent customer’s bank accounts. All customers at this bank can deposit money into their accounts and withdraw money from their accounts. More specific kinds of accounts also exist. Savings accounts, as an example, earn interest on the cash they hold. Checking accounts, on the opposite hand, charge a fee per transaction (i.e., credit or debit).

Create base class Account and derived classes Savings-Account and a bank account that inherit from class Account. Base class Account should include

  • Data member account balance (double)
  • Member function credit should add an amount to this balance.
  • Member function debit should withdraw money from the Account and make sure that the debit amount doesn’t exceed the Account’s balance. If it does, the balance should be left unchanged and therefore the function should print the message “Debit amount exceeded account balance.”

Derived class SavingsAccount should inherit Account, include

  • A data member rate of interest (percentage) assigned to the Account.
  • Function calculate_Interest that returns a double indicating the quantity of interest earned by an account.
    (Member function calculate_interest should determine this amount by multiplying the rate of interest by the account balance)

Derived class CheckingAccount should inherit Account and include

  • An data member of type double that represents the fee charged per transaction.
  • Member functions credit and debit in order that they subtract the fee from the account balance whenever either transaction is performed successfully.
  • CheckingAccount’s versions of those functions should invoke the base-class Account version to perform the updates to an account balance.
  • CheckingAccount’s debit function should charge a fee as long as money is really withdrawn (i.e., the debit amount doesn’t exceed the account balance). C# Projects with Source Code

Code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace codeboks

{

    class Account

    {

        private double balance = 100000;

        public double bal

        {

            get { return balance; }

            set { balance = value; }

        }

        public string name;

        public double account, final_Amt;

        public double withdraw, dep, tobal;

        public void credit()

        {

            Console.WriteLine(“Enter Name of the depositor :”);

            name = Console.ReadLine();

            Console.WriteLine(“Enter Account Number  :”);

            account = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine(“Enter Credit Amount :”);

            dep = Convert.ToDouble(Console.ReadLine());

            tobal = bal + dep;

            Console.WriteLine(“——————————\n”);

            Console.WriteLine(“Name of the depositor : ” + name);

            Console.WriteLine(“Account Number: ” + account);

            Console.WriteLine(“Total Balance amount in the account  : ” + tobal);

        }

        public void debit()

        {

            Console.WriteLine(“Enter Account Name :”);

            name = Console.ReadLine();

            Console.WriteLine(“Enter Account Number  :”);

            account = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine(“Enter Withdraw Amount :”);

            withdraw = Convert.ToDouble(Console.ReadLine());

            if (withdraw <= bal)

            {

                tobal = bal – withdraw;

                Console.WriteLine(“——————————\n”);

                Console.WriteLine(“Account Name : ” + name);

                Console.WriteLine(“Account Number: ” + account);

                Console.WriteLine(“After Withdraw balnace Amount is : ” + tobal);

            }

            else

                Console.WriteLine(“\n\nWithdraw Ammount does not Exist your Account.”);

        }

    }

    class Saving_Account : Account

    {

        double interest_rate, rate;

        public void calculateintrest()

        {

            interest_rate = 0.02;

            //calculation

            rate = tobal * (interest_rate / 100);

            final_Amt = tobal + rate;

            Console.WriteLine(“Total Balance Amount with Interest : ” + final_Amt);

        }

    }

    class CheckingAccount : Saving_Account

    {

        double fee_per = 15;

        public void fee()

        {

            Console.WriteLine(“Balance After Transection Charges : ” + (tobal – fee_per));

        }

    }

    class Program

    {

        static void Main(string[] args)

        {

            char agn;

            do

            {

                CheckingAccount i = new CheckingAccount();

                int num;

                Console.WriteLine(“Please Select Any Function.”);

                Console.WriteLine(“\nPress 1 for Credit an Amount. \nPress 2 for debit an Amount.”);

                num = Convert.ToInt32(Console.ReadLine());

                switch (num)

                {

                    case 1:

                        i.credit();

                        i.calculateintrest();

                        break;

                    case 2:

                        i.debit();

                        i.fee();

                        break;

                    default:

                        Console.WriteLine(“Invalid Selection!!!”);

                        break;

                }

                Console.WriteLine(“\nDo you want to continue this program? (y/n)”);

                agn = Convert.ToChar(Console.ReadLine());

            } while (agn == ‘y’);

            Console.ReadKey();

        }

    }

}

Output:

C# Program Create an inheritance hierarchy that a bank might use to represent the customer's bank accounts. C# Program Create an inheritance hierarchy that a bank might use to represent the customer's bank accounts.

Another C# Program: C# Program Calculating the Area of a Rectangle

Another C# Program: C# Program that Subtracts two user-defined numbers

Another C# Program: C# Program Create a class student with a data members name and calculate marks and percentage.

Another C# Program: C# program to count vowels in a string

Another Program: Write a C# program to create a static function factorial and calculate factorial of the number.

Another Program: Write a C# program that reads two arrays and checks whether they are equal.

Another Program: Develop a C# app that will determine the gross pay for each of three employees

M.A Siddiqui

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *