473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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(wasted) & 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 #1
13 2746
ashu wrote:
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(wasted) & 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


See this FAQ:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

This newsgroup is for C++ language questions. If you have a specific
language-related question, we will be happy to help you. Otherwise, you
might want to try in comp.programming or
comp.please.do.my.homework.for.me.

Cheer! --M

Oct 17 '05 #2
mlimber wrote:
ashu wrote: [snip]
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(wasted) & 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.

[snip] This newsgroup is for C++ language questions. If you have a specific
language-related question, we will be happy to help you. Otherwise, you
might want to try in comp.programming or
comp.please.do.my.homework.for.me.


Don't be so eager to dismiss this as off topic. Actually, there is a
language question in there: given two classes, deriving from a common base,
does C++ have a mechanism to have objects of both types in the same
container. If so, what is the recommended was to go about it?

And a possible answer is: you can use a container of pointers to the base
class. Better even, use a container of reference counting smart_pointers to
the base class so that memory management is still automatic.

To the OP: this should get you started. Post again when you have a draft of
your code and you are running into more serious problems. Also, please do
not roll your own code for the linked list. Use std::list<> instead. It
will save you serious headache.
Best

Kai-Uwe Bux
Oct 17 '05 #3
Thank you for considering my problem & guiding me so well. As i'm new
to the Oops, i not know much about Oops. So would you please tell me
what are containers of pointers, container of reference counting
smart_pointers???.

And "please do not roll your own code for the linked list. Use
std::list<> instead" ????? what does this line means. please tell me.

Oct 17 '05 #4
ashu wrote:
Thank you for considering my problem & guiding me so well. As i'm new
to the Oops, i not know much about Oops. So would you please tell me
what are containers of pointers, container of reference counting
smart_pointers???.
Rather than have one of us explain it, I suggest picking up a good C++
book (or two) and reading it. IIRC, the FAQ has several good
recommendations.
And "please do not roll your own code for the linked list. Use
std::list<> instead" ????? what does this line means. please tell me.


It means that you should use the list class provided by the Standard
Library instead of writing your own.

Kristo

Oct 17 '05 #5
"ashu" writes:
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(wasted) & 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.


First of all, a linked list is a very bad data structure for this problem,
it will be terribly slow and no reasonable amount of cleverness is going to
change that. That *might* be the point your instructor is trying to make.
He specifies you are not to use a meaningful constructor, and this is a
prelude to an obvious array solution, using hashing. Then, for a subsequent
assignment he has you already motivated for a better data structure.

I don't really understand everything you said, I suspect there is an English
problem. You seem to focus on the worst case, a customer who claims to have
an account in fact doesn't have one. Are you proposing three lists? And
some way to get the "customer" to answer some question or other truthfully?
Oct 18 '05 #6

"osmium" <r1********@comcast.net> schrieb im Newsbeitrag
news:3r************@individual.net...

That *might* be the point your instructor is trying to make.


I think the point his instructor is trying to make is an exercise
on how to use a polymorphic class in a container (plus an exercise
in constructing a linked list, if he has to code the list by hand).

Never forget: This are class room assignments, not real world
applications.

--
Karl Heinz Buchegger
Oct 18 '05 #7
"ashu" <as*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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(wasted) & 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.


Maybe this will get you started:

class Base
{
public:
virtual ~Base() {};
};

class Derived1 : Base
{
public:
~Derived1(){};
};

class Derived2 : Base
{
public:
~Derived2 () {};
};

int main()
{
Base* baseP1;
Base* baseP2;
baseP2 = new Derived1;
baseP2 = new Derived2;
};

What I'm showing here is that a base pointer can point to a derived object.
So a linked list of base objects can point to any derived objects of base.

Read your textbook on this.
Oct 19 '05 #8
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.

Oct 19 '05 #9
ashu wrote:

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.


Right. But the base class should not access all of this.

All your base class needs to do is:
make available a couple of virtual functions, which are
implemented in the derived classes.

Eg. The base class introduces functions for handling
of check books. In the 'current account' class, these
functions are fully implemented, while in the 'savings account'
class they are do-nothing-functions (or not implemented at all).

Virtual functions, paired with inheritance is the key to your
assignment!

--
Karl Heinz Buchegger
kb******@gascad.at
Oct 19 '05 #10
"ashu" <as*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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<Base*> MyVector;
MyVector.push_back( (Base*) new Derived1 );
MyVector.push_back( (Base*) new Derived2 );
std::vector<Base*>::iterator it;
for ( it = MyVector.begin(); it != MyVector.end(); ++it )
{
if ( dynamic_cast<Derived1*> (*it) != NULL )
dynamic_cast<Derived1*>(*it)->D1Func();
if ( dynamic_cast<Derived2*> (*it) != NULL )
dynamic_cast<Derived2*>(*it)->D2Func();
(*it)->CommonFunc();
}
char wait;
std::cin >> wait;
};

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

"Jim Langston" <ta*******@rocketmail.com> wrote in message
news:ov***************@fe03.lga...
"ashu" <as*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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).CommonFunc() 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*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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<Base*> MyVector;
MyVector.push_back( (Base*) new Derived1 );
MyVector.push_back( (Base*) new Derived2 );
std::vector<Base*>::iterator it;
for ( it = MyVector.begin(); it != MyVector.end(); ++it )
{
if ( dynamic_cast<Derived1*> (*it) != NULL )
dynamic_cast<Derived1*>(*it)->D1Func();
Better would be:

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

Then, at least there's only one call to the non-trivial dynamic_cast.
if ( dynamic_cast<Derived2*> (*it) != NULL )
dynamic_cast<Derived2*>(*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*********************@g49g2000cwa.googlegro ups.com...
Jim Langston wrote:
"ashu" <as*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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 "Polymorphism 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<Derived1*> (*it) != NULL )
dynamic_cast<Derived1*>(*it)->D1Func();


Better would be:

if( Derived1* p = dynamic_cast<Derived1*>(*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
by: Peter Olcott | last post by:
www.halting-problem.com
3
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...
2
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...
0
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...
11
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...
2
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...
5
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. ...
1
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
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,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.