Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

#include <iostream>

#include <conio.h>
#include <string>
#include <stdlib.h>
using namespace std;
#define KEY_ESCAPE 27
class address {
string addres;
string city;
string state;
int zipcode;
public:
address(string a = "",string t="",string s="",int z=0){
addres = a;
city = t;
state = s;
zipcode = z;
}
void insert() {
cout << "Enter Address: "; cin >> addres;
cout << "Enter City: "; cin >> city;
cout << "Enter State: "; cin >>state;
cout << "Enter ZIPCODE: "; cin >> zipcode;
}
void display() {
cout << "Address " << addres;
cout << "City: " << city;
cout << "State: "<< state;
cout << "ZIPCODE: "<<zipcode;
}
};
class Package {
private:
string name;
address add;
signed int weight;
signed int cost;
public:
Package(string n, string a, string c, string s, signed int z, int w, signed int p):add(n,a,c,w)
{
name = n;
weight = w;
cost = p;
}
virtual void func() = 0;
virtual void insert(){
cout << "Enter Name:"; cin >> name;
cout << "Enter the total weight of product: "; cin >> weight;
cout << "Enter the Shipping Cost: "; cin >> cost;
add.insert();
}
virtual void display(){
cout << "Name:"<<name;
cout << "Total weight of product: "<< weight;
cout << "The Total Shipping Cost is: " << cost;
add.display();
}
virtual double calculateCost() {
return (cost*weight);
}
double getcost() {
return cost;
}
};
class TwoDaysPackage : public Package{
private:
int shipping;
public:
TwoDaysPackage(int ab, string n, string a, string c, string s, signed int z, int w, signed int
p) :Package(n, a, c, s, z, w, p) {
shipping = ab;
}
void func() {}
double calculateCost() {
return (shipping +getcost());
}
void insert() {
cout << "Enter the two days package cost: ";
cin >> shipping;
}
void display() {
cout << "Shipping Fee is: " << shipping;
}
};
class OverNightPackage : public Package{
int ovshipping;
public:
OverNightPackage(int ov,string n, string a, string c, string s, signed int z, int w, signed int
p) :Package(n, a, c, s, z, w, p) {
ovshipping = ov;
}
void func(){}
double calculateCost() {
return (ovshipping + getcost());
}
void insert() {
Package::insert();
cout << "Enter Over Night Shipping Fee: " << ovshipping;
cin >> ovshipping;
}
void display() {
cout << "Over Night Shipping Fee is: " << ovshipping;
Package::display();
}
};

int main() {
char a;
//do {
Package* ptr = NULL;
cout << "Welcome To Fedex Calculator";
cout << "Press 1 for Two Day Shipping.\nPress 2 for Over Night Shipping.\nPress
Escape to Exit.";
cin >> a;
switch (a) {
case '1':
ptr = new TwoDaysPackage ;
break;
case '2':
ptr = new OverNightPackage;
break;
case KEY_ESCAPE:
exit(0);
break;
default:
cout << "Presss valid button!";
system("CLS");
break;
}
ptr->insert();
ptr->calculateCost();
ptr->display();
delete ptr;
system("pause");
//} while (a != KEY_ESCAPE);
return 0;
}

You might also like