Topic: C++ Constructors in Derived Classes (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=28616" title="Pages that link to Topic: C++  Constructors in Derived Classes (Page 1 of 1)" rel="nofollow" >Topic: C++  Constructors in Derived Classes <span class="small">(Page 1 of 1)</span>\

 
binary
Paranoid (IV) Inmate

From: Under the Bridge
Insane since: Nov 2002

posted posted 11-07-2006 12:36

Hi All.... any Guru expert out there...i have the follwing scenario below...and am seeking help from anyone able come up with this small code in C++......

base class BankAccount with derived classes SavingsAccount and ChequeAccount

BankAccount attributes :-
account_number
holder
start_balance

SavingsAccount attributes
withdrawal_notice
intrest_rate
methods to return this attribues

ChequeAccount attributes
allowed overdraft
method to return the value

In both cases initial values of additional attributes should be set using parameters to the constructor

I need to explicitly inherit the parameters from the base class constructor in the base class constructor in the defination of both of derived class constructor

I also need to instantiate an object of SavingsAccount class and set the constructor parameters to:-
start_balance= $1000
withdrawal_notice = 30 days
intrest_rate = 3.5%
account_number = 1
holder = "binary"

I also need to instantiate an object of ChequeAccount class and set the constructor parameters to:-
start_balance = $0.00
overdraft_limit = $500
account_number = 2
holder = " principle"

Lastly i need to display the details of both savings account and cheque account object...

[/i]pls help me to came up a code in C++ to do the above[i]

~Sig coming soon~

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana
Insane since: Aug 2000

posted posted 11-07-2006 17:18

Is this a homework assignment?

What have you done so far to implement these requirements?

.



-- not necessarily stoned... just beautiful.

binary
Paranoid (IV) Inmate

From: Under the Bridge
Insane since: Nov 2002

posted posted 11-08-2006 13:25
code:
#include <iostream.h>
class BankAccount
{
	protected:
        	int account_number;
	        char holder [30];
	        float start_balance;
	public:
		BankAccount( int act_no,char* holdr,float stb)
		{
			account_number = act_no;
			strcpy(holder,holdr);
			start_balance = stb;
		}
		void display()
		{
			cout<<" Account Number ="<<account_number<<endl;
			cout<<" Holder ="<<holder<<endl;
			cout<<" Start Balance ="<<start_balance<<endl;
		}
};

class SavingAccount : public BankAccount
{
	private:
		int withdrawal_notice;
		float intrest_rate;
	public:
		SavingAccount(int acct_no,char* hldr,float sb,int with_ntc,float int_rt):BankAccount(acct_no,hldr,sb)
		{
			withdrawal_notice = with_ntc;
			intrest_rate = int_rt;
		}
		void show()
		{
			cout<<"Withdrawal Notice ="<<withdrawal_notice<<endl;
			cout<<"Intrest Rate"<<intrest_rate<<endl;
		}
}


hyperbole:- this is what i have so far....but am stuck at this point...wouldnt mind your help here...

~Sig coming soon~

(Edited by binary on 11-08-2006 13:28)

Edit Tyberius Prime : Some code tags and a little bit of indention to make the code more readable...

(Edited by Tyberius Prime on 11-08-2006 21:28)

binary
Paranoid (IV) Inmate

From: Under the Bridge
Insane since: Nov 2002

posted posted 11-08-2006 14:08

Hey is there no C++ Guru here....or is the problem that hard...

~Sig coming soon~

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana
Insane since: Aug 2000

posted posted 11-08-2006 18:35

O.K. That's a start. You still need to declare the ChequeAccount class. You would do it in a similar way to the way you've declared the SavingAccount class. Then write a small main function to instantiate the two classes with the parameters your problem specifies.

After you've written the additional class and main function, re-read the assignment to make sure you've included all the items the original problem specified.

Then compile and test the whole program.

.



-- not necessarily stoned... just beautiful.

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 11-08-2006 21:33

As far as I read it you're pretty good to go, sorry for not replying earlier, I have this amazingly facinating problem here on my desk
*shiny eyes*...

All you need is a

code:
SavingsAccount sampleSavingsAccount = new SavingsAccount ( whatever your defined parameters were ) ;



and of course the things hyperbole pointed out.

On a side node:
Your Bankaccount constructer is a buffer overflow waiting to happen.
I advice against using raw char*, think about using CString instead.
At the very least make that a strncpy(holder,holdr,29); /* Don't forget the terminating 0, and boy those variable names suck... */

So long,

->Tyberius Prime

binary
Paranoid (IV) Inmate

From: Under the Bridge
Insane since: Nov 2002

posted posted 11-09-2006 07:54

Done.

But got some strange results and the deadline was today. I guess i cant expect to get everything

Thanks hyper and TP for your help

~Sig coming soon~



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu