運動会のスコア統計
30970 ワード
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class School //
{
private:
char name[20];
int number;
int boy;
int girl;
public:
School *next;
void School_add();
void School_sort();
// int School_getlong(School *first);
void School_output(School *p);
int School_isexist(int a);
void School_show(int a);
void School_search(int a);
void School_addmark(int a, int b, int c);
void School_order(School *temp, int type);
};
class Sport //
{
private:
char name[20];
int isboy; //0 ,1
int is3; //0 ,1
int number; //
int first; //
int second; //
int third; //
int fourth; //
int fifth; //
public:
Sport *next;
int Sport_isexist(int a);
void Sport_add();
// int Sport_getlong(Sport *first);
void Sport_output(Sport *p);
void Sport_search(int a);
};
School* head1;
Sport* head2;
void School::School_add()
{
School* p;
int mark = 0;
p = new School;
cout << " :";
cin >> p->name;
int c;
while (mark != 1)
{
cout << " :";
cin >> c;
p->number = c;
mark = 1;
p->boy = 0;
p->girl = 0;
p->next = head1->next;
head1->next = p;
cout << " " << endl;
cout << " ?(y/n)" << endl;
char input;
cin >> input;
switch (input)
{
case 'y':
mark = 0;
School_add();
case 'n':
mark = 1;
return;
}
}
delete p;
}
void School::School_output(School* p)//
{
cout << " ( ) \t
";
// School *p;
p = head1;
p = p->next;
while (p)
{
cout << p->name << "\t\t" << p->number << "\t"
<< p->boy << "\t" << p->girl << " \t " << (p->girl + p->boy) << endl;
p = p->next;
}
}
int School::School_isexist(int a)
{
int b = 0;
School* p;
p = head1;
p = p->next;
while (p)
{
if (p->number == a)
{
return 1;
}
p = p->next;
}
return 0;
}
void School::School_show(int a)//
{
School *p;
p = head1;
p = p->next;
while (p)
{
if (p->number == a)
{
cout << p->name << " " << endl;
return;
}
p = p->next;
}
cout << " ";
}
void School::School_search(int a)
{
School* p;
p = head1;
p = p->next;
while (p)
{
if (p->number == a)
{
cout << " :" << p->name << " " << " :" << p->boy << " "
<< " :" << p->girl << " " << " :" << (p->boy + p->girl) << " ";
return;
}
p = p->next;
}
cout << " :" << endl;
}
void School::School_addmark(int a, int b, int c) //a ,b ,c=1 ,c=0
{
School* p;
p = head1;
p = p->next;
while (p)
{
if (p->number == b)
{
if (c == 1)
{
p->boy = p->boy + a;
}
else
{
p->girl = p->girl + a;
}
}
p = p->next;
}
}
void School::School_sort() // 。 , 。
{
School* q, *small;
School* temp1;
temp1 = new School;
temp1->next = NULL;
q = head1;
q = q->next;
small = head1;
small = small->next;
temp1->girl = q->girl;
q->girl = small->girl;
small->girl = temp1->girl;
temp1->boy = q->boy;
q->boy = small->boy;
small->boy = temp1->boy;
strcpy_s(temp1->name, q->name);
strcpy_s(q->name, small->name);
strcpy_s(small->name, temp1->name);
temp1->number = q->number;
q->number = small->number;
small->number = temp1->number; //
}
// , 。
// 4 School_sort()。 , 。
void School::School_order(School *temp, int type)
{
//type=0 ,type=1 ,type=2 ,type=3
School* q=NULL, *small=NULL;
School* temp1;
School sh;
temp1 = new School;
temp1->next = NULL;
while (q&&small)
{
switch (type)
{
case 0: //
for (q = head1; q = q->next; q != NULL)
for (small = head1; small = small->next; small != NULL)
{
if ((q->boy + q->girl)boy + small->girl))
{
sh.School_sort(); // School_sort(), 。
}
}
break;
case 1: //
for (q = head1; q = q->next; q != NULL)
for (small = head1; small = small->next; small != NULL)
{
if (q->boyboy)
{
sh.School_sort(); // School_sort(),
}
}
break;
case 2: //
for (q = head1; q = q->next; q != NULL)
for (small = head1; small = small->next; small != NULL)
{
if (q->girlgirl)
{
sh.School_sort(); // School_sort(),
}
}
break;
case 3:
for (q = head1; q = q->next; q != NULL)
for (small = head1; small = small->next; small != NULL)
{
if (q->numbernumber)
{
sh.School_sort(); // School_sort(),
}
}
break;
default:
cout << "error" << endl;
break;
}
}
}
int Sport::Sport_isexist(int a)
{
int b = 0;
Sport* p;
p = head2;
while (p)
{
if (p->number == a)
{
return 1;
}
p = p->next;
}
return 0;
}
void Sport::Sport_add()
{
Sport* p;
// School sh;
int mark = 0;
p = new Sport;
cout << " :";
cin >> p->name;
int c;
while (mark != 1)
{
cout << " :";
cin >> c;
if (Sport_isexist(c))
{
cout << " !";
}
else
{
mark = 1;
p->number = c;
}
}
mark = 0;
while (mark != 1)
{
cout << " (0 ,1 ):";
cin >> c;
// p->isboy=(int)(c-'0');//
mark = 1;
p->isboy = c;
}
mark = 0;
while (mark != 1)
{
cout << " (0 3 ,1 5 ):";
cin >> c;
// p->is3=(int)(c-'0');
mark = 1;
p->is3 = c;
}
mark = 0;
School sh;
while (mark != 1)
{
cout << " :";
cin >> c;
if (!sh.School_isexist(c))
{
cout << " , !";
}
else
{
mark = 1;
p->first = c;
if (p->is3 == '0')
sh.School_addmark(5, c, p->isboy);
else
sh.School_addmark(7, c, p->isboy);
}
}
mark = 0;
while (mark != 1)
{
cout << " :";
cin >> c;
if (!sh.School_isexist(c))
{
cout << " , !";
}
else
{
mark = 1;
p->second = c;
if (p->is3 == '0')
sh.School_addmark(3, c, p->isboy);
else
sh.School_addmark(5, c, p->isboy);
}
}
mark = 0;
while (mark != 1)
{
cout << " :";
cin >> c;
if (!sh.School_isexist(c))
{
cout << " , ";
}
else
{
mark = 1;
p->third = c;
if (p->is3 == '0')
sh.School_addmark(2, c, p->isboy);
else
sh.School_addmark(3, c, p->isboy);
}
}
mark = 0;
if (p->is3 == '1')
{
while (mark != 1)
{
cout << " :";
cin >> c;
if (!sh.School_isexist(c))
{
cout << " , ";
}
else
{
mark = 1;
p->fourth = c;
sh.School_addmark(2, c, p->isboy);
}
}
mark = 0;
while (mark != 1)
{
cout << " :";
if (!sh.School_isexist(c))
{
cout << " , !";
}
else
{
mark = 1;
p->fifth = c;
sh.School_addmark(1, c, p->isboy);
}
}
}
else
{
p->fourth = '0';
p->fifth = '0';
}
p->next = head2->next;
head2->next = p;
cout << " " << endl;
}
void Sport::Sport_output(Sport *p) //
{
p = head2;
p = p->next;
cout << " " << "\t" << " " << " " << "B/G" << " " << "3/5" << " " << " " << " "
<< " " << " " << " " << " " << " " << " " << " " << " " << endl;
School sh;
while (p)
{
cout << p->name << "\t" << " " << p->number << " " << p->isboy << " " << p->is3 << " "
<< " ";
sh.School_show(p->first);
sh.School_show(p->second);
sh.School_show(p->third);
sh.School_show(p->fourth);
sh.School_show(p->fifth);
p = p->next;
cout << "
";
}
cout << endl;
}
void Sport::Sport_search(int a) //
{
Sport *p;
School sh;
p = head2;
p = p->next;
while (p)
{
if (p->number == a)
{
cout << " :" << p->name << endl << " :";
if (p->isboy == 1)
{
cout << " ";
}
else
{
cout << " ";
}
cout << endl << " :";
sh.School_show(p->first);
cout << endl << " :";
sh.School_show(p->second);
cout << endl << " :";
sh.School_show(p->third);
cout << endl << " :";
sh.School_show(p->fourth);
cout << endl << " :";
sh.School_show(p->fifth);
return;
}
p = p->next;
}
cout << " ";
}
void main()
{
system("color C");
head1 = new School;
head1->next = NULL;
head2 = new Sport;
head2->next = NULL;
//school_add();
School sh;
Sport sp;
School* p1;
Sport* p2;
p1 = head1;
p1 = p1->next;
p2 = head2;
p2 = p2->next;
int choose;
char temp;
int a = 1;
while (a != 0)
{
cout << " " << endl;
cout << " " << endl;
cout << " ----------------------------------------------------------" << endl;
cout << " -----July /05/18---- " << endl;
cout << " " << endl;
cout << " 1. ; 2. " << endl;
cout << " 3. ; 4. ; " << endl;
cout << " 5. ; 6. ; " << endl;
cout << " 7. ; 8. ; " << endl;
cout << " 0. " << endl;
cout << " : " << endl;
cout << " ----------------------------------------------------------" << endl;
cout << " ------- (0-8):------ " << endl;
cin >> choose;
switch (choose)
{
case 1:
sh.School_add();
break;
case 2:
sp.Sport_output(p2);
sh.School_output(p1);
sp.Sport_add();
break;
case 3:
sh.School_order(p1, 3);
sh.School_output(p1);
break;
case 4:
sh.School_order(p1, 0);
sh.School_output(p1);
break;
case 5:
sh.School_order(p1, 1);
sh.School_output(p1);
break;
case 6:
sh.School_order(p1, 2);
sh.School_output(p1);
break;
case 7:
cout << " :";
cin >> temp;
sh.School_search(temp);
break;
case 8:
cout << " :";
cin >> temp;
sp.Sport_search(temp);
break;
case 0:
a = 0;
break;
default:
cout << "
";
}
}
system("exit");
}