Single Inheritence

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

Account inheritance hericharey

#ifndef ACCOUNT_H

#define ACCOUNT_H

using namespace std;

class Account

public:

Account(double);

void credit(double);

float debit(double);

void setbalance(double);

double getbalance();

private:

double balance;

};

#endif

#include"Account.h"

#include<iostream>

using namespace std;

Account::Account(double initialbalance)

if(initialbalance>=0)

balance=initialbalance;
}

else

cout<<"Initial balance can not be negative";

void Account::credit(double amount)

balance=balance+amount;

float Account::debit(double amount)

if(amount>balance)

cout<<"Debit amount exceede account balance"<<endl;

return false;

else

balance=balance-amount;

return true;

void Account::setbalance(double newbalance)

balance=newbalance;

double Account::getbalance()

{
return balance;

#ifndef SAVINGS_H

#define SAVINGS_H

#include"Account.h"

using namespace std;

class SavingsAccount:public Account

public:

SavingsAccount(double,double);

double calculatefloaterest();

private:

double floaterestrate;

};

#endif

#include"SavingsAccount.h"

#include<iostream>

using namespace std;

SavingsAccount::SavingsAccount(double initialbalance,double rate):Account(initialbalance)

if(rate>=0)

floaterestrate=rate;
}

else

cout<<"floaterest rate must be greater than or equal to zero";

double SavingsAccount::calculatefloaterest()

return (getbalance()*floaterestrate);

#ifndef CHECKING_H

#define CHECKING_H

#include"Account.h"

#include"SavingsAccount.h"

using namespace std;

class CheckingAccount:public Account

public:

CheckingAccount(double,double);

void credit(double);

float debit(double);

private:

double transactionfee;

void chargefee();

};

#endif
#include"CheckingAccount.h"

#include<iostream>

using namespace std;

CheckingAccount::CheckingAccount(double initialbalance, double fee):Account(initialbalance)

if(fee>=0)

transactionfee=fee;

else

cout<<"Transaction fee must be greater than 0";

void CheckingAccount::credit(double amount)

Account::credit(amount);

chargefee();

float CheckingAccount::debit(double amount)

float success=Account::debit(amount);

if(success)

chargefee();

return true;
}

else

return false;

void CheckingAccount::chargefee()

Account::setbalance(getbalance()- transactionfee);

cout<<"$"<<transactionfee<<"transaction fee charged"<<endl;

#include"Account.h"

#include"SavingsAccount.h"

#include"CheckingAccount.h"

#include<iostream>

#include<iomanip>

using namespace std;

int main()

Account account1(50.0);

SavingsAccount account2(25.0,0.03);

CheckingAccount account3(80.0,1.0);

cout<<fixed<<setprecision(2);

cout<<"Account1 balance $"<<account1.getbalance()<<endl;

cout<<"Account2 balance $"<<account2.getbalance()<<endl;

cout<<"Account3 balance $"<<account3.getbalance()<<endl;


cout<<"\nAttempting to debit $25.00 from account1"<<endl;

account1.debit(25.0);

cout<<"\nAttempting to debit $30.00 from account2"<<endl;

account2.debit(30.0);

cout<<"\nAttempting to debit $40.00 from account 3"<<endl;

account3.debit(40.0);

cout<<"\nAccount1 balance $"<<account1.getbalance()<<endl;

cout<<"\nAccount2 balance $"<<account2.getbalance()<<endl;

cout<<"\nAccount3 balance $"<<account3.getbalance()<<endl;

cout<<"\nCrediting $40.00 to account1";

account1.credit(40.0);

cout<<"\nCrediting $65.00 to account2";

account2.credit(65.0);

cout<<"\nCrediting $20.00 to account3";

account3.credit(20.0);

cout<<"\nAccount1 balance=$"<<account1.getbalance()<<endl;

cout<<"\nAccount2 balance=$"<<account2.getbalance()<<endl;

cout<<"\nAccount3 balance=$"<<account3.getbalance()<<endl;

double floaterestearned=account2.calculatefloaterest();

cout<<"\nAdding $"<<floaterestearned<<"floaterest to account2"<<endl;


account2.credit(floaterestearned);

cout<<"\nNew account2 balance=$"<<account2.getbalance()<<endl;

Package Inheritance Hierarchy


#ifndef PACKAGE_H

#define PACKAGE_H

#include<string>

using namespace std;

class Package

public:

