>>Student.h<<
#ifndef _STUDENT_H_
#define _STUDENT_H_
class Student{
public:
Student(char *pN, char *pP, char *pA, int _age);
~Student();
void Output()const;
private:
char Cname[20], Cphone[20];
char *Caddress;
int Cage;
};
#endif
>>main.cpp<<
#include <iostream>
#include "Student.h"
using std::cin; using std::cout; using std::endl;
int main()
{
char name[20], phone[20];
char address[40];
int age;
cout << "** 학생정보 입력 **\n";
cout << "\n이 름 : ";
fflush(stdin);
cin.getline(name, 20);
cout << "전화번호 : ";
fflush(stdin);
cin.getline(phone, 20);
cout << "주 소 : ";
cin.getline(address, 500);
cout << "나 이 : ";
cin >> age;
Student inf(name, phone, address, age);
inf.Output();
return 0;
}
>>Student.cpp<<
#include <iostream>
#include "Student.h"
#include <string.h>
#include <iomanip>
using std::cin; using std::cout; using std::endl; using std::setw;
Student::Student(char *pN, char *pP, char *pA, int _age)
{
strcpy(Cname, pN);
strcpy(Cphone, pP);
Caddress = NULL;
Caddress = new char[strlen(pA)+1];
strcpy(Caddress, pA);
Cage = _age;
}
Student::~Student()
{
delete [] Caddress;
}
void Student::Output()const
{
cout << "\n\n\n\t\t*** 학생정보 출력 ***\n\n\n";
cout << "이름" << setw(10) << "전화번호" << setw(10) << "주소" << setw(40) << "나이\n";
for(int i=0; i<=70; i++)
{
cout << "-";
}
cout << endl << Cname << setw(10) << Cphone << setw(10) << Caddress << setw(40) << Cage << endl;
}