请用c语言编写完成如下功能的程序:
请编写完成如下功能的程序:在主函数main()中输出如下形式的菜单:ManagementSystemofScores1.Inputthedata2.Outthedata3...
请编写完成如下功能的程序:
在主函数main()中输出如下形式的菜单:
Management System of Scores
1. Input the data
2. Out the data
3. Sort the data
4. Search one data
5. Exit the System
然后,输出:
Please input your choice:
接收键盘上输入的选择,分别完成输入数据、输出数据、排序数据、查找数据以及结束程序运行的功能。其中前4个功能分别编写函数 input ( ), output ( ), sort ( ), search ( )实现,第5个功能可以通过调用系统函数 exit(0)实现。
先给出十分,如果在这两天之内给我答案再给六十分。很急,拜托大家了 展开
在主函数main()中输出如下形式的菜单:
Management System of Scores
1. Input the data
2. Out the data
3. Sort the data
4. Search one data
5. Exit the System
然后,输出:
Please input your choice:
接收键盘上输入的选择,分别完成输入数据、输出数据、排序数据、查找数据以及结束程序运行的功能。其中前4个功能分别编写函数 input ( ), output ( ), sort ( ), search ( )实现,第5个功能可以通过调用系统函数 exit(0)实现。
先给出十分,如果在这两天之内给我答案再给六十分。很急,拜托大家了 展开
2个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
void input(int arr[], int *length);
void output(int *arr, int length);
void sort(int *arr, int length);
int search(int *arr, int length);
int main(int argc, char* argv[])
{
int score[50] = {100, 89, 86, 90, 78, 89, 67};// Test data
int length = 7;//数组当前有效长度
int i;//choose number
char ch;//
int location = -1;
again:
printf("******Management System of Scores******\n");
printf("1.Input data\n2.Output the data\n3.Sort the data\n%s",
"4.Search the data\n5.Exit the System\n");
scanf("%d", &i);
getchar();//get enter char
switch(i)
{
case 1:
input(score, &length);
break;
case 2:
output(score, length);
break;
case 3:
sort(score, length);
printf("sort finish!\n");
break;
case 4:
location = search(score, length);
if(location < 0)
printf("the number is not exist!\n");
else
printf("location of the number in array is %d \n", location);
break;
case 5:
exit(0);
break;
default:
printf("Error input! Please check again!\n");
break;
}
printf("Again('Y/y' for yes, 'N/n' for no)?\n");
ch = getchar();
if(tolower(ch) == 'y')
goto again;
else
return 0;
}
void input(int arr[], int *length)
{
int insertNumber;
printf("Input number you want to insert:");
scanf("%d", &insertNumber);
getchar();
arr[*length] = insertNumber;
(*length)++;
}
void output(int *arr, int length)
{
int i;
printf("Data:\n");
for(i = 0; i < length-1; i++)
printf("%d, ", arr[i]);
printf("%d\n", arr[i]);
}
void sort(int* arr,int length)
{
int iTemp;
int i, j;
for(i=1;i<=length;i++)
for(j=length-1;j>=i;j--)
{
if(arr[j]<arr[j-1])
{
iTemp=arr[j-1];
arr[j-1]=arr[j];
arr[j]=iTemp;
}
}
}
//如果查找的数在数组中,则返回其在数组中的位置
//否则,返回-1
int search(int *arr, int length)
{
int searchNo;//search number
int i;
printf("Input search number:");
scanf("%d", &searchNo);
getchar();
for(i = length - 1; i >= 0; i--)
{
if(searchNo == arr[i])
break;
}
return i;
}
#include <stdlib.h>
#include <ctype.h>
void input(int arr[], int *length);
void output(int *arr, int length);
void sort(int *arr, int length);
int search(int *arr, int length);
int main(int argc, char* argv[])
{
int score[50] = {100, 89, 86, 90, 78, 89, 67};// Test data
int length = 7;//数组当前有效长度
int i;//choose number
char ch;//
int location = -1;
again:
printf("******Management System of Scores******\n");
printf("1.Input data\n2.Output the data\n3.Sort the data\n%s",
"4.Search the data\n5.Exit the System\n");
scanf("%d", &i);
getchar();//get enter char
switch(i)
{
case 1:
input(score, &length);
break;
case 2:
output(score, length);
break;
case 3:
sort(score, length);
printf("sort finish!\n");
break;
case 4:
location = search(score, length);
if(location < 0)
printf("the number is not exist!\n");
else
printf("location of the number in array is %d \n", location);
break;
case 5:
exit(0);
break;
default:
printf("Error input! Please check again!\n");
break;
}
printf("Again('Y/y' for yes, 'N/n' for no)?\n");
ch = getchar();
if(tolower(ch) == 'y')
goto again;
else
return 0;
}
void input(int arr[], int *length)
{
int insertNumber;
printf("Input number you want to insert:");
scanf("%d", &insertNumber);
getchar();
arr[*length] = insertNumber;
(*length)++;
}
void output(int *arr, int length)
{
int i;
printf("Data:\n");
for(i = 0; i < length-1; i++)
printf("%d, ", arr[i]);
printf("%d\n", arr[i]);
}
void sort(int* arr,int length)
{
int iTemp;
int i, j;
for(i=1;i<=length;i++)
for(j=length-1;j>=i;j--)
{
if(arr[j]<arr[j-1])
{
iTemp=arr[j-1];
arr[j-1]=arr[j];
arr[j]=iTemp;
}
}
}
//如果查找的数在数组中,则返回其在数组中的位置
//否则,返回-1
int search(int *arr, int length)
{
int searchNo;//search number
int i;
printf("Input search number:");
scanf("%d", &searchNo);
getchar();
for(i = length - 1; i >= 0; i--)
{
if(searchNo == arr[i])
break;
}
return i;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询