Package( const string &, const string &, const string &,const string &, int, const string &, const string &,
const string &,const string &, int, double, double );

void setSenderName( const string & );

string getSenderName() const;

void setSenderAddress( const string & );

string getSenderAddress() const;

void setSenderCity( const string & );

string getSenderCity() const;

void setSenderState( const string & );

string getSenderState() const;

void setSenderZIP( int );

int getSenderZIP() const;

void setRecipientName( const string & );

string getRecipientName() const;

void setRecipientAddress( const string & );


string getRecipientAddress() const;

void setRecipientCity( const string & );

string getRecipientCity() const;

void setRecipientState( const string & );

string getRecipientState() const;

void setRecipientZIP( int );

int getRecipientZIP() const;

void setWeight( double );

double getWeight() const;

void setCostPerOunce( double );

double getCostPerOunce() const;

double calculateCost() const;

private:

string senderName;

string senderAddress;

string senderCity;

string senderState;

int senderZIP;

string recipientName;

string recipientAddress;

string recipientCity;

string recipientState;

int recipientZIP;

double weight;
double costPerOunce;

};

#endif

#include "Package.h"

#include<iostream>

#include<string>

using namespace std;

Package::Package( const string &sName, const string &sAddress,const string &sCity, const string
&sState, int sZIP,const string &rName, const string &rAddress, const string &rCity,const string &rState,
int rZIP, double w, double cost ):senderName( sName ), senderAddress( sAddress ),
senderCity( sCity ),senderState( sState ), senderZIP( sZIP ),
recipientName( rName ),recipientAddress( rAddress ), recipientCity( rCity ),recipientState( rState ),
recipientZIP( rZIP )

setWeight(w);

setCostPerOunce(cost);

void Package::setSenderName( const string &name )

senderName=name;

string Package::getSenderName() const

return senderName;

void Package::setSenderAddress( const string &address )


{

senderAddress = address;

string Package::getSenderAddress() const

return senderAddress;

void Package::setSenderCity( const string &city )

senderCity = city;

string Package::getSenderCity() const

return senderCity;

void Package::setSenderState( const string &state )

senderState = state;

string Package::getSenderState() const

return senderState;

void Package::setSenderZIP( int zip )

{
senderZIP = zip;

int Package::getSenderZIP() const

return senderZIP;

void Package::setRecipientName( const string &name )

recipientName = name;

string Package::getRecipientName() const

return recipientName;

void Package::setRecipientAddress( const string &address )

recipientAddress = address;

string Package::getRecipientAddress() const

return recipientAddress;

void Package::setRecipientCity( const string &city )

recipientCity = city;
}

string Package::getRecipientCity() const

return recipientCity;

void Package::setRecipientState( const string &state )

recipientState = state;

string Package::getRecipientState() const

return recipientState;

void Package::setRecipientZIP( int zip )

recipientZIP = zip;

int Package::getRecipientZIP() const

return recipientZIP;

void Package::setWeight( double w )

weight = ( w < 0.0 ) ? 0.0 : w;

}
double Package::getWeight() const

return weight;

void Package::setCostPerOunce( double cost )

costPerOunce = ( cost < 0.0 ) ? 0.0 : cost;

cout<<costPerOunce;

double Package::getCostPerOunce() const

return costPerOunce;

double Package::calculateCost() const

return getWeight() * getCostPerOunce();

#ifndef TWODAY_H

#define TWODAY_H

#include "Package.h"

using namespace std;

class TwoDayPackage : public Package

public:
TwoDayPackage( const string &, const string &, const string &,const string &, int, const string &, const
string &, const string &,const string &, int, double, double, double );

void setFlatFee( double );

double getFlatFee() const;

double calculateCost() const;

private:

double flatFee;

};

#endif

#include"TwoDayPackage.h"

#include<iostream>

using namespace std;

TwoDayPackage::TwoDayPackage( const string &sName,const string &sAddress, const string &sCity,


const string &sState,int sZIP, const string &rName, const string &rAddress,const string &rCity, const
string &rState, int rZIP,double w, double cost, double fee ):Package( sName, sAddress, sCity, sState, sZIP,

rName, rAddress, rCity, rState, rZIP, w, cost )

setFlatFee( fee );

void TwoDayPackage::setFlatFee( double fee )

flatFee = ( fee < 0.0 ) ? 0.0 : fee;

double TwoDayPackage::getFlatFee() const


