當前位置:首頁 » 編程語言 » 查找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;

}
}

}