473,769 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Banking Problem

hi to all,
Please read the following ques. first.

assume that a bank maintains 2 kinds of accounts for
customers one called as
savings accounts & other as current account.
the savings account provides simple interest &
withdraw facilities but no check book facilities.
the current account provides check book facilities but
no interest.
current account holders should also maintain a minimum
balance and if the minimum balance falls below this
level a service charge is to be imposed.

create a class account that stores customers name,
account no & type of account
from this class derive the classes current acc &
savings acc. to make them more
specific to their environments. include necessary
member functions in order to achieve following tasks:
1. accept the deposit from the customer and compute
the balance
2. display the balance
3. compute and deposit the interest
4. permit the withdrawl and update the balance
5. check the minimun balance, impose penalty if
necessary &update the balance

-->>DO NOT USE CONSTRUCTORS AND USE MEMBER FUNCTIONS
TO INITIALIZE THE CLASS MEMBERS

(NOTE: #MAKE AN EXTRA FIELD DATE (INCLUDE DOS.H TO
ACCESS DATE STRUCTURE)
#MAKE THIS PROGRAM BY USING LINK LIST )
The problem i am facing is that when i have created two derived class
as directed, i have to create two linklist to each derived class. So at
the time of modifing, depositing or any other operation, i have to
search both the linklist, which will be very time consuming & if no
such account exist, it would be the worst of the worst case. Then i
think another solution, i make another derived class by taking (saving
& current class) early derived class as base class & create a single
linklist. Now, the problem in that is, when my account is saving type,
my current class in totally untouched(waste d) & vice-versa.
I want to make a single linklist by merging two linklist. Would anyone
suggest me the solution. The program should be Menu Driven.

Thank You

Oct 17 '05
13 2783
"ashu" <as*********@gm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
here, the object of base class can't access the member data & functions
of derived class, as inheritance not work in opposite direction, so
can't help.


Actually, it can. Here is a working program showing how using Run Time Type
Checking (RTTI). Polymorphism would be worthless otherwise.

#include <vector>
#include <iostream>
class Base
{
public:
virtual ~Base() {};
virtual void CommonFunc() = 0;
};

class Derived1 : Base
{
public:
~Derived1(){};
void D1Func() { std::cout << "Derived1" << std::endl; };
void CommonFunc() { std::cout << "Derived1 Common" << std::endl; };
};

class Derived2 : Base
{
public:
~Derived2 () {};
void D2Func() { std::cout << "Derived2" << std::endl; };
void CommonFunc() { std::cout << "Derived2 Common" << std::endl; };
};

int main()
{
std::vector<Bas e*> MyVector;
MyVector.push_b ack( (Base*) new Derived1 );
MyVector.push_b ack( (Base*) new Derived2 );
std::vector<Bas e*>::iterator it;
for ( it = MyVector.begin( ); it != MyVector.end(); ++it )
{
if ( dynamic_cast<De rived1*> (*it) != NULL )
dynamic_cast<De rived1*>(*it)->D1Func();
if ( dynamic_cast<De rived2*> (*it) != NULL )
dynamic_cast<De rived2*>(*it)->D2Func();
(*it)->CommonFunc() ;
}
char wait;
std::cin >> wait;
};

Output is:
Derived1
Derived1 Common
Derived2
Derived2 Common
Oct 20 '05 #11

"Jim Langston" <ta*******@rock etmail.com> wrote in message
news:ov******** *******@fe03.lg a...
"ashu" <as*********@gm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
here, the object of base class can't access the member data & functions
of derived class, as inheritance not work in opposite direction, so
can't help.


Actually, it can. Here is a working program showing how using Run Time
Type Checking (RTTI). Polymorphism would be worthless otherwise.


In addition to what I showed you, you should note that the
(*it).CommonFun c() didn't need to dynamic cast the object, because it would
call the function for whichever object was instatized since it was contained
in the base.

Basically you only have to do a dynamic_cast if you want to call a method
that only exists in a derived object, not the base. If the method exists in
the base just call it and it will use the derived's overriden method (if
there is one).

So if you didn't to use dynamic_casts you could enter "stubs" for all
methods that simply do nothing. Such as:

class Account
{
public:
virtual void CalcInterest() { }; // Default is do nothing
};

class Savings: Account
{
void CalcInterest() { Balace += Balance * 0.014; };
};

class Checking: Account
{
// Checking doesn't override CalcInterest()
};

So now when call:
(*it)->CalcInterest() ;

if the actual instance is Savings, nothing will happen as the base method
will be used which does nothing. If the instance is Checking the Balance
will be updated. Not dynamic_cast needed since the method CalcInterest()
exists in the base class.
Oct 20 '05 #12
Jim Langston wrote:
"ashu" <as*********@gm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
here, the object of base class can't access the member data & functions
of derived class, as inheritance not work in opposite direction, so
can't help.

Actually, it can. Here is a working program showing how using Run Time Type
Checking (RTTI). Polymorphism would be worthless otherwise.


I wouldn't say worthless. In fact, in my current project I use
polymorphism extensively but have RTTI disabled via a compiler switch
because my classes follow the more standard method of design described
by Karl above and don't need it.

#include <vector>
#include <iostream>
class Base
{
public:
virtual ~Base() {};
virtual void CommonFunc() = 0;
};

