如何给数组赋值java_java怎样给数组赋值
#include
#include
#include /*清屏*/
#include /*显示目录*/
#include
#define MAX 80
void input(); /*输入数据函数*/
void sort();/*排序数据函数*/
void sort1();
void sort2();
void sort3();
void display();/*显示数据函数*/
void display1();
void insert(); /*插入数据函数*/
void del(); /*删除数据函数*/
void average(); /*平均值函数*/
void find();/*查找数据函数*/
void find1();
void find2();
void save(); /*保存数据函数*/
void read(); /*读出数据函数*/
void del_file(); /*删除文件函数*/
void modify(); /*修改文件函数*/
int now_no=0;
struct student
{
int no;
char name[20];
char sex[4];
float score1;
float score2;
float score3;
float sort;
float ave;
float sum;
};
struct student stu[MAX],*p;
main()/*主函数*/
{
int as;
char ch;
do{
start: printf("\n\n\n\t\t\t欢迎使用学生成绩管理系统\n");
printf("\n\n\n\n\n\n\t\t******************按任意键继续********************");
ch=getch();
}
while(!ch);
system("cls");
/*一下为功能选择模块*/
do
{
printf("\n\t\t\t\t1.录入学员信息\n\t\t\t\t2.显示学员总成绩信息\n\t\t\t\t3.对总成绩排序\n\t\t\t\t4.显示学员单科成绩排序\n\t\t\t\t5.添加学员信息\n\t\t\t\t6.删除学员信息\n\t\t\t\t7.修改学员信息\n\t\t\t\t8.查询学员信息\n\t\t\t\t9.从文件读入学员信息\n\t\t\t\t10.删除文件中学员信息\n\t\t\t\t11.保存学员信息\n\t\t\t\t12.退出\n");
printf("\t\t\t\t选择功能选项(输入所选功能前的数字):");
fflush(stdin);
/*可用可不用,用于清除缓存防止下次用scanf输入是出现错误*/
scanf("%d",&as);
switch(as)
{
case 1:system("cls");
input();
break;
case 2:system("cls");
display();
break;
case 3:system("cls");
sort();
break;
case 4:system("cls");
display1();
break;
case 5:system("cls");
insert();
break;
case 6:system("cls");
del();
break;
case 7:system("cls");
modify();
break;
case 8:system("cls");
find();
break;
case 9:system("cls");
read();
break;
case 10:system("cls");
del_file();
break;
case 11:system("cls");
save();
break;
case 12:system("exit");
exit(0);
default:system("cls");
goto start;
}
}while(1);/*while(1),1表示真,所以while(1)表示永远循环下去,一般在while(1)的循环体内都有break 或者return 跳出循环*/
/*至此功能选择结束*/
}
void input()/*原始数据录入模块*/
{
int i=0;
char ch;
do
{
printf("\t\t\t\t1.录入学员信息\n输入第%d个学员的信息\n",i+1);
printf("\n输入学生编号:");
scanf("%d",&stu[i].no);
fflush(stdin);
printf("\n输入学员姓名:");
fflush(stdin);
gets(stu[i].name);
printf("\n输入学员性别:");
fflush(stdin);
gets(stu[i].sex);
printf("\n输入学员成绩1:");
scanf("%f",&stu[i].score1);
printf("\n输入学员成绩2:");
fflush(stdin);
scanf("%f",&stu[i].score2);
printf("\n输入学员成绩3:");
fflush(stdin);
scanf("%f",&stu[i].score3);
printf("\n\n");
i++;
now_no=i;
printf("是否继续输入?(Y/N)");
fflush(stdin);
ch=getch();
system("cls");
}
while(ch!='n'&&ch!='N');
system("cls");
}
void sort()/*排序数据函数*/
{
struct student temp;
int i,j;
average();
for(i=1;i
{
for(j=1;j<=now_no-i;j++)
{
if(stu[j-1].ave
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
}
}
}
printf("排序以完成进入功能2可进行显示\n");
system("pause");
system("cls");
}
void sort1()/*排序数据函数*/
{
struct student temp;
int i,j;
for(i=1;i
{
for(j=1;j<=now_no-i;j++)
{
if(stu[j-1].score1
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
}
}
}
}
void sort2()/*排序数据函数*/
{
struct student temp;
int i,j;
for(i=1;i
{
for(j=1;j<=now_no-i;j++)
{
if(stu[j-1].score2
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
}
}
}
}
void sort3()/*排序数据函数*/
{
struct student temp;
int i,j;
for(i=1;i
{
for(j=1;j<=now_no-i;j++)
{
if(stu[j-1].score3
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
}
}
}
}
void display()/*显示数据函数*/
{
int i;
char as;
average();
do
{
printf("\t\t\t班级学员信息列表\n");
printf("\t编号\t姓名\t性别\t成绩1\t成绩2\t成绩3\t平均值\n");
for(i=0;i
printf("\t%d\t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n",stu[i].no,stu[i].name,stu[i].sex,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].ave);
printf("\t\t按任意键返回主菜单.");
fflush(stdin);
as=getch();
}
while(!as);
system("cls");
}
void display1()/*显示数据函数*/
{
int i;
char as;
do
{
printf("\t\t\t班级学员score1成绩排序\n");
printf("\t编号\t姓名\t性别\t成绩1\n");
sort1();
for(i=0;i
printf("\t%d\t%s\t%s\t%.2f\t\n",stu[i].no,stu[i].name,stu[i].sex,stu[i].score1);
printf("\t\t\t班级学员score2成绩排序\n");
printf("\t编号\t姓名\t性别\t成绩2\n");
sort2();
for(i=0;i
printf("\t%d\t%s\t%s\t%.2f\t\n",stu[i].no,stu[i].name,stu[i].sex,stu[i].score2);
printf("\t\t\t班级学员score3成绩排序\n");
printf("\t编号\t姓名\t性别\t成绩3\n");
sort3();
for(i=0;i
printf("\t%d\t%s\t%s\t%.2f\t\n",stu[i].no,stu[i].name,stu[i].sex,stu[i].score3);
printf("\t\t按任意键返回主菜单.");
fflush(stdin);
as=getch();
}
while(!as);
system("cls");
}
void insert()/*插入数据函数*/
{
char ch;
do
{
printf("\n\t\t输入新插入学员队信息\n");
printf("\n输入学生编号:");
scanf("%d",&stu[now_no].no);
fflush(stdin);
printf("\n输入学员姓名:");
fflush(stdin);
gets(stu[now_no].name);
printf("\n输入学员性别:");
fflush(stdin);
gets(stu[now_no].sex);
printf("\n输入学员成绩1:");
fflush(stdin);
scanf("%f",&stu[now_no].score1);
printf("\n输入学员成绩2:");
fflush(stdin);
scanf("%f",&stu[now_no].score2);
printf("\n输入学员成绩3:");
fflush(stdin);
scanf("%f",&stu[now_no].score3);
printf("\n\n");
now_no=now_no+1;
sort();
printf("是否继续输入?(Y/N)");
fflush(stdin);
ch=getch();
system("cls");
}
while(ch!='n'&&ch!='N');
}
void del()/*删除数据函数*/
{
int inum,i;
printf("输入要删除学员的编号:");
fflush(stdin);
scanf("%d",&inum);
for(i=0;i
{
if(stu[i].no==inum)
{
if(i==now_no)now_no-=1;
else
{
stu[i]=stu[now_no-1];
now_no-=1;
}
sort();
break;
}
}
system("cls");
}
void save()/*保存数据函数*/
{
FILE *fp;
int i;
char filepath[20];
printf("输入要保存的文件路径:");
fflush(stdin);
gets(filepath);
if((fp=fopen(filepath,"w"))==NULL)
{
printf("\n保存失败!");
exit(0);
}
for(i=0;i
{
stu[i].sum=stu[i].score1+stu[i].score2+stu[i].score3;
stu[i].ave=stu[i].sum/3;
fprintf(fp,"\t%d\t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n",stu[i].no,stu[i].name,stu[i].sex,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].ave);
}
fclose(fp);
printf("学生信息已保存在%s中!\n",filepath);
system("pause");
system("cls");
}
void find()/*查询函数*/
{
int i;
char str[20],as;
do
{
printf("输入要查询的学生姓名:");
fflush(stdin);
gets(str);
for(i=0;i
if(!strcmp(stu[i].name,str))
{
printf("\t编号\t姓名\t性别\t成绩1\t成绩2\t成绩3\t平均值\n");
printf("\t%d\t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n",stu[i].no,stu[i].name,stu[i].sex,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].ave);
}
printf("\t\t按任意键返回主菜单.");
fflush(stdin);
as=getch();
}
while(!as);
system("cls");
}
void average()/*求平均数*/
{
int i;
for(i=0;i
{
stu[i].sum=stu[i].score1+stu[i].score2+stu[i].score3;
stu[i].ave=stu[i].sum/3;
}
}
void modify()/*修改数据函数*/
{
int i;
char str[20];
printf("输入要修改的学生姓名:");
fflush(stdin);
gets(str);
for(i=0;i
{
if(!strcmp(stu[i].name,str))
{
system("cls");
printf("\n\t\t输入新插入学员队信息\n");
printf("\n输入学生编号:");
fflush(stdin);
scanf("%d",&stu[i].no);
printf("\n输入学员性别:");
fflush(stdin);
gets(stu[i].sex);
printf("\n输入学员成绩1:");
fflush(stdin);
scanf("%f",&stu[i].score1);
printf("\n输入学员成绩2:");
fflush(stdin);
scanf("%f",&stu[i].score2);
printf("\n输入学员成绩3:");
fflush(stdin);
scanf("%f",&stu[i].score3);
printf("\n\n");
sort();
break;
}
}
system("cls");
}
void read()
{
FILE *fp;
int i;
char filepath[20];
printf("输入要读入的文件路径:");
fflush(stdin);
gets(filepath);
if((fp=fopen(filepath,"r"))==NULL)
{
printf("找不到%s文件!\n",filepath);
system("pause");
exit(0);
}
now_no=0;
for(i=0;i
{
fscanf(fp,"\t%d\t%s\t%s\t%f\t%f\t%f\t%f\n",&stu[i].no,stu[i].name,stu[i].sex,&stu[i].score1,&stu[i].score2,&stu[i].score3,&stu[i].ave);
now_no++;
}
fclose(fp);
printf("保存的在文件%s中的所有信息已经读入!\n",filepath);
system("pause"); /*按任意键继续*/
system("cls");
}
void del_file()
{
FILE *fp;
char filepath[20];
printf("输入要删除的文件路径:");
fflush(stdin);
gets(filepath);
fp=fopen(filepath,"w");
fclose(fp);
printf("保存的在文件%s中的所有信息已经删除!\n",filepath);
system("pause");
system("cls");
}
◆◆
评论读取中....
请登录后再发表评论!
◆◆
修改失败,请稍后尝试
如何给数组赋值java_java怎样给数组赋值相关推荐
- 向数组添加元素 java_java如何向数组里添加元素
向数组里添加一个元素怎么添加,这儿总结有三种方法: 1.一般数组是不能添加元素的,因为他们在初始化时就已定好长度了,不能改变长度. 但有个可以改变大小的数组为ArrayList,即可以定义一个Arra ...
- 二维数组赋值 java_java二维数组的赋值方法
在java数组中,我们想要知道其长度,可以通过赋值的方法来实现.在正式开始对数组赋值前,我们要明确其中的下标问题.在准备步骤上,先找到高维的位置,再确定低纬的下标,就可以进行相关的赋值操作了.下面就具 ...
- arraylist扩容是创建新数组吗 java_Java编程之数组扩容
一.背景 数组在实际的系统开发中用的越来越少了,我们只有在阅读某些开源项目时才会看到数组的使用.在Java中,数组与List.Set.Map等集合类相比,后者使用起来方便,但是在基本数据类型处理方面, ...
- 数组序列化 java_Java基础之数组序列化、反序列化 小发现(不知道 是不是有问题)...
结论: 数组,无论是否声明为transient,都是可以序列化.反序列化的. 测试情况如下: 1.两种类型的数组:int .String: 2 声明为transient 或者不做任何修饰:. 3. ...
- c语言把一个数组赋值给另一个数组_如何把一个固定数组的值传递给另外一个数组...
大家好,今日我们继续讲解VBA数组与字典解决方案,今日讲解的是第34讲:数组的传递.在应用数组的时候,我们往往需要要把数组的值由一个数组传递给另外一个数组,就如同变量的传递一样: A=B '把B值赋给 ...
- oracle游标循环定义变量赋值,PL/SQL 循环 数组 游标的使用
1.创建存储过程 create or replace procedure test(var_name_1 in type,var_name_2 out type) as --声明变量(变量名 变量类型 ...
- access vba 常量数组赋值_聊聊 VBA 数组的那些坑
为什么使用数组? 1. 缩减工作薄文件大小,提高运行效率 一般而言只是使用 Excel 的内置工作表函数,在运算方面还是很高效的,但有时因为一个单元格牵扯的计算太多,比如调用多单元格数据,对结果文本进 ...
- Java基础:数组的声明,循环,赋值,拷贝。
数组的声明 一般有两种形式的声明: int[] a; int a[]; 这两种声明都没错,但是大多数都使用第一种声明,因为变量名是独立的,不带任何符号. 声明一个数组,并没有将a正在的初始化为一个数组 ...
- python 结构体数组_python实现结构体数组(初始化并赋值)
标签: C语言中结构体数组概念及定义 一个结构体变量可以存放一个学生的一组信息,可是如果有 10 个学生呢?难道要定义 10 个结构体变量吗?难道上面的程序要复制和粘贴 10 次吗? 很明显不可能,这 ...
最新文章
- 【 C 】在双链表中插入一个新值的简明程序
- NetCDF Overview
- Spring学习4之依赖注入(DI)
- 启明云端分享|ESP32-C3-MINI-1和ESP32-C3-MINI-1U的区别是什么?
- 2017 Google 开发者大会终于来了!
- 随手记_重建的五花八门的点云地图效果(供娱乐)
- springboot日志输出异常_基于aop进行springboot接口调用日志和埋点日志输出,支持json格式方便elk收集...
- MASM32汇编SDK安装
- TCP客户端和服务端
- 【杂谈】为了子孙后代,请不要逃离大城市或者龟缩在三四线小城市
- php 判断字数,php 如何统计中文字数
- javaweb实现在线支付功能
- 史上最全最实用的生活小窍门
- HTML无序列表四大名著
- Element-ui 日期选择器切换类型(type)
- css 文字中间 两边横线
- bootstrap(手风琴、图片轮换和固定定位)
- JQuery运行机制及原理
- Springboot整合JPA
- 图片教程+html,html图片教程
热门文章
- 计算几何之凸包_卷包裹算法
- 跨平台的网络通信中间件:ICE和ACE
- gcc之UTF-8编码
- vue二级路由跳转后外部引入js失效问题解决方案
- Spark推荐实战系列之Swing算法介绍、实现与在阿里飞猪的实战应用(附代码)
- mysql 建表sysdate_mysql数据库基本操作练习
- bat启动脚本 springboot_Windows系统配置.bat启动spring boot项目jar
- 个性屏幕保护程序_Mac高清鸟瞰屏幕保护程序,酷毙了
- 我为何选择Facebook广告
- Tiktok代运营才是跨境卖家的未来?别再错过这个风口了!