Do I declare the prototype in my header file and cpp file virtual?
Can a virtual function take parameters like other functions?
some code written so far: Package is my base class, TwoDayPackage is 1 derived class
#ifndef PACKAGE_H
#define PACKAGE_H
#include <iostream>
#include <string>
using namespace std;
class Package
{
public:
// constructor receives package information and validates
Package(string, string, string, string, int, string, string, string, string, int,
int, double = 0.0);
// prints the sender's and recipient's addresses on screen as a shipping label
void printLabel(string, string, string, string, int, string, string, string, string, int);
// virtual function, will be defined by derived classes
virtual double calculateCost();
protected:
string senderName;
string receiverName;
string senderAddress;
string receiverAddress;
string senderCity;
string receiverCity;
string senderState;
string receiverState;
int senderZipcode;
int receiverZipcode;
int packageWeight;
double ounceCost;
}; // end class
#endif
#ifndef TWODAYPACKAGE_H
#define TWODAYPACKAGE_H
#include <iostream>
#include <string>
#include "Package.h" // Package class declaration
using namespace std;
class TwoDayPackage : public Package // will inherit functionallity of base class Package
{
public:
// constructor
TwoDayPackage(string, string, string, string, int, string, string, string, string, int,
int, double = 0.0, double = 0.0);
// calculate the cost of two day shipping
double calculateCost();
private:
double flatFee; // flat rate for two day delivery service
}; // end class
#endif

New Topic/Question
Reply




MultiQuote



|