class Derived1 : Base
{
public:
~Derived1(){};
void D1Func() { std::cout << "Derived1" << std::endl; };
void CommonFunc() { std::cout << "Derived1 Common" << std::endl; };
};

class Derived2 : Base
{
public:
~Derived2 () {};
void D2Func() { std::cout << "Derived2" << std::endl; };
void CommonFunc() { std::cout << "Derived2 Common" << std::endl; };
};

int main()
{
std::vector<Bas e*> MyVector;
MyVector.push_b ack( (Base*) new Derived1 );
MyVector.push_b ack( (Base*) new Derived2 );
std::vector<Bas e*>::iterator it;
for ( it = MyVector.begin( ); it != MyVector.end(); ++it )
{
if ( dynamic_cast<De rived1*> (*it) != NULL )
dynamic_cast<De rived1*>(*it)->D1Func();
Better would be:

if( Derived1* p = dynamic_cast<De rived1*>(*it) )
{
p->D1Func();
}

Then, at least there's only one call to the non-trivial dynamic_cast.
if ( dynamic_cast<De rived2*> (*it) != NULL )
dynamic_cast<De rived2*>(*it)->D2Func();
(*it)->CommonFunc() ;
}
char wait;
std::cin >> wait;
};

Output is:
Derived1
Derived1 Common
Derived2
Derived2 Common


Cheers! --M

Oct 20 '05 #13

"mlimber" <ml*****@gmail. com> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
Jim Langston wrote:
"ashu" <as*********@gm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
> here, the object of base class can't access the member data & functions
> of derived class, as inheritance not work in opposite direction, so
> can't help.
>


Actually, it can. Here is a working program showing how using Run Time
Type
Checking (RTTI). Polymorphism would be worthless otherwise.


I wouldn't say worthless. In fact, in my current project I use
polymorphism extensively but have RTTI disabled via a compiler switch
because my classes follow the more standard method of design described
by Karl above and don't need it.


Actually, my "Polymorphi sm would be worthless otherwise" was refering to the
fact that the member data & functions can be assess through a base pointer,
not to RTII. I had added the last sentance as an afterthough. Switch
sentances 2 and 3 around and it what I meant to say :D (IOW, I agree with
you)

if ( dynamic_cast<De rived1*> (*it) != NULL )
dynamic_cast<De rived1*>(*it)->D1Func();


Better would be:

if( Derived1* p = dynamic_cast<De rived1*>(*it) )
{
p->D1Func();
}

Then, at least there's only one call to the non-trivial dynamic_cast.


Agreed.
Oct 21 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

117
7265
by: Peter Olcott | last post by:
www.halting-problem.com
3
5470
by: mazubair | last post by:
I am going to develop a Banking Solution for very small branches of a Bank. The branches are standalone and no remote transactions will be made i.e. only the individual branch will be under networking and there will be no networking between the branches. The branches have maximum 10000 (ten thousand) customer accounts, maximum 200 daily (60000 yearly) transactions and maximum 3 to 4 concurrent users. The solution will provide voucher...
2
2292
by: mazubair | last post by:
I am going to develop a Banking Solution for very small branches of a Bank. The branches are standalone and no remote transactions will be made i.e. only the individual branch will be under networking and there will be no networking between the branches. The branches have maximum 10000 (ten thousand) customer accounts, maximum 200 daily transactions (120000 yearly including processed transactions i.e. interest, charges etc.) and maximum 3...
0
372
by: jason1551 | last post by:
I'm working on a program that will compute interest on a savings account. The interest is compounded monthly for 30 years, and a desposit is made on the account at the beginning of each year. My problem is that my C++ skills are pretty limited, and this needs to be done within a few days. I've figured out a basic structure, but need help understanding what is and what is not working. Here's what I've got so far: #include <iostream>...
11
6657
by: cj | last post by:
Lets assume all calculations are done with decimal data types so things are as precise as possible. When it comes to the final rounding to cut a check to pay dividends for example in VB rounding seems to be done like this 3.435 = 3.44 3.445 = 3.44 Dim decNbr1 As Decimal
2
1114
by: =?Utf-8?B?V2F5bmU=?= | last post by:
Been using Money 2005 without problem until recent. Suddenly, I can no longer add new banking accounts even though I only have 10 or 11 existing accounts. When I click on "add new account" , it goes to the page titled "choose acct. type" but goes into a "frozen" state with the "time out" hour glass showing and stays that way forever. I then have to click on the "stop loading" icon to get out. Any ideas? Thanks.
5
4483
by: Jervin | last post by:
Project Requirements The key elements of the project are that the project: • Needs a database support. • Have rather well defined functions with certain degree of complexity. Implementation Requirement (Functional System)
1
1037
by: =?Utf-8?B?Umlja1JTQkFFbnRlcnByaXNl?= | last post by:
I am having trouble downloading my banking transactions from Wachovia Bank. The only way a business can download is thru MS Money. Can anyone tell me how they get there transactions from Wachovia?
2
2143
by: anasanjaria | last post by:
I m working on my project, its based on a banking application. What i basically does is send bank account owners an sms after every transaction made to their account. This is to prevent fraud so if, for example, i have a credit card, and someone uses my card ill get an SMS saying where and for how much the card was used after the transaction has been made, that way ill know if any fraud has been commited and i can report it directly to the bank....
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.