Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<ctime>
- #define BCOST 5 // Base Package Factor
- #define ACOST 2 // Advanced Package Aditional Fee
- #define OCOST 10// OverNight Package Factor (+Fee)
- using namespace std;
- class package {
- public:
- string sname,sadd;
- string rname,radd;
- float weight;
- struct tm dateofsend;
- public:
- package(string _sname, string _sadd, string _rname, string _radd,float _weight,struct tm _dateofsend)
- {sname=_sname;sadd=_sadd;rname=_rname;radd=_radd;weight=_weight;dateofsend=_dateofsend;};
- package()
- {sname="Sender Name Undefined";sadd="Sender Address Undefined";rname="Recipient Name Undefined",radd="Recipient Name Undefined";weight=-1;};
- //float calculateCost() {};
- //time_t calculatedeliverytime() {};
- void print() {cout << dateofsend.tm_mday;};
- };
- class base : public package {
- public:
- base(string __sname, string __sadd, string __rname, string __radd, float __weight, struct tm __dateofsend) : package(__sname, __sadd, __rname, __radd, __weight, __dateofsend) {};
- base() : package() {};
- float calculateCost() {return BCOST*weight;};
- tm calculatedeliverytime() {
- struct tm deltime = dateofsend;
- deltime.tm_mday += 5;
- return deltime;
- };
- };
- class advanced : public package {
- public:
- advanced(string __sname, string __sadd, string __rname, string __radd, float __weight,struct tm __dateofsend) : package(__sname, __sadd, __rname, __radd, __weight,__dateofsend) {};
- advanced() : package() {};
- float calculateCost() {return ACOST+(BCOST*weight);};
- tm calculatedeliverytime(struct tm datesend) {struct tm datedelivered; return datedelivered;};
- };
- class overnight : public package {
- public:
- overnight(string __sname, string __sadd, string __rname, string __radd, float __weight,struct tm __dateofsend) : package(__sname, __sadd, __rname, __radd, __weight,__dateofsend) {};
- overnight() : package() {};
- float calculateCost() {return ((BCOST+OCOST) * weight);};
- tm calculatedeliverytime(struct tm datesend) {struct tm datedelivered; return datedelivered;};
- };
- void printmenu() {cout << "1.New Base Package\n2.New Advanced Package\n3.New Overnight Package\nPlease Select: " << endl;}
- void getinfo(string &sname, string &sadd, string &recname, string &recadd,float &w, int &dd, int &mm, int &yy)
- {cout << "Please enter the sender's name and Surname:" << endl;
- getline(cin, sname);
- cout << "Now enter the sender's address:" << endl;
- getline(cin, sadd);
- cout << "Please do the same for the recipient. Name:" << endl;
- getline(cin, recname);
- cout << "And now the recipient's address:" << endl;
- getline(cin, recadd);
- cout << "What is the date that the parcel has or will be sent? (format DD MM YYYY)" << endl;
- cin >> dd >> mm >> yy;
- fflush(stdin);
- cout << "Finally, please enter the parcel's weight:" <<endl;
- cin >> w;};
- //Global Variables:
- time_t now = time(0);
- struct tm *crt = localtime(&now);
- int main() {
- int o, d, m, y;
- struct tm datesend;
- string sendname,sendadd,recname,recadd;
- float weight;
- cout << "Current date: " << crt->tm_mday << "/" << 1 + crt->tm_mon << "/" << 1900 + crt->tm_year << "." << endl;
- printmenu();
- cin >> o;
- fflush(stdin);
- if(o>0 && o<4){
- getinfo(sendname,sendadd,recname,recadd,weight,d,m,y);
- struct tm datesend; datesend.tm_mday=d; datesend.tm_mon=m; datesend.tm_year=y;
- cout << "Parcel Sent At: " << datesend.tm_mday << "/" << datesend.tm_mon << "/" << datesend.tm_year << endl;
- cout << "Sender Name : " << sendname << "\nSender Address : " << sendadd << "\nRecipient's Name : " << recname << "\nRecipient's Address : " << recadd << "\nParcel Weight : " << weight << endl;}
- switch (o)
- {case 1: {class base* basepack = new base(sendname,sendadd,recname,recadd,weight,datesend);
- basepack->print(); //FAILS
- cout << "The total fee is " << basepack->calculateCost() << "E." << endl;
- // cout << "The estimated day of delivery is " << basepack->calculatedeliverytime().tm_year ; //<< "/"
- // << basepack->calculatedeliverytime().tm_mon +1 << "/" << basepack->calculatedeliverytime().tm_year + 1900 << "." << endl;
- break;}
- case 2: {class advanced* advpack = new advanced(sendname,sendadd,recname,recadd,weight,datesend);
- cout << "The total fee is " << advpack->calculateCost() << "€." << endl;
- cout << "The estimated date of delivery is " << advpack->calculatedeliverytime(datesend).tm_mday << "/"
- << 1 + advpack->calculatedeliverytime(datesend).tm_mon << "/" << 1900 + advpack->calculatedeliverytime(datesend).tm_year << "." << endl;
- break;}
- case 3: {class overnight* overpack = new overnight(sendname,sendadd,recname,recadd,weight,datesend);
- cout << "The total fee is " << overpack->calculateCost() << "€." << endl;
- cout << "The estimated date of delivery is " << overpack->calculatedeliverytime(datesend).tm_mday << "/"
- << 1 + overpack->calculatedeliverytime(datesend).tm_mon << "/" << 1900 + overpack->calculatedeliverytime(datesend).tm_year << "." << endl;
- break;}
- default: {cout << "Wrong choice. Will now exit." << endl;
- break;}
- };
- system("pause");
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement