[[연습문제 1]]
>>Phone.h<<
#ifndef _PHONE_H_
#define _PHONE_H_
class Phone
{
public:
Phone(char *PM, char *PC, int PCH);
~Phone();
public:
//Return func
char * Getmodel() const;
char * Getcompany() const;
int Getchord() const;
protected:
char *model;
char *company;
int chord;
private:
};
#endif
>>CameraPhone.h<<
#ifndef _CAMERAPHONE_H_
#define _CAMERAPHONE_H_
#include "Phone.h"
class CameraPhone : public Phone
{
public:
CameraPhone(char *PM, char *PC, int PCH, char *_pix);
~CameraPhone();
char * Getpixel() const;
protected:
private:
char *pix;
};
#endif
>>MP3Phone.h<<
#ifndef _MP3PHONE_H_
#define _MP3PHONE_H_
#include "Phone.h"
class MP3Phone : public Phone
{
public:
MP3Phone(char *PM, char *PC, int PCH, char *_play);
~MP3Phone();
char * Getplayer() const;
protected:
private:
char *player;
};
#endif
>>main.cpp<<
#include <iostream>
#include <iomanip>
#include "CameraPhone.h"
#include "MP3Phone.h"
using std::endl; using std::setw;
using std::cout;
using std::left;
int main()
{
CameraPhone ca("EV-W7600", "SAMSUNG", 60, "500만 화소");
MP3Phone mp("QMT-AB12", "LG", 120, "Player");
cout << left;
cout << setw(20) << "모델명" << setw(20) << "제조사" << setw(10) << "화음"
<< setw(20) << "특징" << endl;
cout << setw(20) << ca.Getmodel() << setw(20) << ca.Getcompany() << setw(10) << ca.Getchord()
<< setw(20) << ca.Getpixel() << endl;
cout << setw(20) << mp.Getmodel() << setw(20) << mp.Getcompany() << setw(10) << mp.Getchord()
<< setw(20) << mp.Getplayer() << endl;
return 0;
}
>>Phone.cpp<<
#include "Phone.h"
#include <string.h>
Phone::Phone(char *PM, char *PC, int PCH)
{
model = new char[strlen(PM)+1];
strcpy(model, PM);
company = new char[strlen(PC)+1];
strcpy(company, PC);
chord = PCH;
}
Phone::~Phone()
{
delete [] model;
delete [] company;
}
char * Phone::Getmodel() const
{
return model;
}
char * Phone::Getcompany() const
{
return company;
}
int Phone::Getchord() const
{
return chord;
}
>>CameraPhone.cpp<<
#include "CameraPhone.h"
#include <string.h>
CameraPhone::CameraPhone(char *PM, char *PC, int PCH, char *_pix): Phone(PM,PC,PCH)
{
pix = new char[strlen(_pix)+1];
strcpy(pix, _pix);
}
CameraPhone::~CameraPhone()
{
delete []pix;
}
char * CameraPhone::Getpixel() const
{
return pix;
}
>>MP3Phone.cpp<<
#include "MP3Phone.h"
#include <string.h>
MP3Phone::MP3Phone(char *PM, char *PC, int PCH, char *_play): Phone(PM,PC,PCH)
{
player = new char[strlen(_play)+1];
strcpy(player, _play);
}
MP3Phone::~MP3Phone()
{
delete []player;
}
char * MP3Phone::Getplayer() const
{
return player;
}