ํด๋ ํ์ผ ¶
Data.h ¶
~cpp
// Data.h
#ifndef _DATA_H_
#define _DATA_H_
class Data{
private:
char name[20];
int number;
int kor;
int eng;
int math;
int total;
double ave;
char grade[2];
public:
Data();
Data(char na[], int nu, int k, int e, int m);
int showNumber(int select);
char * showName();
int showNum();
int showTotal();
double showAve();
};
#endif
Judgement.h ¶
~cpp
//Judgement.h
#ifndef _JUDGEMENT_H_
#define _JUDGEMENT_H_
#include "Data.h"
#include "Order.h"
class Judgement{
private:
int tempData;
int tempNumber;
int stData[20];
int arrayNumber[20];
public:
Judgement();
void sort(bool IsItSort , int select , Data d[]);
void outputAll(bool IsItAll, Data d[]);
void outputPart(bool IsItPart, Data d[] , int select);
};
#endif
Order.h ¶
~cpp
//Order.h
#ifndef _ORDER_H_
#define _ORDER_H_
class Order{
private:
int mainmenu;
int submenu;
public:
Order();
void menu();
bool IsItAll();
bool IsItSort();
int subNumber();
};
#endif
ํด๋์ค ์ ๋ ฅ ¶
Data.cpp ¶
~cpp
// Data.cpp
#include <iostream>
using namespace std;
#include "Data.h"
Data::Data()
{
}
Data::Data(char na[], int nu, int k, int e , int m)
{
strcpy(name, na);
number = nu;
kor = k;
eng = e;
math = m;
total = k + e + m;
ave = (double)total/3;
for (int i = 0 ; i <= 19 ; i++ )
{
if ( ave >= 95 && ave <=100)
strcpy(grade,"a+");
else if ( ave >= 90 && ave < 95)
strcpy(grade,"a");
else if ( ave >= 85 && ave < 90)
strcpy(grade,"b+");
else if ( ave >= 80 && ave < 85)
strcpy(grade,"b");
else if ( ave >= 75 && ave < 80)
strcpy(grade,"c+");
else if ( ave >= 70 && ave < 75)
strcpy(grade,"c");
else if ( ave >= 65 && ave < 70)
strcpy(grade,"d+");
else if ( ave >= 60 && ave < 65)
strcpy(grade,"d");
else if ( ave <= 59)
strcpy(grade,"f");
}
}
int Data::showNumber(int select)
{
if (select == 1 )
return kor;
else if (select == 2 )
return eng;
else if (select == 3 )
return math;
else
return 0;
}
char * Data::showName()
{
return name;
}
int Data::showNum()
{
return number;
}
int Data::showTotal()
{
return total;
}
double Data::showAve()
{
return ave;
}
Judgement.cpp ¶
~cpp
//Judgement.cpp
#include <iostream>
using namespace std;
#include "Judgement.h"
#include "Data.h"
#include "Order.h"
Judgement::Judgement()
{
for (int i = 0 ; i <= 19 ; i++)
arrayNumber[i] = i;
}
void Judgement::sort(bool IsItSort , int select , Data d[]) // ์ํธ ๋ถ๋ถ
{
if (IsItSort)
{
if ( select == 0 )
for (int k = 0 ; k <= 19 ; k++) //
stData[k] = d[k].showTotal(); //
else // ์๋ง๋ ๋ฐ์ดํฐ ๊ฐ ์นดํผ
for (int k = 0 ; k <= 19 ; k++) //
stData[k] = d[k].showNumber(select); //
for (int i = 0 ; i <= 19 ; i++) {
for (int j = i+1 ; j <= 19 ; j++) {
if ( stData[i] < stData[j] ) {
tempData = stData[i];
tempNumber = arrayNumber[i];
stData[i] = stData[j];
arrayNumber[i] = arrayNumber[j];
stData[j] = tempData;
arrayNumber[j] = tempNumber;
} } } // ์ํธ
}
}
void Judgement::outputAll(bool IsItAll, Data d[])
{
if (IsItAll)
{
cout << "์ด๋ฆ\t๋ฒํธ\t\t๊ตญ์ด\t์์ด\t์ํ\t์ด์ \tํ๊ท " << endl;
for (int i = 0 ; i <= 19 ; i++){
cout << d[arrayNumber[i]].showName()
<< "\t" << d[arrayNumber[i]].showNum()
<< "\t" << d[arrayNumber[i]].showNumber(1)
<< "\t" << d[arrayNumber[i]].showNumber(2)
<< "\t" << d[arrayNumber[i]].showNumber(3)
<< "\t" << d[arrayNumber[i]].showTotal()
<< "\t" << d[arrayNumber[i]].showAve()
<< endl;
}
cin.get();
cin.get();
}
}
void Judgement::outputPart(bool IsItPart, Data d[] , int select)
{
if (IsItPart)
{
cout << "์ด๋ฆ\t๋ฒํธ\t";
if ( select == 1 )
cout << "\t๊ตญ์ด" << endl;
else if ( select == 2 )
cout << "\t์์ด" << endl;
else if ( select == 3 )
cout << "\t์ํ" << endl;
for (int i = 0 ; i <= 19 ; i++){
cout << d[arrayNumber[i]].showName()
<< "\t" << d[arrayNumber[i]].showNum()
<< "\t" << d[arrayNumber[i]].showNumber(select)
<< endl;
}
cin.get();
cin.get();
}
}
Order.cpp ¶
~cpp
//Order.cpp
#include <iostream>
using namespace std;
#include "Order.h"
Order::Order()
{
submenu = 0;
}
bool Order::IsItAll()
{
if (mainmenu == 3 || mainmenu == 4)
return true;
else
return false;
}
bool Order::IsItSort()
{
if (mainmenu == 2 || mainmenu == 4)
return true;
else
return false;
}
void Order::menu()
{
system("cls");
cout << "\tโ ๋ฉ๋ด โ" << endl
<< "1) ๊ณผ๋ชฉ๋ณ ์
๋ ฅ ๊ฒฐ๊ณผ ๋ฆฌ์คํธ " << endl
<< "2) ๊ณผ๋ชฉ๋ณ ์ฑ์ ์ ๋ฆฌ์คํธ " << endl
<< "3) ํ์ ์ ๊ณผ๋ชฉ ์
๋ ฅ ๊ฒฐ๊ณผ ๋ฆฌ์คํธ " << endl
<< "4) ํ์ ์ ๊ณผ๋ชฉ ์ฑ์ ์ ๋ฆฌ์คํธ " << endl
<< "5) ์ข
๋ฃ " << endl << endl
<< "๋ฉ๋ด๋ฅผ ์ ํํ์ธ์ -> ";
cin >> mainmenu;
if (mainmenu == 5)
exit(1);
if (mainmenu == 1 || mainmenu == 2)
{
system("cls");
cout << "\tโ๊ณผ๋ชฉ ์ ํ ๋ฉ๋ดโ" << endl
<< "1) ๊ตญ์ด" << endl
<< "2) ์์ด" << endl
<< "3) ์ํ" << endl
<< "๊ณผ๋ชฉ์ ์ ํํ์ธ์ -> ";
cin >> submenu;
}
}
int Order::subNumber()
{
return submenu;
}
๋ฉ์ธ ํจ์ ¶
~cpp
#include <iostream>
using namespace std;
#include "Data.h"
#include "Judgement.h"
#include "Order.h"
Data data[] = {
Data( "๊ณ ์ฌ์ " ,20025301, 85, 90, 80 ),
Data( "๊ถํ์ง" ,20025302, 80, 88, 85 ),
Data( "๊น๋์ฑ" ,20025303, 88, 93, 75 ),
Data( "๊น๋ฌด์" ,20025309, 75, 85, 70 ),
Data( "๊น๋ฏผ์ฌ" ,20025307, 73, 83, 77 ),
Data( "๊น์ฑ์" ,20025304, 95, 88, 80 ),
Data( "๊น์์ค" ,20025308, 95, 88, 80 ),
Data( "๊น์ค์ญ" ,20025305, 94, 70, 65 ),
Data( "๊น์ฒ ํธ" ,20025306, 80, 75, 88 ),
Data( "๊นํ์" ,20025310, 65, 73, 94 ),
Data( "๊นํ์" ,20025313, 77, 78, 99 ),
Data( "๊นํฌ๊ท " ,20025312, 80, 77, 85 ),
Data( "๋ฅ์ฌํ" ,20025311, 95, 80, 95 ),
Data( "๋ฌธ๊ตฌ๋ด" ,20025315, 78, 90, 75 ),
Data( "๋ฐ๋์" ,20025314, 90, 95, 65 ),
Data( "๋ฐ์ธ์ฐ" ,20025316, 88, 88, 80 ),
Data( "๋ฐ์ค์ฑ" ,20025317, 83, 76, 75 ),
Data( "์์์" ,20025318, 75, 68, 70 ),
Data( "์๋ฏผ์ฐ" ,20025319, 65, 70, 80 ),
Data( "์์ ์" ,20025320, 88, 85, 90 )
};
int main()
{
while (1)
{
Judgement judgement;
Order order;
order.menu();
judgement.sort(order.IsItSort(), order.subNumber(), data);
judgement.outputAll(order.IsItAll(), data);
judgement.outputPart(!(order.IsItAll()), data, order.subNumber());
}
return 0;
}










