当前位置:首页 » 编程语言 » 查找c语言的答案
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

查找c语言的答案

发布时间: 2022-05-18 02:24:29

⑴ 求这道c语言编程题的答案

部分测试样例

⑵ 有什么软件可以搜索大学C语言题目的啊

大学c语言搜题app。大学c语言搜题app原名叫做菜鸟学C语言是一款非常好用的学习c语言的手机软件

软件功能

1、选择题:按照考点分类的选择题习题,并有答案解析。

2、错题库:可自动加练习过程中错题加入收藏,以便反复练习。

3、上机操作题:300道上机操作题,程序填空题、程序修改题、程序设计题。

软件优势

1、选择题:按照考点分类的选择题习题,并有答案解析。

2、上级操作题:300道上机操作题,程序填空题、程序修改题、程序设计题。

3、最新押题:最新考试押题3套。

4、考点汇总:包含复习的考点。

5、错题库:可自动加练习过程中错题加入收藏,以便反复练习。

6、收藏夹:可在练习过程中自行收录题目到收藏夹,形成自己的小题库,针对性练习,提高通过率。

软件特色

1、随时随地都能够学习,而且还支持下载保存你学习内容离线继续学习。

2、同学们能够直接通过搜索引擎来查询寻找你感兴趣对你内容。

3、解答问题的办法非常多,可以选择通过拍照来答题,也可以选择输入题目来解答。

⑶ 寻找c程序答案

#include

#define available 1 //用来标志该位是否可用,availabel表示可用,unailable表示不可


#define unavailable 0

#define true 1

#define false 0

int j,top=-1,flag,i,is_pop,total=0;
// top用来保存栈顶指针,flag用来说明该次是否成功下了一个皇后
//is_pop用来说明是否把栈弹出,total用来保存共有多少种下法
//i用来保存下一次皇后应下的列

int stack[8],a[15],b[15],c[7];
//stack保存皇后的位置,a,b,c三个数住用来保存该位是否可以下皇后

void init(void);//初始化各位状态,使之可以下皇后

void release (void);//当该列都不能下皇后,则解除上次下皇后试对相关位的锁定

main()

{

cout<
init();

is_pop=false;//初始化

for( ; ;)

{

do {

for (j=is_pop? stack[i]+1:0;j<=7;j++)

if (a[i+j]&&b[i-j+7]&&c[j])//判断该位是否可用
{//若可用,则栈顶指针上移,在该位存入皇后号

top++;

stack[top]=j;

a[i+j]=b[i-j+7]=c[j]=unavailable;//并把相关位设为不可用

i++;//i指向下一个应填入皇后德列

flag=true;//设标志,说明成功

is_pop=false;

break;//则直接退出循环

}

if (!flag)//若不成功,则释放被锁定的位

release();

flag=false;

if (stack[0]+1==8&&top==-1)//若第一列也没有位置可以放皇后,

goto END; //则说明没有其他的放法了,则退出

}

while (top!=7);

for (int k=0;k<=7;k++)

cout

⑷ 如何快速查找C语言编译时的错误

1、首先,我们启动编译软件程序,今天我们以VC++6.0为例。

注意事项:

编译语言是一种以编译器来实现的编程语言。它不像直译语言一样,由解释器将代码一句一句运行,而是以编译器,先将代码编译为机器码,再加以运行。理论上,任何编程语言都可以是编译式,或直译式的。它们之间的区别,仅与程序的应用有关。

⑸ C语言答案

C语言程序设计复习:

1、理解以下术语的含义:数组、函数、地址 指针 指针变量 直接访问 间接访问、结构体
2、用起泡法对10个数由小到大排序(P134例题)
5、输入10个学生的成绩,分别用函数实现下列功能:
1)计算所有学生的平均分;
2) 计算学生成绩中最高分;
3) 计算学生成绩中最低分;
4) 统计及格学生人数;
5) 查找成绩为指定成绩(如90)记录,如果没有,请给出提示,如果有,请统计满足条件的记录数。
6、有一个已经排好序的数组,今输入一个数,要求按原来排序的规律将它插入数组中。(P153习题7.4)
7、编写一个函数,输入一个4位数字,要求输出这4个数字字符,但每两个数字字符间空一个空格。如输入1990,应输出“1 9 9 0”。(要求用函数)(P202习题8.8)
8、编写一个函数,求一个字符串的长度。在main函数中输入字符串,并输出其长度。(要求用指针,不能使用strlen()函数) (P279习题10.6)
9、编写一个程序,打入月份号,输出该月的英文月名。例如,输入“3”则输出“March”(要求用指针数组)。(P279习题10.18)
10、将一个数组中的值按逆序重新存放。例如,输入的数组顺序为8,6,5,4,1,要求改为1,4,5,6,8。(P153习题7.5)
11、编写一个函数用“起泡法”对输入的10个字符按由小到大顺序排序(要用函数)。(P202习题8.11)
12、将数组a中n个整数按相反顺序存放(要用函数)。(P237例题10.7)
13、输入一行文字,找出其中大写字母、小写字母、空格、数字及其他字符各有多少。(要求用指针实现)(P279习题10.8)
14、编写一个函数,将两个字符串连接(要用自定义函数,不能用strcat函数)。(P202习题8.6)
15、输入3个字符串,按照由小到大的顺序输出。(要求用指针) (P278习题10.2)
16、输入10整数,将其中最小的数与第一个数对换,把最大的数与最后一个数对换。写三个函数:1、输入10个数; 2、进行处理; 3、输出10个数(数据对换要求用指针实现)(P278习题10.3)

