teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

ソート内容が表示されないのでソート1種類のみの記載に変更しました。

2020/07/09 23:10

投稿

741s
741s

スコア5

title CHANGED
File without changes
body CHANGED
@@ -8,18 +8,17 @@
8
8
 
9
9
  ### 出力結果
10
10
  ```ここに言語を入力
11
+ ファイル読み込み:1 終了:0  :
11
- ファイル読み込み:1 終了:0  :Mami h567 60.0 80.0 70.0
12
+ Mami h567 60.0 80.0 70.0
12
13
  Momo h878 80.0 90.0 70.0
13
14
  Kinoshita h698 90.0 60.0 70.0
14
- ファイル読み込み:1 終了:0  :各順にソートしますか? はい:1 いいえ:2  :どのデータによってソートしますか? 名前:1 学籍番号:2 数学:3 英語:4 物理:5  :昇順と降順どちらでソートしますか? 昇順:1 降順:2  :
15
+ Koko h767 80.0 80.0 80.0
15
- 数学の得点を昇順にソートしました。
16
+ ファイル読み込み:1 終了:0  :
16
- 各順にソートしますか? はい:1 いいえ:2  :どのデータによってソートしますか? 名前:1 学籍番号:2 数学:3 英語:4 物理:5  :昇順と降順どちらでソートしますか? 昇順:1 降順:2  :
17
- 数学の得点を昇順にソートしました。
18
17
  ```
19
18
 
20
19
  ### ソースコード
21
20
  ```ここに言語を入力
22
- *成績管理システム*/
21
+ /*成績管理システム*/
23
22
  #include<stdio.h>
24
23
  #include<string.h>
25
24
  #include<math.h>
@@ -44,6 +43,7 @@
44
43
  *y = temp;
45
44
  }
46
45
 
46
+
47
47
  /*数学の得点順にソート*/
48
48
  void sort_by_math1(Student a[],int n) //昇順
49
49
  {
@@ -56,18 +56,6 @@
56
56
  }
57
57
  }
58
58
 
59
- void sort_by_math2(Student a[],int n) //降順
60
- {
61
- int i,j;
62
-
63
- for(i = 0;i < n - 1;i++){
64
- for(j = n - 1;j > i;j--)
65
- if(a[j-1].math < a[j].math)
66
- swap_Student(&a[j - 1],&a[j]);
67
- }
68
- }
69
-
70
-
71
59
  /*ファイルの読み込み*/
72
60
  int out_file(Student a[])
73
61
  {
@@ -88,98 +76,26 @@
88
76
 
89
77
  int main(void)
90
78
  {
91
- int a,b,c,d;
92
79
  int flag=0;
93
80
  int i=0;
94
81
  int cnt=0;
95
82
  Student human[40];
96
-
97
83
 
98
84
  do{
99
- printf("ファイル読み込み:1 終了:0  :");
85
+ printf("ファイル読み込み:1 終了:0  :\n");
100
86
  scanf("%d",&flag);
101
87
  if(flag==1)
102
88
  out_file(human);
103
89
  }while(flag!=0);
104
-
105
90
 
106
- do{
107
- printf("各順にソートしますか? はい:1 いいえ:2  :");
108
- scanf("%d",&b);
109
- if(a==1){
110
- printf("どのデータによってソートしますか? 名前:1 学籍番号:2 数学:3 英語:4 物理:5  :");
111
- scanf("%d",&c);
112
- printf("昇順と降順どちらでソートしますか? 昇順:1 降順:2  :");
113
- scanf("%d",&d);
114
-
115
-
116
- if(c==1&d==1){
117
- puts("\n名前を昇順にソートしました。");
118
- sort_by_name1(human,cnt);
91
+ sort_by_math1(human,cnt);
119
92
  for(i=0;i<cnt;i++)
120
93
  printf("%-10s %-10s %5.1f %5.1f %5.1f\n",human[i].name,human[i].number,human[i].math,human[i].eng,human[i].phy);
121
- }
94
+
122
- if(c==1&d==2){
123
- puts("\n名前を降順にソートしました。");
124
- sort_by_name2(human,cnt);
125
- for(i=0;i<cnt;i++)
126
- printf("%-10s %-10s %5.1f %5.1f %5.1f\n",human[i].name,human[i].number,human[i].math,human[i].eng,human[i].phy);
127
- }
128
- if(c==2&d==1){
129
- puts("\n学籍番号を昇順にソートしました。");
130
- sort_by_number1(human,cnt);
131
- for(i=0;i<cnt;i++)
132
- printf("%-10s %-10s %5.1f %5.1f %5.1f\n",human[i].name,human[i].number,human[i].math,human[i].eng,human[i].phy);
133
- }
134
- if(c==2&d==2){
135
- puts("\n学籍番号を降順にソートしました。");
136
- sort_by_number2(human,cnt);
137
- for(i=0;i<cnt;i++)
138
- printf("%-10s %-10s %5.1f %5.1f %5.1f\n",human[i].name,human[i].number,human[i].math,human[i].eng,human[i].phy);
139
- }
140
- if(c==3&d==1){
141
- puts("\n数学の得点を昇順にソートしました。");
142
- sort_by_math1(human,cnt);
143
- for(i=0;i<cnt;i++)
144
- printf("%-10s %-10s %5.1f %5.1f %5.1f\n",human[i].name,human[i].number,human[i].math,human[i].eng,human[i].phy);
145
- }
146
- if(c==3&d==2){
147
- puts("\n数学の得点を降順にソートしました。");
148
- sort_by_math2(human,cnt);
149
- for(i=0;i<cnt;i++)
150
- printf("%-10s %-10s %5.1f %5.1f %5.1f\n",human[i].name,human[i].number,human[i].math,human[i].eng,human[i].phy);
151
- }
152
- if(c==4&d==1){
153
- puts("\n英語の得点を昇順にソートしました。");
154
- sort_by_eng1(human,cnt);
155
- for(i=0;i<cnt;i++)
156
- printf("%-10s %-10s %5.1f %5.1f %5.1f\n",human[i].name,human[i].number,human[i].math,human[i].eng,human[i].phy);
157
- }
158
- if(c==4&d==2){
159
- puts("\n英語の得点を降順にソートしました。");
160
- sort_by_eng2(human,cnt);
161
- for(i=0;i<cnt;i++)
162
- printf("%-10s %-10s %5.1f %5.1f %5.1f\n",human[i].name,human[i].number,human[i].math,human[i].eng,human[i].phy);
163
- }
164
- if(c==5&d==1){
165
- puts("\n物理の得点を昇順にソートしました。");
166
- sort_by_phy1(human,cnt);
167
- for(i=0;i<cnt;i++)
168
- printf("%-10s %-10s %5.1f %5.1f %5.1f\n",human[i].name,human[i].number,human[i].math,human[i].eng,human[i].phy);
169
- }
170
- if(c==5&d==2){
171
- puts("\n物理の得点を降順にソートしました。");
172
- sort_by_phy2(human,cnt);
173
- for(i=0;i<cnt;i++)
174
- printf("%-10s %-10s %5.1f %5.1f %5.1f\n",human[i].name,human[i].number,human[i].math,human[i].eng,human[i].phy);
175
- }
176
- }
177
-
178
-
179
- }while(b!=2);
180
- return 0;
95
+ return 0;
96
+
97
+
181
98
  }
182
-
183
99
  ```
184
100
 
185
101
  ### 補足