Advertisement
Guest User

oop-2805

a guest
May 28th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Test{
  5. private:
  6.     char* name;
  7.     double price;
  8.     double time;
  9. public:
  10.     Test(const char* =" ", double = 0, double = 0);
  11.     virtual ~Test(){
  12.         delete [] name;
  13.     }
  14.     Test(const Test& rhs){
  15.         strcpy_s(name, (strlen(rhs.name) + 1), rhs.name);
  16.         price = rhs.price;
  17.         time = rhs.time;
  18.     }
  19.     Test& operator=(const Test& other){
  20.         if (this != &other){
  21.             delete [] name;
  22.             name = new char[strlen(other.name)+1];
  23.             strcpy_s(name, (strlen(other.name) + 1), other.name);
  24.             price = other.price;
  25.             time = other.time;
  26.         }
  27.         return *this;
  28.     }
  29.     void setName(const char* _name){
  30.         delete [] name;
  31.         name = new char[strlen(_name)+1];
  32.         strcpy_s(name, (strlen(_name)+1), _name);
  33.     }
  34.     void setPrice(double _price){
  35.         price = _price;
  36.     }
  37.     void setTime(double _time){
  38.         time = _time;
  39.     }
  40.     virtual double getPrice()const{
  41.         return price;
  42.     }
  43.     virtual double getTime()const{
  44.         return time;
  45.     }
  46.     const char* getName()const{
  47.         return name;
  48.     }
  49.     virtual void print()const;
  50. };
  51.  
  52.  
  53. class Pack{
  54. private:
  55.     Test** t;
  56.     int size_t;
  57. public:
  58.     Pack(const char*);
  59.     ~Pack();
  60.     virtual double getPrice()const;
  61.     virtual double getTime()const;
  62.     virtual void print()const;
  63.     void addTest(const Test&);
  64.  
  65.  
  66. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement