2008. 8. 29. 15:57

product

#ifndef _PRODUCT_H_
#define _PRODUCT_H_
#include"date.h"

class Product:public Date
{
public:
 Product(char *pN, char *fN, int _price, int _year, int _month, int _day);
 ~Product();
 void OutProduct()const;
 Product(const Product &pro) ;
private:
 char *p_name;
 char *f_name;
 int price;
};

#endif
--

//#include"date.h"
#include"product.h"
#include<iostream>

using std::cout;
using std::endl;

Product::Product(char *pN, char *fN, int _price, int _year, int _month, int _day):Date(_year, _month,_day)
{
 p_name = new char[strlen(pN)+1];
 strcpy(p_name,pN);
 f_name = new char[strlen(fN)+1];
 strcpy(f_name,fN);
 price = _price;
}
Product::~Product()
{
 delete []p_name;
 delete []f_name;
}
void Product::OutProduct()const
{
 cout<<"\t\t******** 상품정보 ******** "<<endl;
 cout<<"상품명 : "<<p_name<<endl;
 cout<<"제조사 : "<<f_name<<endl;
 cout<<"가  격 : "<<price<<endl;
 cout<<"제조 년/월/일 : "<<GetYear()<<'/'<<GetMonth()<<'/'<<GetDay()<<'/'<<endl;
}
Product::Product(const Product &pro) : Date(pro.GetYear(), pro.GetMonth(), pro.GetDay())
{// Date(pro)
 p_name = new char[strlen(pro.p_name)+1];
 strcpy(p_name,pro.p_name);
 f_name= new char[strlen(pro.f_name)+1];
 strcpy(f_name,pro.f_name);
 
 price= pro.price;
}

--

#ifndef _DATE_H_
#define _DATE_H_

class Date
{
public:
 Date(int _year, int _month, int _day);
 int GetYear()const;
 int GetMonth()const;
 int GetDay()const;
private:
 int year, month, day;
};

#endif


--

#include"date.h"

Date::Date(int _year, int _month, int _day)
{
 year=_year;
 month=_month;
 day=_day;
}
int Date::GetYear()const
{
 return year;
}
int Date::GetMonth()const
{
 return month;
}
int Date::GetDay()const
{
 return day;
}


--





#include<iostream>
#include"date.h"
#include"product.h"

int main()
{

 Product p("새우깡","농심",700,2005,3,4);
 Product p1("새우깡","농심",700,2005,3,4);
 Product p2 =p1;
 
 p.OutProduct();
 p1.OutProduct();
 p2.OutProduct();
 
 return 0;
}