参考答案:
2、用起泡法对10个数由小到大排序
#include <stdio.h>
void main()
{ int a[10]; int i,j,t;
printf("input 10 numbers :\n");
for (i=0;i<10;i++)
scanf("%d“,&a[i]);
printf(“\n");
for(j=0;j<9;j++)
for(i=0;i<10-j;i++)
if (a[i]>a[i+1])

printf("the sorted numbers :\n");
for(i=0;i<10;i++)
printf(“%d “,a[i]);
}
3、用递归方法求n阶勒让德多项式的值,递归公式为(要求用函数):(P202习题8.13)

pn(x)= 1 n=0
x n=1
((2n-1)*x-pn-1(x)-(n-1)*pn-2(x)/n n>1

3、#include <stdio.h>
void main()
{
int x,n;
float p(int,int);
printf(“input n & x:”);
scanf(“%d,%d”,&n,&x);
printf(“n=%d,x=%d\n”,n,x);
printf(“P%d(%d)=%6.2f\n”,n,x,p(n,x));
}
float p(int n,int x)
{
if(n==0)
return 1;
else if(n==1)
return x;
else
return ((2*n-1)*x*p((n-1),x)-(n-1)*p((n-2),x))/n;
}
4、输入3个整数,按由小到大的顺序输出(要求用指针类型)(P228例题)

4、输入3个整数,按由小到大的顺序输出(要求用指针类型)
#include <stdio.h>
void main()
{
void sort (int*a, int*b,int*c);
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
sort(&a,&b,&c);
printf("a=%d,b=%d,c=%d\n",a,b,c);
}
void sort (int *a, int *b,int *c)
{
int tmp;
if (*a>*b)
{
tmp=*a;
*a=*b;
*b=tmp;
}
if (*a>*c)
{
tmp=*a;
*a=*c;
*c=tmp;
}
if (*b>*c)
{
tmp=*b;
*b=*c;
*c=tmp;
}

}
5、输入10个学生的成绩,分别用函数实现下列功能:
1)计算所有学生的平均分;
6) 计算学生成绩中最高分;
7) 计算学生成绩中最低分;
8) 统计及格学生人数;
9) 查找成绩为指定成绩(如90)记录,如果没有,请给出提示,如果有,请统计满足条件的记录数。

