ADD file via upload

main
pv7g39eqr 1 year ago
parent 99d098c39b
commit 767da5ec68

156
8.cpp

@ -0,0 +1,156 @@
#include<stdio.h>
#include<string.h>
void Menu()
{
printf("1.input\n");
printf("2.delete\n");
printf("3.select\n");
printf("4.order\n");
printf("5.output\n");
printf("6.quit\n");
printf("please input your option\n");
}
struct Info
{
char num[6], name[7];
int cls;
float math, phy, eng, sum;
}arr[4], ins, mod;
void Input(int i)
{
void Option();
printf("id ");
scanf("%s", arr[i].num);
printf("class ");
scanf("%d", &arr[i].cls);
printf("name ");
scanf("%s", arr[i].name);
printf("score1 ");
scanf("%f", &arr[i].math);
printf("score2 ");
scanf("%f", &arr[i].phy);
printf("score3 ");
scanf("%f", &arr[i].eng);
arr[i].sum = arr[i].math + arr[i].phy + arr[i].eng;
printf("continue?\n");
char yon[4];
scanf("%s", yon);
if (strcmp(yon, "yes") == 0)
Input(i + 1);
else
Option();
}
void Output(int i)
{
printf("%s ", arr[i].num);
printf("%d ", arr[i].cls);
printf("%s ", arr[i].name);
printf("%.1f %.1f %.1f ", arr[i].math, arr[i].phy, arr[i].eng);
printf("%.1f", arr[i].sum);
printf("\n");
}
void Rank(int s)
{
for (int i = 0; i < s; i++)
for (int j = s - 1; j > i; j--)
{
if (arr[j].cls < arr[j - 1].cls)
{
struct Info temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
for (int i = 0; i < s; i++)
for (int j = s - 1; j > 0; j--)
{
if (arr[j].cls == arr[j - 1].cls && arr[j].sum > arr[j - 1].sum)
{
struct Info temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
}
void Del(int* p)
{
void Option();
char str[7];
scanf("%s", str);
for (int i = 0; i < *p; i++)
{
if (strcmp(str, arr[i].num) == 0 || strcmp(str, arr[i].name) == 0)
{
for (int j = i + 1; j < *p; j++)
arr[j - 1] = arr[j];
(*p)--;
}
}
for (int j = 0; j < *p; j++)
Output(j);
printf("continue?\n");
char yon[4];
scanf("%s", yon);
if (strcmp(yon, "yes") == 0)
Del(p);
else
Option();
}
void Find(int s)
{
void Option();
char n[6];
scanf("%s", n);
int l = strlen(n);
if (l > 2)
{
for (int i = 0; i < s; i++)
if (strcmp(arr[i].num, n) == 0)
Output(i);
}
else
{
int c = 10 * (n[0] - '0') + n[1] - '0';
for (int i = 0; i < s; i++)
if (arr[i].cls == c)
Output(i);
}
char yon[4];
scanf("%s", yon);
if (strcmp(yon, "yes") == 0)
Find(s);
else
Option();
}
void Option()
{
Menu();
int c;
scanf("%d", &c);
int s = 3;
int* p = &s;
switch (c)
{
case 1:Input(0); break;
case 2:Del(p); break;
case 3:Find(s); break;
case 4: {
Rank(s);
for (int i = 0; i < s; i++)
Output(i);
Option();
break;
}
case 5: {
for (int i = 0; i < s; i++)
Output(i);
Option();
break;
}
case 6:break;
}
}
int main()
{
Option();
}
Loading…
Cancel
Save