Earn in Dollars

PaidVerts

Semester: Fall 2014
CS304: Object Oriented Programming
Due Date: 08/12/2014
Total Marks: 20
Instructions:
Please read the following instructions carefully before submitting assignment. It should be clear that your assignment will not get any credit if:
  • The assignment is submitted after due date.
  • The submitted assignment does not open or file is corrupt.
  • Assignment is copied(partial or full) from any source (websites, forums, students, etc)

Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks. For example, if you submit code in .doc (Microsoft Word Document) or .txt files or .exe file, no reward will be given in any case.

Objective:

The objective of this assignment is to provide hands on experience of:

  • Relationships among classes
  • Constructors
  • Constructor overloading
  • Getter and Setter functions
Guidelines:

  • Code should be properly indented and well commented.
  • Follow C/C++ guide lines while writing variable names, function names etc
  • Use only dev-C++ for this assignment.

Assignment  


Problem Statement:  
  
In this assignment you will be modeling a part of simple banking system. In this system, there are two classes, Customer and Account which are related to each other via aggregation relationship.

Account class has the following data members:
  • Account No.
  • Current Balance
  • Bank name
  • Branch code

Account class must have the following member functions:

Function
Description
Account()
Default constructor for account class, setting account balance to 0, Account number to 1, branch name to NULL and branch code to 0
Account(float, int, char *, int)
It will take balance,  account no, bank name and branch code as arguments and set their values accordingly
withdraw(float)
This will subtract amount from the balance of account that will be passed as its parameter.
If the amount being withdrawn is greater the balance of the account , it will display the message “Insufficient balance”
deposit(float)
Function will add amount to the balance of account. Amount will be passed as its parameter.
getBalance()
This function will return the value of available balance
getAccountNo()
This function will return the account number
getBankName()
This function will return the name of bank
getBrachCode()
This function will return branch code of bank

Customer class has the following data members:
  • Customer Name
  • Address
  • Account object

Customer class must have the following member functions:

Function
Description
display()
This function will display the values of all data members of Customer and Account class
Parameterized constructor
It will take Account, name and address as a arguments and set their values accordingly


Within main() function, objects of both classes will be created , and respective member functions of these objects will be called.

First of all create an object of Account class by passing balance, account number, bank name and branch code. Then create an object of customer class by passing Account object, name and address. Now call display() function which will display all the values of Customer including his/her name, address and account detail.

The program should prompt the user to enter a value and call deposit() function passing it entered value. Then call the display() function.

 After this, the program should prompt the user to enter a value and call withdraw() function passing it entered value. Then call the display() function.

 Sample output of the program:
  

BEST OF LUCK!

Solution

#include <iostream.h>
using namespace std;
// Account Class Declaration and Definition 
class account{
private:
int accountNo;
float balance;
string bankName;
int b_code;
public:
account(){ // Default Constructor 
accountNo=00;
balance=0.0;
bankName="Default";
b_code=00; 
} // End of Default Constructor

account(int ac_num, float bal, string b_name, int code){ // Parametarized Constructor
accountNo=ac_num;
balance=bal;
bankName=b_name;
b_code= code;
} // End Parametarized Constructor

void withdraw(float draw_money){ // WithDrawl Func
if (balance<draw_money){
cout "\n\a \"Insufficient balance.......\""; 
}
else{
balance-=draw_money;
}
} // End of WithDrawl Func

void deposit(float add_money){ // Deposit Func
balance+=add_money; 
}
// And other some self explanatory Function of Account Class
float getBalance(){
return balance;
}
int getAccountNo(){
return accountNo; 
}
string getBankName(){
return bankName; 
}
int getBrachCode(){
return b_code; 
}; // End of Account Class
class customer{
private:
string name;
string address; 
public:
account ac; // public because it is represented as public in class diagram
customer(string n, string a, account acc){ // Parametarized Constructor
name= n;
address=a;
ac=acc;
} // End of Parametarized Constructor

void display(){
cout "\n Customer Name: "name;
cout "\n Customer Address: "address;
cout "\n Bank Name: "ac.getBankName();
cout "\n Branch Code: "ac.getBrachCode();
cout "\n Current Balance: "ac.getBalance();
cout "\n Account No. "ac.getAccountNo(); 
}
}; // End of Customer Class

main(){
cout "..........Displaying Customer Account Information........."endlendl;
account myaccount(7812, 40000, "Askari Bank", 123); // Creating an account Obj
customer DD("Double Diamond", "Programming Island", myaccount); // Creating an customer Obj
DD.display();

float dep, draw;
cout "\n\n Please Enter a value for Deposit: ";
cin >> dep;
DD.ac.deposit(dep);
cout "\n\n Current Balance after Depositing...";
DD.display();

cout "\n\n Please Enter a value for Withdrawl: ";
cin >> draw;
DD.ac.withdraw(draw);
cout "\n\n Current Balance after withdrawing...";
DD.display();
cout endlendl; 
system("pause"); 
}
/*
This is an Example Solution Don't copy Paste it......
Any Problem can be solved with Different Logic and styles
So Try to Make your OWN....



 
Top