C# Program that Defines a Class to Represent a bank account which includes the following Member
Object:
Define a class to represent a bank account which includes the subsequent members:
Data members:
1. Name of the depositor
2. Account Number
3. Withdraw amount
4. Balance amount in the account
Member Functions:
1. To assign initial values
2. To deposit an amount
3. To withdraw amount after checking the balance
4. To display name and balance. C# Projects with Source Code
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace oop3
{
class bank
{
private double balance = 100000;
public double bal
{
get { return balance;}
set { balance = value; }
}
}
class fuctions
{
bank i = new bank();
string name;
int account;
double withdraw, dep,tobal;
public void fun1()
{
Console.WriteLine(“Enter Name of the depositor :”);
name = Console.ReadLine();
Console.WriteLine(“Enter Account Number :”);
account = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(“Enter Deposit Amount :”);
dep = Convert.ToDouble(Console.ReadLine());
tobal = i.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 fun2()
{
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 <= i.bal)
{
tobal = i.bal – withdraw;
Console.WriteLine(“——————————\n”);
Console.WriteLine(“Account Name : ” + name);
Console.WriteLine(“Account Number: ” + account);
Console.WriteLine(“After Withdraw Amount balnace is : ” + tobal);
}
else
Console.WriteLine(“\n\nWithdraw Ammount does not Exist your Account.”);
}
}
class Program
{
static void Main(string[] args)
{
char agn;
do
{
fuctions k = new fuctions();
int num;
Console.WriteLine(“Please Select Any Function.”);
Console.WriteLine(“\nPress 1 for Deposit an Amount. \nPress 2 for Withdraw an Amount.”);
num = Convert.ToInt32(Console.ReadLine());
switch (num)
{
case 1:
k.fun1();
break;
case 2:
k.fun2();
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();
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace oop3 { class bank { private double balance = 100000; public double bal { get { return balance;} set { balance = value; } } } class fuctions { bank i = new bank(); string name; int account; double withdraw, dep,tobal; public void fun1() { Console.WriteLine("Enter Name of the depositor :"); name = Console.ReadLine(); Console.WriteLine("Enter Account Number :"); account = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Deposit Amount :"); dep = Convert.ToDouble(Console.ReadLine()); tobal = i.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 fun2() { 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 <= i.bal) { tobal = i.bal - withdraw; Console.WriteLine("------------------------------\n"); Console.WriteLine("Account Name : " + name); Console.WriteLine("Account Number: " + account); Console.WriteLine("After Withdraw Amount balnace is : " + tobal); } else Console.WriteLine("\n\nWithdraw Ammount does not Exist your Account."); } } class Program { static void Main(string[] args) { char agn; do { fuctions k = new fuctions(); int num; Console.WriteLine("Please Select Any Function."); Console.WriteLine("\nPress 1 for Deposit an Amount. \nPress 2 for Withdraw an Amount."); num = Convert.ToInt32(Console.ReadLine()); switch (num) { case 1: k.fun1(); break; case 2: k.fun2(); 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:
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 to count vowels in a string
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
Pingback: C# Program Create an inheritance hierarchy that a bank might use to represent the customer's bank accounts.
Pingback: Top 20 C# programs examples in 2021