==헤더파일==
~cpp
class SungJuk //클래스를 선언합니다.
{
private:
char m_szName[30]; //이름입니다.
int m_nNumber, m_nKorean, m_nEnglish, m_nMath;
//번호,국어,영어,수학 점수를 나타냅니다.
int m_nTotal; //점수 합계를 나타냅니다.
double m_dAvg; //평균을 나타냅니다.
public:
SungJuk(); //디폴트 생성자입니다.
SungJuk(const char *name,int nNumber, int nKorean, int nEnglish, int nMath);
//생성자입니다.
int GetTotal(); //점수합계를 호출하는 매써드입니다.
void PrintResult(); //결과를 출력합니다.
void TopTotal_Print();
void Top_Print(); //전체수석을 출력합니다.
void TopKorean_Print(); //국어점수 수석을 출력합니다.
void TopEnglish_Print(); //영어점수 수석을 출력합니다.
void TopMath_Print(); //수학점수 수석을 출력합니다.
const SungJuk & Top_Avg(const SungJuk &s) const;
const SungJuk & Top_Total(const SungJuk & s) const;
const SungJuk & Top_Korean(const SungJuk & s) const;
const SungJuk & Top_English(const SungJuk & s) const;
const SungJuk & Top_Math(const SungJuk & s) const;
void Input(int nNumber, char szName[], int nKorean, int nEnglish, int nMath);
};
소스파일 ¶
~cpp
#include<iostream>
using namespace std;
#include<iostream> //strcpy()
#include"SungJuk.h"
SungJuk::SungJuk()
{
strcpy(m_szName, "이름없음");
m_nKorean = 0;
m_nEnglish = 0;
m_nMath = 0;
m_nTotal = 0;
m_dAvg = 0.0;
}
int SungJuk::GetTotal()
{
return m_nTotal;
}
void SungJuk::PrintResult()
{
cout<< " " << m_nNumber << "\t" << m_szName<< "\t" << m_nKorean << "\t"
<< m_nEnglish << "\t" << m_nMath << "\t" <<m_nTotal << "\t"
<<m_dAvg << endl;
}
void SungJuk::TopTotal_Print()
{
cout<<"\n 전체수석 " << "\t" << "번 호 : "<< m_nNumber << "\n"
<<"\t\t"<< "이 름 : "<< m_szName << "\n" <<"\t\t"<<"총 점 : "
<< m_nTotal << "\n";
}
void SungJuk::TopKorean_Print()
{
cout<<"\n 국어수석 " << "\t" << "번 호 : "<< m_nNumber << "\n"
<<"\t\t"<< "이 름 : "<< m_szName << endl <<"\t\t"<<"국 어 : "
<< m_nKorean << endl;
}
void SungJuk::TopEnglish_Print()
{
cout<<"\n 영어수석 " << "\t" << "번 호 : "<< m_nNumber << endl
<<"\t\t"<< "이 름 : "<< m_szName << endl <<"\t\t"<<"영 어 : "
<< m_nEnglish << endl;
}
void SungJuk::TopMath_Print()
{
cout<<"\n 수학수석 " << "\t" << "번 호 : "<< m_nNumber << endl
<<"\t\t"<< "이 름 : "<< m_szName << endl <<"\t\t"<<"수 학 : "
<< m_nMath << endl;
}
const SungJuk & SungJuk::Top_Avg(const SungJuk &s) const
{
if (s.m_nTotal > m_nTotal)
return s;
else
return *this;
}
const SungJuk & SungJuk::Top_Korean(const SungJuk &s) const
{
if (s.m_nKorean > m_nKorean)
return s;
else
return *this;
}
const SungJuk & SungJuk::Top_English(const SungJuk &s) const
{
if (s.m_nEnglish > m_nEnglish)
return s;
else
return *this;
}
const SungJuk & SungJuk::Top_Math(const SungJuk &s) const
{
if (s.m_nMath > m_nMath)
return s;
else
return *this;
}
void SungJuk::Input(int nNumber, char szName[], int nKorean, int nEnglish, int nMath)
{
strcpy(m_szName,szName);
m_nNumber = nNumber;
m_nKorean = nKorean;
m_nEnglish = nEnglish;
m_nMath = nMath;
m_nTotal = m_nKorean + m_nEnglish + m_nMath;
m_dAvg = m_nTotal / 3;
}
const int caucse = 10;
void main()
{
SungJuk score[caucse];
score[0].Input(1,"Park",85,93,92);
score[1].Input(2,"kang",96,93,100);
score[2].Input(3,"Jang",87,89,94);
score[3].Input(4,"Jung",86,97,93);
score[4].Input(5,"Shin",94,90,92);
score[5].Input(6,"Lee",89,96,87);
score[6].Input(7,"Kim",98,93,96);
score[7].Input(8,"Min",83,87,82);
score[8].Input(9,"Mun",89,96,92);
score[9].Input(10,"Han",91,99,100);
for(int i=0; i< caucse; i++)
score[i].PrintResult();
}