#include <stdio.h>
void main()
{
int average(int a[]);
int max(int a[]);
int min(int a[]);
int pass(int a[]);
int search(int a[],int g);
int i,j,g;
int score[10],aver,m1,m2,p,s;
printf("Please input 10 scores:\n");
for(i=0;i<10;i++)
scanf("%d",&score[i]);
printf("\n");
aver=average(score);
m1=max(score);
m2=min(score);
p=pass(score);
printf("平均分为: %d\n",aver);
printf("最高分为: %d\n",m1);
printf("最低分为: %d\n",m2);
printf("及格人数为: %d\n",p);
printf("需要查找吗?\n");
printf("输入1继续查找,输入0退出(1/0):");
scanf("%d",&j);
if(j==1)
{
printf("请输入要查找的分数: \n");
scanf("%d",&g);
s=search(score,g);
if(s==0)
printf("没有满足条件的记录");
else
printf("成绩为%d的学生共有%d名\n",g,s);
}
}
int average(int a[])
{
int i;
int aver,sum=a[0];
for(i=1;i<10;i++)
sum=sum+a[i];
aver=sum/10;
return aver;
}
int max(int a[])
{
int i;
int m=a[0];
for(i=1;i<10;i++)
if(m<a[i])
m=a[i];
return m;
}
int min(int a[])
{
int i;
int m=a[0];
for(i=1;i<10;i++)
if(m>a[i])
m=a[i];
return m;
}
int pass(int a[])
{
int i;
int s=0;
for(i=0;i<10;i++)
if(a[i]>=60)
s++;
return s;
}
int search(int a[],int g)
{
int i;
int s=0;
for(i=0;i<10;i++)
if(a[i]==g)
s++;
return s;
}

6、已有一个已排好次序的数组,要求输入一个数后,按原先排序的规律将它插入数组中。
Void main()
;
int temp1,temp2,number,end,i,j;
printf("初始数组如下:");
for (i=0;i<10;i++)
printf("%5d",a[i]);
printf("\n");
printf("输入插入数据:");
scanf("%d",&number);
end=a[9];
if(number>end)
a[10]=number;
else
{for(i=0;i<10;i++)
{ if(a[i]>number)
{temp1=a[i];
a[i]=number;
for(j=i+1;j<1;j++)
{temp2=a[j];
a[j]=temp1;
temp1=temp2;
}
break;
}
}
}
for(i=0;i<11;i++)
printf("a%6d",a[i]);
}

7、编写一个函数,输入一个4位数字,要求输出这4个数字字符,但每两个数字字符间空一个空格。如输入1990,应输出“1 9 9 0”。
#include <iostream>
void main()
{
void stradd(char str[]);
char str[80];
printf("输入一串数字\n\n");
gets(str);
stradd(str);
printf("\n\n加空格后的字符串\n\n");
puts(str);
}
void stradd(char str[])
{
char a[80];
int i=0,j;
for(j=0;str[j]!='\0';j++)
{
a[i]=str[j];
a[i+1]=' ';
i+=2;
}
a[i]='\0';
for(i=0;a[i]!='\0';i++)
{
str[i]=a[i];
}
str[i]='\0';
}

8、编写一个函数,求一个字符串的长度。在main函数中输入字符串,并输出其长度。(要求用指针实现)
#include "stdio.h"
int stringlength( char *str )
{int n;
n=0;
While(*str!=0)
{n++;
str++;
}
Return(n);
}

int main()
{
char str〔100〕,
int len,

printf("Please input a string: "),
scanf("%s".str),
len = stringlength( str ),

printf("The string’s length is %d.".len),
return 0;
}

9、编写一个程序,打入月份号,输出该月的英文月名 n。例如,输入“3”则输出“March”,要求用指针数组处理。
#include <stdio.h>
main()
{ char *month_name[13]={"illegal month","January","February","March","April",
"May","June","July","August","September","October","November","December"};
int n;
printf("Input month: ");
scanf("%d",&n);
if((n<=12)&&(n>=1))
printf("It is %s.\n",*(month_name+n));
else
printf("It is wrong.\n");
}
10、将一个数组中的值按逆序重新存放。例如,输入的数组顺序为8,6,5,4,1,要求改为1,4,5,6,8。
#include <stdio.h>
#define N 5;
void main()
{
int a[N],i,temp;
printf(“enter array a:\n”);
for(i=0;i<N;i++)
scanf(“%d”,&a[i]);
printf(“array a:\n”);
for(i=0;i<N;i++)

printf(“\nNow, array a:\n”);
for(i=0;i<N;i++)
printf(“%4d”,a[i]);
printf(“\n”);
}