{

return flatFee;

double TwoDayPackage::calculateCost() const

return Package::calculateCost() + getFlatFee();

#ifndef OVERNIGHT_H

#define OVERNIGHT_H

#include "Package.h"

#include"TwoDayPackage.h"

class OvernightPackage : public Package

public:

OvernightPackage( const string &, const string &, const string &,const string &, int, const string &, const
string &, const string &,const string &, int, double, double, double );

void setOvernightFeePerOunce( double );

double getOvernightFeePerOunce() const;

double calculateCost() const;

private:

double overnightFeePerOunce;

};

#endif

#include "OvernightPackage.h"
#include<iostream>

using namespace std;

OvernightPackage::OvernightPackage( const string &sName,const string &sAddress, const string &sCity,


const string &sState,int sZIP, const string &rName, const string &rAddress,const string &rCity, const
string &rState, int rZIP, double w, double cost, double fee ) : Package( sName, sAddress, sCity, sState,
sZIP,

rName, rAddress, rCity, rState, rZIP, w, cost )

setOvernightFeePerOunce( fee );

void OvernightPackage::setOvernightFeePerOunce(double overnightFee)

overnightFeePerOunce =overnightFee;

double OvernightPackage::getOvernightFeePerOunce()const

return overnightFeePerOunce;

double OvernightPackage::calculateCost()const

return getWeight() * ( getCostPerOunce() + getOvernightFeePerOunce() );

#include "Package.h"

#include "TwoDayPackage.h"

#include "OvernightPackage.h"

#include<iostream>
#include<string>

#include<iomanip>

using namespace std;

int main()

Package package1( "Ahmad Khan", "1 Main St", "Boston", "MA", 11111,"Zahid", "7 Elm St", "New York",
"NY", 22222, 8.5, .5 );

TwoDayPackage package2( "Ayesha", "5 Broadway", "Somerville", "MA",33333, "George", "21 Pine Rd",
"Cambridge", "MA", 44444,10.5, .65, 2.0 );

OvernightPackage package3( "Seokjin", "2 Oak St", "Boston", "MA",55555,"Helina", "9 Main St",
"Denver", "CO", 66666,12.25, .7, .25 );

cout << fixed << setprecision( 2 );

cout<<"Package 1:\n\nSender:\n"<<package1.getSenderName()<<'\
n'<<package1.getSenderAddress()<<'\
n'<<package1.getSenderCity()<<","<<package1.getSenderState()<<' '<< package1.getSenderZIP();

cout<<"\n\nRecipient:\n"<<package1.getRecipientName()<<'\n'<<package1.getRecipientAddress()<<'\
n'<<package1.getRecipientCity()<<","<<package1.getRecipientState()<<' '<< package1.getRecipientZIP();

cout << "\n\nCost: $" << package1.calculateCost() << endl;

cout<<"\nPackage 2:\n\nSender:\n"<<package2.getSenderName()<<'\
n'<<package2.getSenderAddress()<<'\n'<<package2.getSenderCity()<<",
"<<package2.getSenderState()<< ' ' << package2.getSenderZIP();

cout<<"\n\nRecipient:\n"<<package2.getRecipientName()<<'\n'<<package2.getRecipientAddress() << '\


n'<< package2.getRecipientCity() << ", "<<package2.getRecipientState() << ' '<<
package2.getRecipientZIP();

cout << "\n\nCost: $" << package2.calculateCost() << endl;

cout << "\nPackage 3:\n\nSender:\n" << package3.getSenderName()<< '\n' <<


package3.getSenderAddress() << '\n'<< package3.getSenderCity() << ", " <<
package3.getSenderState()<< ' ' << package3.getSenderZIP();

cout << "\n\nRecipient:\n" << package3.getRecipientName()<< '\n' << package3.getRecipientAddress()


<< '\n'<<package3.getRecipientCity() << ", "<<package3.getRecipientState() << ' '<<
package3.getRecipientZIP();
cout << "\n\nCost: $" << package3.calculateCost() << endl;

return 0;

Student Inheritance Hierarchy

Student at a university

Undergraduate Students Graduate Students

Master Students Doctoral Students


Junior Senior

Freshman Sophomore
Employee Inheritance Hierarchy

Academic Administrative

Professor Instructor Dean Principal

Vice Principal
Lecturer
Employee at a university

Richer Shape Hierarchy

Shape

Two Dimensional Shapes Three Dimensional Shapes

Circle Triangle Square Sphere Cube Tetrahedron

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy