热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何给数组赋值java_java怎样给数组赋值

#include#include#include*清屏*#include*显示目录*#include#defineMAX80voidinput();*输入数据函数*voidsort

8575c11a51105e36efe1278152e2c0df.png

#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&#61;1;j<&#61;now_no-i;j&#43;&#43;)

{

if(stu[j-1].ave

{

temp&#61;stu[j];

stu[j]&#61;stu[j-1];

stu[j-1]&#61;temp;

}

}

}

printf("排序以完成进入功能2可进行显示\n");

system("pause");

system("cls");

}

void sort1()/*排序数据函数*/

{

struct student temp;

int i,j;

for(i&#61;1;i

{

for(j&#61;1;j<&#61;now_no-i;j&#43;&#43;)

{

if(stu[j-1].score1

{

temp&#61;stu[j];

stu[j]&#61;stu[j-1];

stu[j-1]&#61;temp;

}

}

}

}

void sort2()/*排序数据函数*/

{

struct student temp;

int i,j;

for(i&#61;1;i

{

for(j&#61;1;j<&#61;now_no-i;j&#43;&#43;)

{

if(stu[j-1].score2

{

temp&#61;stu[j];

stu[j]&#61;stu[j-1];

stu[j-1]&#61;temp;

}

}

}

}

void sort3()/*排序数据函数*/

{

struct student temp;

int i,j;

for(i&#61;1;i

{

for(j&#61;1;j<&#61;now_no-i;j&#43;&#43;)

{

if(stu[j-1].score3

{

temp&#61;stu[j];

stu[j]&#61;stu[j-1];

stu[j-1]&#61;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&#61;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&#61;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&#61;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&#61;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&#61;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&#61;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&#61;now_no&#43;1;

sort();

printf("是否继续输入?(Y/N)");

fflush(stdin);

ch&#61;getch();

system("cls");

}

while(ch!&#61;&#39;n&#39;&&ch!&#61;&#39;N&#39;);

}

void del()/*删除数据函数*/

{

int inum,i;

printf("输入要删除学员的编号:");

fflush(stdin);

scanf("%d",&inum);

for(i&#61;0;i

{

if(stu[i].no&#61;&#61;inum)

{

if(i&#61;&#61;now_no)now_no-&#61;1;

else

{

stu[i]&#61;stu[now_no-1];

now_no-&#61;1;

}

sort();

break;

}

}

system("cls");

}

void save()/*保存数据函数*/

{

FILE *fp;

int i;

char filepath[20];

printf("输入要保存的文件路径:");

fflush(stdin);

gets(filepath);

if((fp&#61;fopen(filepath,"w"))&#61;&#61;NULL)

{

printf("\n保存失败!");

exit(0);

}

for(i&#61;0;i

{

stu[i].sum&#61;stu[i].score1&#43;stu[i].score2&#43;stu[i].score3;

stu[i].ave&#61;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&#61;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&#61;getch();

}

while(!as);

system("cls");

}

void average()/*求平均数*/

{

int i;

for(i&#61;0;i

{

stu[i].sum&#61;stu[i].score1&#43;stu[i].score2&#43;stu[i].score3;

stu[i].ave&#61;stu[i].sum/3;

}

}

void modify()/*修改数据函数*/

{

int i;

char str[20];

printf("输入要修改的学生姓名:");

fflush(stdin);

gets(str);

for(i&#61;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&#61;fopen(filepath,"r"))&#61;&#61;NULL)

{

printf("找不到%s文件!\n",filepath);

system("pause");

exit(0);

}

now_no&#61;0;

for(i&#61;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&#43;&#43;;

}

fclose(fp);

printf("保存的在文件%s中的所有信息已经读入!\n",filepath);

system("pause"); /*按任意键继续*/

system("cls");

}

void del_file()

{

FILE *fp;

char filepath[20];

printf("输入要删除的文件路径:");

fflush(stdin);

gets(filepath);

fp&#61;fopen(filepath,"w");

fclose(fp);

printf("保存的在文件%s中的所有信息已经删除!\n",filepath);

system("pause");

system("cls");

}

◆◆

评论读取中....

请登录后再发表评论!

◆◆

修改失败&#xff0c;请稍后尝试



推荐阅读
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文介绍了一个题目的解法,通过二分答案来解决问题,但困难在于如何进行检查。文章提供了一种逃逸方式,通过移动最慢的宿管来锁门时跑到更居中的位置,从而使所有合格的寝室都居中。文章还提到可以分开判断两边的情况,并使用前缀和的方式来求出在任意时刻能够到达宿管即将锁门的寝室的人数。最后,文章提到可以改成O(n)的直接枚举来解决问题。 ... [详细]
  • 本文介绍了闭包的定义和运转机制,重点解释了闭包如何能够接触外部函数的作用域中的变量。通过词法作用域的查找规则,闭包可以访问外部函数的作用域。同时还提到了闭包的作用和影响。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 目录实现效果:实现环境实现方法一:基本思路主要代码JavaScript代码总结方法二主要代码总结方法三基本思路主要代码JavaScriptHTML总结实 ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • 本文介绍了如何在给定的有序字符序列中插入新字符,并保持序列的有序性。通过示例代码演示了插入过程,以及插入后的字符序列。 ... [详细]
  • 本文介绍了为什么要使用多进程处理TCP服务端,多进程的好处包括可靠性高和处理大量数据时速度快。然而,多进程不能共享进程空间,因此有一些变量不能共享。文章还提供了使用多进程实现TCP服务端的代码,并对代码进行了详细注释。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 猜字母游戏
    猜字母游戏猜字母游戏——设计数据结构猜字母游戏——设计程序结构猜字母游戏——实现字母生成方法猜字母游戏——实现字母检测方法猜字母游戏——实现主方法1猜字母游戏——设计数据结构1.1 ... [详细]
  • Linux环境变量函数getenv、putenv、setenv和unsetenv详解
    本文详细解释了Linux中的环境变量函数getenv、putenv、setenv和unsetenv的用法和功能。通过使用这些函数,可以获取、设置和删除环境变量的值。同时给出了相应的函数原型、参数说明和返回值。通过示例代码演示了如何使用getenv函数获取环境变量的值,并打印出来。 ... [详细]
  • 本文介绍了PE文件结构中的导出表的解析方法,包括获取区段头表、遍历查找所在的区段等步骤。通过该方法可以准确地解析PE文件中的导出表信息。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
author-avatar
suibian
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有