11、编写一个函数用“起泡法”对输入的10个字符按由小到大顺序排序(要用函数)。
#include <stdio.h>
void main()
{ char str[80];
void sort(char str[]);
printf("输入一个字符串\n\n");
gets(str);
sort(str);
printf("\n\n字符由小到大排序为:\n\n");
puts(str);
}
void sort(char str[])
{ int i,j;
char temp;
for(i=0;i<strlen(str);i++)
{
for(j=0;j<strlen(str)-i-1;j++)
{
if(str[j]>str[j+1])
{
temp=str[j];
str[j]=str[j+1];
str[j+1]=temp;
}
}
}
}

12、将数组a中n个整数按相反顺序存放(要用函数)。
#include <stdio.h>
void inv(int x[ ],int n)/*形参x是数组名*/

int temp,i,j,m=(n-1)/2;
for(i=0;i<=m;i++)
{j=n-1-i;
temp=x[i];x[i]=x[j];x[j]=temp;}
return;

void main()
{ int i,a[10]={3,7,9,11,0,6,7,5,4,2};
printf(“转换前的数组为:\n");
for(i=0;i<10;i++)
printf("%d,",a[i]);
printf("\n");
inv(a,10);
printf(“转换后的数组为:\n");
for(i=0;i<10;i++)
printf("%d,",a[i]);
printf("\n");

13、输入一行文字,找出期中大写字母、小写字母、空格、数字及其他字符各有多少?(要求用指针实现)
#include<stdio.h>
#include<string.h>
int main()
{
char str[40];//创建字符串数组
int count[5]=;//创建计数器数组并初始化
printf("Please input a string .\n");
scanf("%s",str);
char *p=str;//指针p指向字符串数组str
int n=strlen(str);//确定输入字符串的长度
for(int i=0;i<n;i++)
{
if(*(p+i)>='A'&&*(p+i)<='Z')
{
count[0]++;//统计大写字母数目
}
else if(*(p+i)>='a'&&*(p+i)<='z')
{
count[1]++;//统计小写字母数目
}
else if(*(p+i)>='0'&&*(p+i)<='9')
{
count[2]++;//统计数字数目
}
else if(*(p+i)=='')
{
count[3]++;//统计空格数目
}
else
{
count[4]++;//统计其他字符数目
}
}
printf("大写字母 小写字母 数字 空格 其他字符:\n");
for(i=0;i<5;i++)
{
printf("%d\t ",count[i]);//打印各统计数目
}
printf("\n\n");
return 0;
}

14、编写一个函数,将两个字符串连接。
#include < stdio.h >
#include<string.h>
void concatenate(char string1[],char string2[],char string[])
{
int i,j;
for(i=0;string1[i]!=’\0’;i++)
string[i]=string1[i];
for(j=0;string2[j]!=’\0’;j++)
string[i+j]=string2[j];
string[i+j]=’\0’;
}
void main()
{
char s1[100],s2[100],s[100];
printf(“input string1:”);
scanf(“%s”,s1);
printf(“input string2:”);
scanf(“%s”,s2);
concatenate(s1,s2,s)
printf(“the new string is %s”,s);
}
15、输入3个字符串,按照由小到大的顺序输出。 (要求用指针实现)
#include <stdio.h>
void main()
{
void sort (int*a, int*b,int*c);
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
sort(&a,&b,&c);
printf("a=%d,b=%d,c=%d\n",a,b,c);
}
void sort (int *a, int *b,int *c)
{
int tmp;
if (*a>*b)
{
tmp=*a;
*a=*b;
*b=tmp;
}
if (*a>*c)
{
tmp=*a;
*a=*c;
*c=tmp;
}
if (*b>*c)
{
tmp=*b;
*b=*c;
*c=tmp;
}
}

16、输入10整数,将其中最小的数与第一个数对换,把最大的数与最后一个数对换。写三个函数:1、输入10个数; 2、进行处理; 3、输出10个数(数据对换要求用指针实现)
#include <stdio.h>
void input(int number[])
{
Int I;
Printf(“input 10 numbers:”);
For(i=0;i<10;i++)
Scanf(“%d”,&number[i]);
}
void max_min_value(int number[])
{
int *max,*min,*p,temp;
max=min=number;
For(p=number+1;p<number+10;p++)
if(*p>*max)
max=p;
else if(*p<*min)
min=p;
temp=number[0];number[0]=*min;*min=temp;
if(max=number) max=min;
temp=number[9];number[9]=*max;*max=temp;
}
void output(int number[])
{
int *p;
printf(“Now, they are: “);
for(p=number;p<number+10;p++)
Printf(“%d”,*p);
printf(“\n”);
}
void main()
{
int number[10];
input(number);
max_min_value(number);
output(number);
}

⑹ 求c语言答案

☆ 、整型变量i 定义后赋初值int i = 3.4 * 7的结果是(23)。
☆ 、已知a=10,b=20,则表达式!a<b的值为(1)。
☆ 、设x、y、z和k都是int型变量,则执行表达式:x=(y=4,(z=16+y)+(k=32))后,x的值为(52)。
☆ 、用逻辑表达式表示“x>=30或者x<10”,能正确表示的关系表达式是(x>=30||x<10)

☆ 、在int a[8]={1,3,5,7};中,数组元素a[2]的值是(5)。
☆ 、在宏定义#define PI 3.14中,用宏名PI代替一个(3.14)。
☆ 、C语言源程序的后缀名是(B)。
(A)exe (B) .c (C).obj (D) .cp

☆ 、设a=6,b=9,则执行b=(a++)+b;后a的值为_____7_____,b的值为 ____15______ 。
☆、#define S(a,b) a2+a*b+b2,计算表达式S(2,4)的值为____28______。

⑺ 急求c语言编程答案

// test.cpp : 定义控制台应用程序的入口点。
//

// test1.cpp : Defines the entry point for the console application.
//
// test.cpp : Defines the entry point for the console application.

# include "stdafx.h"
# include "stdio.h"
# include "stdlib.h"
# include <iostream>
# include <fstream>
# include <iomanip> /*需引用的头文件*/
using namespace std;

struct node /*定义结点结构体保存结点信息*/
{
struct student /*定义结构体变量student保存学生的信息*/
{
char studentnumber[10]; /*学生学号*/
char studentname[5]; /*学生姓名*/
struct course /*定义结构体变量Course保存课程信息*/
{
float course1; //*********************************
float course2;
float course3; //各门课程的分数和平均分
float averagemark; //*****************************
};struct course allcourse;
};struct student stu;
struct node *next;
};

node *top;

struct node *createlist(char info[2][9],float marksinfo[]) //**************************
{

static struct node *new_node,*current_node;

new_node=(struct node *)new(node); /*建立新的结点*/
strcpy(new_node->stu.studentnumber,info[0]);
strcpy(new_node->stu.studentname,info[1]);
new_node->stu.allcourse.course1=marksinfo[0];
new_node->stu.allcourse.course2=marksinfo[1];
new_node->stu.allcourse.course3=marksinfo[2]; //对结点的元素付值
new_node->stu.allcourse.averagemark=(marksinfo[0]+
marksinfo[1]+marksinfo[2])/3;
new_node->next=NULL;
if (top==NULL)
{
top=new_node;
current_node=top;
}

current_node->next=new_node; /*指向新的结点*/
current_node=new_node; /*总指向新的结点*/
return top; //*****************************
}
void studentaverage(node *top) /*显示平均分函数*/
{
int i=0,maxcount=0; /*结点的数目maxcount*/
char response='y';
struct node *t=top;

fstream readcount("countsave.txt",ios::in); /*定义文件流*/
readcount>>maxcount; /*将文件信息读入变量Maxcount*/
system("cls"); /*清屏*/

cout.flags(ios::left); /*输出格式为左对齐*/
cout<<setw(14)<<"学号"<<setw(14)<<"姓名"<<setw(14)<<"课程1"<<setw(14)
<<"课程2"<<setw(14)<<"课程3"<<"平均分"<<endl;

for (i=0;i<maxcount;i++)
{
t=top;
top=top->next;

cout.flags(ios::left);

cout<<setw(14)<<t->stu.studentnumber<<setw(14)<<
t->stu.studentname<<setw(14)<<t->stu.allcourse.course1<<setw(14)<<t->stu.allcourse.course2
<<setw(14)<<t->stu.allcourse.course3<<setw(14)<<t->stu.allcourse.averagemark<<endl;
}

system("pause");
}

void courseaverage(node *top)/*显示每门课程的平均分*/
{
int maxcount;
node *t=top;
float courseaverage_1=0.00;//********************************
float courseaverage_2=0.00;// 保存各门平均分的变量
float courseaverage_3=0.00;//********************************

fstream readcount("countsave.txt",ios::in);
readcount>>maxcount;
system("cls");

for (int i=0;i<maxcount;i++) //********************************************************************
{
t=top;
top=top->next; //遍历结点累加各门课程分数求平均值
float(courseaverage_1)+=float(t->stu.allcourse.course1);
courseaverage_2+=t->stu.allcourse.course2;
courseaverage_3+=t->stu.allcourse.course3;
} //********************************************************************

cout.flags(ios::left);
cout<<setw(25)<<"课程1"<<setw(25)<<"课程2"<<setw(25)<<"课程3"<<endl;

cout<<setw(25)<<float(courseaverage_1/(maxcount+1))<<setw(25)<<
courseaverage_2/float(maxcount+1)<<setw(25)<<courseaverage_3/float(maxcount+1)<<endl;

system("pause");
}
void orderWithAverageMark(node *top)/*按平均分排序*/
{

struct node *t=top;
static struct node *t0=top; /*保存结点的头*/
float averagemark_1=0.00;
float averagemark_2=0.00;
static char temp[10]; /*保存字符串的中间变量*/
float temp0; /*整型变量的中间变量*/
int maxcount;
int i;
bool flag; /*判断冒泡算法是否结束*/

fstream readcount("countsave.txt",ios::in||ios::out);
readcount>>maxcount;
//*****************************************************************************
//冒泡排序
//if (count
for(int j=0;j<maxcount;j++)
{

top=t0; //结点指针指向表头,执行下一次排序

for (i=0;i<(maxcount-1);i++)
{
flag=false;
t=top;
averagemark_1=t->stu.allcourse.averagemark;
averagemark_2=top->next->stu.allcourse.averagemark;

if (averagemark_1<=averagemark_2)
{ //****************************************************************
strcpy(temp,t->stu.studentnumber);
strcpy(t->stu.studentnumber,top->next->stu.studentnumber);
strcpy(top->next->stu.studentnumber,temp);

strcpy(temp,t->stu.studentname);
strcpy(t->stu.studentname,top->next->stu.studentname);
strcpy(top->next->stu.studentname,temp);

temp0=t->stu.allcourse.course1;
t->stu.allcourse.course1=top->next->stu.allcourse.course1; //交换两结点的各数值
top->next->stu.allcourse.course1=temp0;

temp0=t->stu.allcourse.course2;
t->stu.allcourse.course2=top->next->stu.allcourse.course2;
top->next->stu.allcourse.course2=temp0;

temp0=t->stu.allcourse.course3;
t->stu.allcourse.course3=top->next->stu.allcourse.course3;
top->next->stu.allcourse.course3=temp0;

temp0=t->stu.allcourse.averagemark;
t->stu.allcourse.averagemark=top->next->stu.allcourse.averagemark;
top->next->stu.allcourse.averagemark=temp0; //*************************************************************
flag=true;
}

top=top->next;
}
}
//********************************************************************************************
}

int menu()//主菜单
{
int choice;
cout<<"*******************************************************************************"<<endl;
cout<<"* *"<<endl;
cout<<"* 1. 输入学生信息 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 2. 显示学生平均分 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 3. 显示每门课的平均分 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 4. 显示总分在某平均分以上的学生 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 5. 保存数据 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 0. 退出 *"<<endl;
cout<<"* *"<<endl;
cout<<"*******************************************************************************"<<endl;
cout<<" "<<endl;
cout<<" 请选择:";

loop:cin>>choice;

if (choice>=0&&choice<=5)
return choice;
else
goto loop;

}
int findstdentnumber(node *top,char namestr[5])
{
node *t=top;
int count;

fstream readcount("countsave.txt",ios::in);
readcount>>count;

for (int i=0;i<count;i++)
{
t=top;
top=top->next;
if (strcmp(namestr,t->stu.studentnumber)==0)
{
return 1;
}
}
return 0;
}

node *getinfo()
{
char response='y';
char studentinfo[2][9]; //二维数组保存学号和姓名
float studentcoursemark[3]; //保存各科成绩
int count=0;
static int count0;

void savestudentinfo(node *);
node *readstudentinfo();
void freelist(node *);

fstream readcount("countsave.txt",ios::in);/*读出结点值*/
readcount>>count0;
readcount.close();

do
{
loop0: system("cls");
cout<<endl;
cout<<"请输入学号:";
cin>>studentinfo[0];
cout<<endl;
if(findstdentnumber(top,studentinfo[0]))
{
cout<<"该学号已存在:"<<endl;
system("pause");
strcpy(studentinfo[0]," ");
goto loop0;
}
cout<<"姓名:";
cin>>studentinfo[1];
cout<<endl;
cout<<"课程1:";
cin>>studentcoursemark[0];
cout<<endl;
cout<<"课程2:";
cin>>studentcoursemark[1];
cout<<endl;
cout<<"课程3:";
cin>>studentcoursemark[2];
top=createlist(studentinfo,studentcoursemark);
count++;
cout<<endl;
cout<<"要继续吗?(y or n)";
cin>>response;
}while(count>=0&&count<30&&(response=='y'||response=='Y'));

orderWithAverageMark(top); /*对链表按学生平均分进行排序*/

fstream savecount("countsave.txt",ios::out);
savecount<<(count+count0);/*保存结点值并累加*/
savecount.close();

savestudentinfo(top); /*保存学生信息到文件*/

return top;
}
void savestudentinfo(node *top) /*保存学生信息*/
{
int i,numberofstudent;
node *head=top;

fstream count("countsave.txt",ios::in);
count>>numberofstudent; /*获得学生个数*/
count.close();

orderWithAverageMark(head);

fstream student("studentinfosave.txt",ios::out);

system("cls");

//遍历链表,保存信息
for (i=0;i<numberofstudent;i++)
{

head=top;
top=top->next;
student<<head->stu.studentnumber<<" "<<head->stu.studentname<<" "<<
head->stu.allcourse.course1<<" "<<head->stu.allcourse.course2<<" "<<
head->stu.allcourse.course3<<endl;

}
student.close();
//*********************
cout<<" 保存成功!"<<endl;
system("pause");
}
node *readstudentinfo() /*从文件读取学生信息*/
{
int numberofstudent;
char studentinfo[2][9];
float studentcoursemark[3];

fstream readcount("countsave.txt",ios::in);
fstream readstuinfo("studentinfosave.txt",ios::in);
readcount>>numberofstudent;

for (int i=0;i<numberofstudent;i++)
{

readstuinfo>>studentinfo[0]>>studentinfo[1]>>studentcoursemark[0]>>
studentcoursemark[1]>>studentcoursemark[2];

top=createlist(studentinfo,studentcoursemark);
}

readcount.close();
readstuinfo.close();
return top;
}

void find(node *top)/*查找函数*/
{
int lowmark=0,i=0,count=0;
struct node *t=top;

system("cls");

cout<<"请输入一个平均分的下限:";
cin>>lowmark;

system("cls");

fstream readcount("countsave.txt",ios::in);
readcount>>count;

cout.flags(ios::left);
cout<<setw(14)<<"学号"<<setw(14)<<"姓名"<<setw(14)<<"课程1"<<setw(14)
<<"课程2"<<setw(14)<<"课程3"<<setw(14)<<"平均分"<<endl;

if(lowmark>=0&&lowmark<=100)
{
for(int j=0;j<count;j++)
{
t=top;
top=top->next;
if(lowmark<=(t->stu.allcourse.averagemark))//****************************显示满足条件的信息
{
cout<<setw(14)<<t->stu.studentnumber<<setw(14)<<t->stu.studentname<<setw(14)<<t->stu.allcourse.course1<<setw(14)
<<t->stu.allcourse.course2<<setw(14)<<t->stu.allcourse.course3<<setw(14)<<t->stu.allcourse.averagemark<<endl;
i++;
}
} //****************************
if (i==0)
{
cout<<endl;
system("cls");
cout<<"找不学生信息!"<<endl;
}
cout<<"共找到"<<i<<"条信息!"<<endl;

system("pause");
}
}

void main()
{

top=readstudentinfo(); /*读取学生信息*/

for(;;)
{
system("cls");

switch(menu())
{

case 1:
top=getinfo();
break;

case 2:
studentaverage(top);
break;

case 3:
courseaverage(top);
break;
case 4:
find(top);
break;
case 5:
savestudentinfo(top);
break;
case 0:
exit(0);
break;

}
}

}