Advertisement
Guest User

Untitled

a guest
Dec 8th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.86 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<ctime>
  4. #define BCOST 5 // Base Package Factor
  5. #define ACOST 2 // Advanced Package Aditional Fee
  6. #define OCOST 10// OverNight Package Factor (+Fee)
  7. using namespace std;
  8.  
  9. class package {
  10.       public:
  11.               string sname,sadd;
  12.               string rname,radd;
  13.               float weight;
  14.               struct tm dateofsend;
  15.       public:
  16.              package(string _sname, string _sadd, string _rname, string _radd,float _weight,struct tm _dateofsend)
  17.                             {sname=_sname;sadd=_sadd;rname=_rname;radd=_radd;weight=_weight;dateofsend=_dateofsend;};
  18.              package()
  19.                       {sname="Sender Name Undefined";sadd="Sender Address Undefined";rname="Recipient Name Undefined",radd="Recipient Name Undefined";weight=-1;};
  20.              //float  calculateCost() {};
  21.              //time_t calculatedeliverytime() {};
  22.              void print() {cout << dateofsend.tm_mday;};
  23. };          
  24. class base : public package {
  25.       public:
  26.              base(string __sname, string __sadd, string __rname, string __radd, float __weight, struct tm __dateofsend) : package(__sname, __sadd, __rname, __radd, __weight, __dateofsend) {};
  27.              base() : package() {};
  28.              float calculateCost() {return BCOST*weight;};
  29.              tm calculatedeliverytime() {
  30.                     struct tm deltime = dateofsend;
  31.                     deltime.tm_mday +=  5;
  32.                     return deltime;
  33.                     };
  34.              };
  35.      
  36. class advanced : public package {
  37.       public:
  38.              advanced(string __sname, string __sadd, string __rname, string __radd, float __weight,struct tm __dateofsend) : package(__sname, __sadd, __rname, __radd, __weight,__dateofsend) {};
  39.              advanced() : package() {};
  40.              float calculateCost() {return ACOST+(BCOST*weight);};
  41.              tm calculatedeliverytime(struct tm datesend) {struct tm datedelivered; return datedelivered;};
  42.              };
  43.              
  44. class overnight : public package {
  45.       public:
  46.              overnight(string __sname, string __sadd, string __rname, string __radd, float __weight,struct tm __dateofsend) : package(__sname, __sadd, __rname, __radd, __weight,__dateofsend) {};
  47.              overnight() : package() {};
  48.              float calculateCost() {return ((BCOST+OCOST) * weight);};
  49.              tm calculatedeliverytime(struct tm datesend) {struct tm datedelivered; return datedelivered;};
  50.              };
  51.              
  52. void printmenu() {cout << "1.New Base Package\n2.New Advanced Package\n3.New Overnight Package\nPlease Select: " << endl;}
  53. void getinfo(string &sname, string &sadd, string &recname, string &recadd,float &w, int &dd, int &mm, int &yy)
  54.      {cout << "Please enter the sender's name and Surname:" << endl;
  55.      getline(cin, sname);
  56.      cout << "Now enter the sender's address:" << endl;
  57.      getline(cin, sadd);
  58.      cout << "Please do the same for the recipient. Name:" << endl;
  59.      getline(cin, recname);
  60.      cout << "And now the recipient's address:" << endl;
  61.      getline(cin, recadd);
  62.      cout << "What is the date that the parcel has or will be sent? (format DD MM YYYY)" << endl;
  63.      cin >> dd >> mm >> yy;
  64.      fflush(stdin);
  65.      cout << "Finally, please enter the parcel's weight:" <<endl;
  66.      cin >> w;};
  67.      
  68. //Global Variables:
  69. time_t now = time(0);    
  70. struct tm *crt = localtime(&now);
  71.  
  72. int main() {
  73.     int o, d, m, y;
  74.     struct tm  datesend;
  75.     string sendname,sendadd,recname,recadd;
  76.     float weight;
  77.     cout << "Current date: " << crt->tm_mday << "/" << 1 + crt->tm_mon << "/" << 1900 + crt->tm_year << "." << endl;
  78.     printmenu();
  79.     cin >> o;
  80.     fflush(stdin);
  81.     if(o>0 && o<4){
  82.         getinfo(sendname,sendadd,recname,recadd,weight,d,m,y);
  83.         struct tm datesend; datesend.tm_mday=d; datesend.tm_mon=m; datesend.tm_year=y;
  84.         cout << "Parcel Sent At: " << datesend.tm_mday << "/" << datesend.tm_mon << "/" << datesend.tm_year << endl;
  85.         cout << "Sender Name : " << sendname << "\nSender Address : " << sendadd << "\nRecipient's Name : " << recname << "\nRecipient's Address : " << recadd << "\nParcel Weight : " << weight << endl;}
  86.         switch (o)
  87.         {case 1: {class base* basepack = new base(sendname,sendadd,recname,recadd,weight,datesend);
  88.                     basepack->print(); //FAILS
  89.                  cout << "The total fee is " << basepack->calculateCost() << "E." << endl;
  90.                // cout << "The estimated day of delivery is " <<  basepack->calculatedeliverytime().tm_year ; //<< "/"
  91.                //   << basepack->calculatedeliverytime().tm_mon +1 << "/" << basepack->calculatedeliverytime().tm_year + 1900 << "." << endl;
  92.                  break;}          
  93.         case 2:  {class advanced* advpack = new advanced(sendname,sendadd,recname,recadd,weight,datesend);
  94.                  cout << "The total fee is " << advpack->calculateCost() << "€." << endl;
  95.                  cout << "The estimated date of delivery is " <<  advpack->calculatedeliverytime(datesend).tm_mday << "/"
  96.                   << 1 + advpack->calculatedeliverytime(datesend).tm_mon << "/" << 1900 + advpack->calculatedeliverytime(datesend).tm_year << "." << endl;
  97.                  break;}
  98.         case 3:  {class overnight* overpack = new overnight(sendname,sendadd,recname,recadd,weight,datesend);
  99.                  cout << "The total fee is " << overpack->calculateCost() << "€." << endl;
  100.                  cout << "The estimated date of delivery is " <<  overpack->calculatedeliverytime(datesend).tm_mday << "/"
  101.                   << 1 + overpack->calculatedeliverytime(datesend).tm_mon << "/" << 1900 + overpack->calculatedeliverytime(datesend).tm_year << "." << endl;
  102.                  break;}
  103.         default: {cout << "Wrong choice. Will now exit." << endl;
  104.                   break;}
  105.     };
  106.     system("pause");
  107.      return 0;
  108.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement