I am receiving the following errors with my code:
Error 3 error LNK1120: 1 unresolved
externals c:\users\toking\documents\visual studio
2012\Projects\11.9\Debug\11.9.exe 11.9
Error 2 error LNK2001: unresolved external symbol "public: double
__thiscall Package::calculateCost(float,double)" (?calculateCost#Package##QAENMN#Z) c:\Users\toking\documents\visual
studio 2012\Projects\11.9\11.9\11.9_main.obj 11.9
Error 1 error LNK2019: unresolved external symbol "public: double
__thiscall Package::calculateCost(float,double)" (?calculateCost#Package##QAENMN#Z) referenced in function "public:
double __thiscall
overnightPackage::calcCostOvernight(float,double,double)"
(?calcCostOvernight#overnightPackage##QAENMNN#Z) c:\Users\toking\documents\visual
studio 2012\Projects\11.9\11.9\11.9.obj 11.9
This is my second semester of C++ and my first time using inheritance. I tried calling the functions similarly to how my book calls them, but all of the errors seem to be related to my derived classes functions. Any help is greatly appreciated.
// Main
#include <iostream>
#include "stdafx.h"
#include <string>
using namespace std;
int main()
{
int i;
string customerName,customerAddress,city,state,senderAddress,recipientAddress;
float packageWeight;
string customerCity;
double costPerOunce;
double flatFee;
double additionalCost;
string customerState;
int customerZipcode;
Package base;
twoDayPackage twoday;
overnightPackage overnight;
cout<<" *****Welcome To The American Package Delievery Services*****"<<endl<<endl;
cout<<"Please Fill In The Requested Data Follow: "<<endl<<"-----------------------------------------"<<endl<<endl;;
cout<<"Enter Customer Name "<<endl<<endl;
cin>>customerName;
cout<<endl;
base.setName(customerName);
cout<<"Enter Customer Address"<<endl<<endl;
cin>>customerAddress;
cout<<endl;
base.setAddress(customerAddress);
cout<<"Enter Customer City"<<endl<<endl;
cin>>customerCity;
cout<<endl;
base.setCity(customerCity);
cout<<"Enter Customer State"<<endl<<endl;
cin>>customerState;
cout<<endl;
base.setState(customerState);
cout<<"Enter Customer ZIP code"<<endl<<endl;
cin>>customerZipcode;
cout<<endl;
base.setZip(customerZipcode);
cout<<"Enter Weight"<<endl;
cin>>packageWeight;
cout<<endl;
cout<<"Enter Cost Per Ounce"<<endl;
cin>>costPerOunce;
cout<<endl;
cout<<"Please Enter Your Choice From The Menu Below:"<<endl<<endl;
cout<<" 1- Calculate Base Cost "<<endl<<endl;
cout<<" 2- Calculate Two Day Cost "<<endl<<endl;
cout<<" 3- Calculate Over Night Cost"<<endl<<endl;
cin>>i;
cout<<endl;
switch (i)
{
case 1 :
base.calculateCost(packageWeight,costPerOunce);
break;
case 2 :
cout<<"Enter Flat Cost"<<endl<<endl;
cin >> flatFee;
twoday.calcShippingCost(packageWeight,costPerOunce,flatFee);
break;
case 3 :
cout<<"Enter The Additional Cost"<<endl<<endl;
cin >> additionalCost;
overnight.calcCostOvernight(packageWeight,costPerOunce,additionalCost);
break;
default:
cout << "INVALID CHOICE....Please Enter ur Choice Number From 1-->3 "<<endl;
}
cout<<"Enter sender address "<<endl<<endl;
cin>>senderAddress;
cout<<endl;
base.setSender( senderAddress);
cout<<"Enter ricipent address"<<endl<<endl;
cin>>recipientAddress;
cout<<endl;
base.setRecipient(recipientAddress);
cout<<"address from:"<< senderAddress<<endl;
cout<<"To:"<<recipientAddress<<endl;
system ("pause");
return 0;
}
// Header
#include <iostream>
#include <string>
using namespace std;
class Package // Base Class
{
private:
string name, city, state, sender, recipient;
int zip;
string address;
float weight;
double cost;
public:
void setName(string);
string getName();
void setCity(string);
string getCity();
void setState(string);
string getState();
void setZip(int);
int getZip();
void setAddress(string);
string getAddress();
void setSender(string);
string getSender();
void setRecipient(string);
string getRecipient();
double calculateCost(float , double);
};
class twoDayPackage: public Package
{
public:
double calcShippingCost(float, double, double);
private:
double flatFee;
};
class overnightPackage: public Package
{
public:
double calcCostOvernight(float, double, double);
private:
double overnightCost;
};
// Cpp
#include <iostream>
#include "stdafx.h"
#include <string>
using namespace std;
void Package::setName(string n)
{
name = n;
}
void Package::setCity(string c)
{
city = c;
}
void Package::setState(string s)
{
state = s;
}
void Package::setZip (int zp)
{
zip = zp;
}
void Package::setAddress(string adr)
{
address = adr;
}
void Package::setSender(string sen)
{
sender = sen;
}
void Package::setRecipient(string rec)
{
recipient = rec;
}
string Package::getName()
{
return name;
}
string Package::getCity()
{
return city;
}
string Package::getState()
{
return state;
}
int Package::getZip()
{
return zip;
}
string Package::getAddress()
{
return address;
}
string Package::getSender()
{
return sender;
}
string Package::getRecipient()
{
return recipient;
}
double calculateCost(float weight,double costPerOunce)
{
double z;
z = weight * costPerOunce;
cout<< "The Base Cost = " <<z << endl<<endl;
return z;
}
double twoDayPackage::calcShippingCost(float weight, double costPerOunce, double flatFee)
{
double z;
z = calculateCost(weight,costPerOunce) + flatFee;
cout << "The TwoDayPackage Cost = " << z << endl;
return z;
}
double overnightPackage::calcCostOvernight(float weight,double costPerOunce,double additionalCost )
{
double z;
z = calculateCost(weight, costPerOunce)+(additionalCost * weight);
cout<< "The OvernightPackage Cost = " <<z << endl;
return z;
}
Your code can't decide whether calculateCost is a member function of Package or not. Pick one way and stick to it.
Related
I always get this errors when I try to compile and run program:
undefined reference to 'vtable for Currency'
undefined reference to 'WinMain'
[Error] ld returned 1 exit status
My program should convert values from one currency to another (from Euro or Dollars to hryvnias). I am using Dev C++, if that matters.
Class Currency is an abstract base class, and classes Euro and Dollar are child classes.
File currency.h:
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <iostream>
#include <locale.h>
using namespace std;
class Currency
{
protected:
double amount; //amount of money in some currency
float rate; //exchange rate
double amount_grivni; //amount of money in hryvnias
public:
virtual void Convert() = 0;
virtual void print();
virtual void Setamount(double);
virtual void Setrate(float);
virtual ~Currency();
};
class Euro: public Currency
{
public:
Euro();
Euro(double, float);
virtual void Convert();
virtual void print();
virtual void Setamount(double);
virtual void Setrate(float);
~Euro();
};
class Dollar:public Currency
{
public:
Dollar();
Dollar(double, float);
virtual void Convert();
virtual void print();
virtual void Setamount(double);
virtual void Setrate(float);
~Dollar();
};
File currency.cpp:
#include "currency.h"
Currency::~Currency()
{
}
//----------------------------------------------------------------
Dollar::Dollar()
{
amount=0;
rate=0;
amount_grivni=0;
}
Dollar::Dollar(double cur_amount, float cur_rate)
{
amount=cur_amount;
rate=cur_rate;
amount_grivni=0;
}
void Dollar::Convert()
{
amount_grivni=amount*rate;
}
void Dollar::print()
{
cout<<"Amount of money in dollars = "<<amount;
cout<<"\nCurrent rate of dollar to hryvnia = "<<rate;
cout<<"\nAmount of money transferred in hryvnias = "<<amount_grivni<<"\n\n";
}
void Dollar::Setamount(double amount_dm)
{
amount=amount_dm;
}
void Dollar::Setrate(float rate_dm)
{
rate=rate_dm;
}
Dollar::~Dollar()
{
}
//----------------------------------------------------------------
Euro::Euro()
{
amount=0;
rate=0;
amount_grivni=0;
}
Euro::Euro(double cur_amount, float cur_rate)
{
amount=cur_amount;
rate=cur_rate;
amount_grivni=0;
}
void Euro::Convert()
{
amount_grivni=amount*rate;
}
void Euro::Setamount(double amount_d)
{
amount=amount_d;
}
void Euro::Setrate(float rate_d)
{
rate=rate_d;
}
void Euro::print()
{
cout<<"Amount of money in euros = "<<amount;
cout<<"\nCurrent rate of euro to hryvnia = "<<rate;
cout<<"\nAmount of money transferred in hryvnias = "<<amount_grivni<<"\n\n";
}
Euro::~Euro()
{
}
File currency_main.cpp:
#include "currency.cpp"
int main()
{
int i, n, choice;
double cu_amount;
float cu_rate;
cout<<"Enter the number of currencies to process";
cin>>n;
Currency **arr=new Currency*[n];
for(i=0; i<n; i++)
{
cout<<"\nType number 1 for Dollar and 2 for Euro:";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"\nEnter amount of money in dollars = ";
cin>>cu_amount;
cout<<"\nEnter the exchange rate (1 dollar in hryvnia) = ";
cin>>cu_rate;
arr[i]=new Dollar(cu_amount, cu_rate);
break;
}
case 2:
{
cout<<"\nEnter amount of money in euro = ";
cin>>cu_amount;
cout<<"\nEnter the exchange rate (1 euro in hryvnia) = ";
cin>>cu_rate;
arr[i]=new Euro(cu_amount, cu_rate);
break;
}
}
}
for(i=0; i<n; i++)
{
arr[i]->Convert();
arr[i]->print();
}
for (i=0; i<n; i++)
delete arr[i];
delete[] arr;
return 0;
}
I tried to run this program in Visual Studio, but it didn't help. I created new files and copied code from old ones, but it also didn't work. I even reinstalled Dev C++ and rebooted the computer. The code looks simple, but I can't see what the problem is.
#include <iostream>
#include <string>
#ifndef FOOD_H
#define FOOD_H
using namespace std;
this class for insertion sorting for food's price or food's calorie
class Food
{
private:
string Name;
float Calorie;
float Price;
public:
void setName(string n);
void setCalorie(float c);
void setPrice(float p);
string getName();
float getCalorie();
float getPrice();
Food();
Food(string n,float c,float p);
void Print(Food FoodArray[],int);
void Sort(Food FoodArray[], float);
void Sort2(Food FoodArray[], float);
};
#endif
#include <iostream>
#include <string>
#include "Food.h"
#ifndef IMPLEMENTER_CPP
#define IMPLEMENTER_CPP
using namespace std;
void Food::setName(string n){Name=n;}
void Food::setPrice(float p){Price=p;}
void Food::setCalorie(float c){Calorie=c;}
string Food::getName(){return Name;}
float Food::getPrice(){ return Price;}
float Food::getCalorie(){ return Calorie;}
Food::Food(string n,float c,float p)
{
Food::Name=n;
Food::Calorie=c;
Food::Price=p;
}
Food::Food()
{
Food::Name="";
Food::Calorie=0.00;
Food::Price=0.00;
}
void Food::Print(Food FoodArray[],int num)
{
for (int i=0;i>num;i++)
{
cout<<"-------------------------------------------------"<<endl;
cout<<"NAME: "<<FoodArray[i].getName()<<" CALORIE: "<<FoodArray[i].getCalorie()<<" PRICE: "<<FoodArray[i].getPrice()<<endl;
cout<<"-------------------------------------------------"<<endl;
}
}
void Food::Sort(Food FoodArray[], float pri)
{
int i,j;
float tmp;
string t;
for(i=1;i<=pri-1;i++)
{
tmp=FoodArray[i].getPrice();
t=FoodArray[i].getName();
j=i-1;
while((tmp<FoodArray[j].getPrice())&&(j>=0))
{
FoodArray[j+1]=FoodArray[j];
j--;
}
FoodArray[j+1].setName(t);
FoodArray[j+1].setPrice(tmp);
}
cout<<endl<<"Sorted list is shown below: "<<endl;
}
void Food::Sort2(Food FoodArray[], float cal)
{
int i, j;
float tmp;
string t;
for(i=1;i<=cal-1;i++)
{
tmp=FoodArray[i].getCalorie();
t=FoodArray[i].getName();
j=i-1;
while((tmp<FoodArray[j].getCalorie())&&(j>=0))
{
FoodArray[j+1]=FoodArray[j];
j=j-1;
}
FoodArray[j+1].setCalorie(tmp);
FoodArray[j+1].setName(t);
}
cout<<endl<<"Sorted list is shown below: "<<endl;
}
#endif
#include <iostream>
#include <string>
#include "Food.h"
#include "Implementer.cpp"
using namespace std;
contains the main method. From this class an array of food will be created and the sorting function
will be called to sort the array.
class client
{
public:
Food *foodArray[];
void info()
{int num;
string name,answer;
float calorie,price;
loop2:
cout<<"how many do you want ? ";
cin>>num;
if (num>0)
{
for (int i=0; i<num; i++)
{
cout<<i+1<<"- ";
cout<<"Enter Food name: ";
cin>>name;
cout<<"Enter Calories: ";
cin>>calorie;
cout<<"Enter Price: ";
cin>>price;
Food food=Food(name,calorie,price);
*foodArray[i]=food;
}
foodArray[num]->Print(*foodArray,num);
loop:
cout<<"Would you like to sort the foods based on Price or Calories? P/C"<<endl;
cin>>answer;
if (answer=="P")
{
foodArray[num]->Sort(*foodArray,price);
foodArray[num]->Print(*foodArray,num);
}
else if (answer=="C")
{
foodArray[num]->Sort2(*foodArray,calorie);
foodArray[num]->Print(*foodArray,num);
}
else
{
cout<<"please choose P or C."<<endl;
goto loop;
}
}
else
{
goto loop2;
}
}
};
int main()
{
client C;
C.info();
return 0;
}
I want float variable 'avg' to be returned and then in the main pass it to 'void batsman::display(float a)' using a parameter. then display the average marks in display method. this method gives me 2 errors. any other way?
#include<iostream.h>
class batsman
{
int marks[5];
char name[15],country[15];
public:
void input();
float cal();
void display();
};
void batsman::input()
{
int i;
cout<<"Enter player name: ";
cin>>name;
cout<<"Enter player country: ";
cin>>country;
cout<<"Enter player marks"<<"\n";
for(i=0;i<5;i++)
{
cout<<"Mark "<<i+1<<": ";
cin>>marks[i];
}
}
float batsman::cal()
{
int i;
int tot=0;
float avg;
for(i=0;i<5;i++)
{
tot=tot+marks[i];
}
avg=(float)tot/5;
return avg;
}
void batsman::display(float a)
{
float avg1;
avg1=a;
cout<<"Player name: "<<name<<"\n";
cout<<"Player country: "<<country<<"\n";
cout<<"Average: "<<avg1<<"\n";
}
int main()
{
batsman b1;
b1.input();
b1.cal();
b1.display(b1.batsman::cal());
//cout<<"Average: "<<b1.batsman::cal()<<"\n";
}
The code has several errors.
iostream.h should be iostream
using namespace std; // add this at top so that cout is found
display() should be display(float a) in the class declaration.
After those changes the code ran as expected.
Change display's definition in your class to display(float a), and prepend std:: to cout and cin. As a recommendation, don't use iostream.h, use iostream.
Im new to classes and i have to write my own functions and variables in a class that stores rover information when it is entered and for some reason whenever I write my functions and try to call them in main they are not working. I have provided my code and Im wondering if someone can help me explain how to get the rovers data to be stored for each rover r1-r5. Thank you.
class Rover{
private:
string name;
int xpos;
int ypos;
string direction; //Use Cardinal Directions (N,S,E,W)
int speed; //(0-5 m/sec)
public:
//Constructors
//defaultRover();
//Rover();
//Get functions
string getName();
int getXpos();
int getYpos();
string getDirect();
int getSpeed();
void getRoverData();
//Set functions
string setName();
void setXpos();
void setYpos();
void setDirect();
void setSpeed();
};
//Constructor function
/*Rover::defaultRover()
{
xpos=0;
ypos=0;
direction="N";
speed=0;
}
*/
/*
Rover::Rover()
{
cout<<"Please enter the starting X-position: ";
cin>>xpos;
cout<<"Please enter the starting Y-position: ";
cin>>ypos;
cout<<"Please enter the starting direction (N,S,E,W): ";
cin>>direction;
cout<<"Please enter the starting speed (0-5): ";
cin>>speed;
cout<<endl;
}
*/
//Getter functions
string Rover::getName()
{
return name;
}
int Rover::getXpos()
{
return xpos;
}
int Rover::getYpos()
{
return ypos;
}
string Rover::getDirect()
{
return direction;
}
int Rover::getSpeed()
{
return speed;
}
void Rover::getRoverData()
{
cout<<name;
cout<<xpos;
cout<<ypos;
cout<<direction;
cout<<speed;
}
//Setter functions
string Rover::setName()
{
cout<<"Please enter the Rover name ";
cin>>name;
}
void Rover::setXpos()
{
cout<<"Please enter the X-position of the Rover ";
cin>>xpos;
}
void Rover::setYpos()
{
cout<<"Please enter the Y-position of the Rover ";
cin>>ypos;
}
void Rover::setDirect()
{
cout<<"Please enter the direction of the Rover (N,S,E,W) ";
cin>>direction;
}
void Rover::setSpeed()
{
cout<<"Please enter the speed of the Rover (0-5) ";
cin>>speed;
}
int main(int argc, char** argv)
{
Rover r1, r2, r3, r4, r5;
r1.setName();
r1.getName();
return 0;
}
As a general rule...
getters and setters should not communicate with stdin or stdout
getters should return what they're getting
setters should assign the member to what is being passed in
Let's make a pretend class Foo:
class Foo {
public:
// setters
void set_bar(int bar) { bar_ = bar; }
void set_baz(std::string baz) { baz_ = baz; }
void set_boo(double boo) { boo_ = boo; }
// getters
int get_bar() const { return bar_; }
std::string get_baz() const { return baz_; }
double get_boo() const { return boo_; }
private:
int bar_;
std::string baz_;
double boo_;
};
The way this should be used is something like this:
Foo foo;
int bar;
std::cout << "Please enter bar: " << std::endl;
std::cin >> bar;
foo.set_bar(bar);
std::cout << "foo's bar is " << foo.get_bar() << std::endl;
You need to change a lot of code, but I hope this helped.
I need to write the name, act# balance and address of the object that is stored in the vector, to a file.
I believe I have the program to push the objects into the vectors, but since they are vectors of object pointers I am having problems figure out how to call the object and print all 3 objects out.
Main.cpp
vector<Account*> accounts;
accounts.push_back(new Savings(new Person("Bilbo Baggins", "43 Bag End"), 1, 500, 0.075));
accounts.push_back(new Checking(new Person("Wizard Gandalf", "Crystal Palace"), 2, 1000.00, 2.00));
accounts.push_back(new Savings(new Person("Elf Elrond", "Rivendell"), 3, 1200, 0.050));
ofstream outFile;
outFile.open("accounts.txt");
if (outFile.fail())
{
cout << "\nYour file did not open, the program will now close!\n";
system("PAUSE");
return 0;
}
else
{
cout << "\nBINGO!!! It worked.\n\n";
system("PAUSE");
cout << "\n";
}
// New : Using a loop, send messages to each of the three Account objects to write themselves out to the file.
cout << "\nNow we are going to write the information to \"Accounts.txt\" \n\n";
system("PAUSE");
for (int i = 0; i < accounts.size(); i++) {
accounts[i]->writeAccount(outFile);
}
Account.h
#pragma once
#include <string>
#include <iostream>
#include "Person.h"
using namespace std;
// Account class - abstract/parent class
class Account
{
private:
int actNumber;
double actBallance;
Person PersonName;
public:
Account();
Account(int, double, Person*);
int getActNumber();
virtual double getActBallance();
string getName();
string getAdd();
void deposit(double);
void withdrawl(double);
virtual void writeAccount(ofstream&);
virtual void readAccount(ifstream&);
void testAccount(int i);
};
// Checking class: inherits from the Account class
class Checking : public Account
{
private:
double monthlyFee;
public:
Checking();
Checking(Person*, int, double, double);
void setMonthlyFee(double);
double getActBallance();
void writeAccount(ofstream&);
void readAccount(ifstream&);
};
// Savings class: inherits from the Account class
class Savings : public Account
{
private:
int interestRate;
public:
Savings();
Savings(Person*, int, double, double); // person, act#, Ballance, Interest Rate
void setInterestRate(double);
double getActBallance();
void writeAccount(ofstream&);
void readAccount(ifstream&);
};
Account.cpp
#include "Account.h"
#include <string>
using namespace std;
Account::Account()
{
actNumber = 0;
actBallance = 0.0;
}
Account::Account(int act, double bal, Person* name)
{
actNumber = act;
actBallance = bal;
}
int Account::getActNumber()
{
return actNumber;
}
double Account::getActBallance()
{
return actBallance;
}
string Account::getName()
{
return PersonName.getName();
}
string Account::getAdd()
{
return PersonName.getAddress();
}
void Account::deposit(double money)
{
actBallance += money;
}
void Account::withdrawl(double money)
{
actBallance -= money;
}
void Account::writeAccount(ofstream& output)
{
output << actNumber << "\n" << actBallance << "\n" << PersonName.getName() << "\n" << PersonName.getAddress() << endl;
}
void Account::readAccount(ifstream& output)
{
output >> actNumber;
output >> actBallance;
}
// Checking Account
Checking::Checking() {
monthlyFee = 0;
}
Checking::Checking(Person* per, int actNum, double bal, double interest) {
bal -= monthlyFee;
Account:Account(actNum, bal, per);
}
void Checking::setMonthlyFee(double fee) {
monthlyFee = fee;
}
double Checking::getActBallance() {
double ballance = Account::getActBallance();
return ballance = monthlyFee;
}
void Checking::readAccount(ifstream& output) {
int actNumber = Account::getActNumber();
int actBallance = Account::getActBallance() - monthlyFee;
output >> actNumber;
output >> actBallance;
}
void Checking::writeAccount(ofstream& output) {
int actNumber = Account::getActNumber();
int actBallance = Account::getActBallance();
output << actNumber << "\n" << actBallance << endl;
}
// Savings Account
Savings::Savings() {
interestRate = 0;
}
// Savings(Person, int, double, double) // person, act#, Ballance, Interest Rate
Savings::Savings(Person* per, int actNum, double bal, double interest) {
bal += (bal * interest);
Account:Account(actNum, bal, per);
}
void Savings::setInterestRate(double rate) {
interestRate = rate;
}
double Savings::getActBallance() {
double ballance = Account::getActBallance();
return ballance + (ballance * interestRate);
}
void Savings::readAccount(ifstream& output) {
double actBallance = Account::getActBallance();
int actNumber = Account::getActNumber();
actBallance += (actBallance * interestRate);
output >> actNumber;
output >> actBallance;
}
void Savings::writeAccount(ofstream& output) {
int actNumber = Account::getActNumber();
int actBallance = Account::getActBallance();
output << actNumber << "\n" << actBallance << endl;
}
I realize I am so far off... but I have been at this for HOURS and I can not figure out for the life of me, but to take the vector of object pointers and output the objects values.
Person.h
#pragma once
#include <string>
#include <fstream>
using namespace std;
class Person
{
private:
string name;
string address;
public:
Person();
Person(string a, string b);
string getName();
string getAddress();
void writePerson(ofstream&);
void readPerson(ifstream&);
};
Person.cpp
#include "Person.h"
#include <string>
using namespace std;
Person::Person()
{
name = "NAME";
address = "123 STREET";
}
Person::Person(string a, string b)
{
name = a;
address = b;
}
string Person::getName()
{
return name;
}
string Person::getAddress()
{
return address;
}
void Person::writePerson(ofstream& output)
{
output << name << " " << address << endl;
}
void Person::readPerson(ifstream& output)
{
output >> name;
output >> address;
Person(name, address);
}
Read again your course books on constructors: there are severe issues in all of your constructors. As a result, you don't initialize the object member variables, and you effectively end up printing lots of zeros and empty strings...
Firstly, for your base-class, you must initialize the person name. You should have written:
Account::Account(int act, double bal, Person* name)
: actNumber(act)
, actBallance(bal)
, PersonName(name)
{}
Secondly, for your derived classes, the initialisation of the base-class must be done in the initializer-list, not in the body of the ctor. Here is for exemple the correct definition for the Checking's ctor:
Checking::Checking(Person* per, int actNum, double bal, double interest)
: Account(actNum, bal, per)
, monthlyFee(-bal)
{}
Thirdly, be careful to initialize the member variables with the arguments of the ctor. You sometimes do the opposite and assign the ctor arguments with the (uninitialized) member variables.
BTW, Account is a base-class for a polymorphic hierarchy: thus, the Account destructor must be declared virtual.