『壹』 《c#程序設計》多元化考核採用大作業的形式,具體要求如下:
《c#程序設計》多元化考核採用大作業的形式
這個內容
有說明嗎
『貳』 我們vb要交程序設計的大作業了。。。誰有做好的程序啊。
已經做了一個簡單
掃雷游戲
『叄』 數據結構程序設計大作業求幫助
建議,數據結構果斷放棄設計與演算法
工作沒太大用處
『肆』 c語言程序設計170行大作業
1 具
2 體
3 什
4 么
5 要
6 求
7
8
9
10
11
12
13
14
15
。。。。。。
『伍』 高級語言程序設計大作業,求幫助。感激不盡。
/** **** **** *** **** *文件包含****** *** *** ** *****/
#include <dos.h> /*DOS介面函數*/
#include <math.h> /*數學函數的定義*/
#include <conio.h> /*屏幕操作函數*/
#include <stdio.h> /*I/O函數*/
#include <stdlib.h> /*庫函數*/
#include <stdarg.h> /*變數長度參數表*/
#include <graphics.h> /*圖形函數*/
#include <string.h> /*字元串函數*/
#include <ctype.h> /*字元操作函數*/
#include <bios.h>
/** **** ***** ******宏代換定義****** ****** *** *****/
#define BWIDTH 50 /*按鍵條的寬度*/
#define BHEIGHT 30 /*按鍵條的高度*/
#define MAX_SCR 15
#define PI 3.141592654
/** **** ********** ***聲明函數** ****** ** **** *****/
void graph(void); /*畫圖形函數聲明*/
void windows(void); /*繪制窗口界面函數聲明*/
void button(int x,int y,int c1,int c2,int c3,char *bt); /*按鍵函數聲明*/
void scr(char scr_main[MAX_SCR],int error); /*屏顯函數聲明*/
int mouse_message(void); /*滑鼠信息函數聲明*/
void visbilemouse(void); /*滑鼠可視化函數聲明*/
void getmouse(int *x,int *y,int *key); /*獲得滑鼠信息函數聲明*/
void drawmouse(int *x,int *y,int *z); /*畫滑鼠函數聲明*/
void jd(int x,int y); /*按鈕焦點函數聲明*/
void calculator(int fun_code); /*實現計算器功能函數聲明*/
void clrnum(int n0,int n1); /*清空Num數組函數聲明*/
void adv(void); /*高級函數功能聲明*/
double qiu_(char *bds_start,char *bds_end); /*求表達式值函數聲明*/
long jie_cheng(long n); /*階乘函數聲明*/
/** **** ***** **** ****定義全局變數* ****** **** ****/
int Maxcolor,Maxx,Maxy; /*定義最大顏色數,邊界*/
char Num[2][MAX_SCR]={{0},{0}}; /*定義存儲數據的二維數組,分別對應雙目運算的數據*/
double Memory=0; /*定義內存存儲數據*/
int Flag=0,Num_flag=0; /*二維數組的第幾維數和第幾個數*/
char fun=0; /*功能變數,對應雙目運算*/
int Mx,My,Mkey,Mk0=-1; /*定義滑鼠的位置和按鍵狀態,初始鍵值為-1*/
int jd0=-1,jd1=-1; /*定義按鍵焦點,按滑鼠鍵後返回0~29或-1*/
char function[30]={'Q','M','R','S','P','B','7','4','1','0','C','8','5','2','F','A','9','6','3','.','%','/','*','-','+','e','^','K','D','='}; /*定義按鍵對應的function[fun_code]*/
char Adv_ch[100]={0}; /*定義表達式數組變數*/
/** **** ***** ** ****** ***主函數** *** *** **** *****/
void main()
{
int message; /*定義通信變數*/
graph(); /*進入圖形模式*/
windows(); /*繪制窗口界面*/
visbilemouse(); /*顯示滑鼠*/
for (;message=mouse_message();)
if (message!=-1) calculator(message); /*用滑鼠輸入數據mouse-message返回jd1到message*/
closegraph(); /*關閉圖形模式*/
} /*message,fun-code,jd1是相互聯系的通信變數*/
/** **** **** *** ***進入圖形模式** *** *** ** ***** *****/
void graph(void)
{
int GraphDriver=DETECT,GraphMode,ErrorCode;
initgraph( &GraphDriver, &GraphMode, "" ); /*初始化圖形系統*/
ErrorCode = graphresult(); /*讀初始化結果*/
if( ErrorCode != grOk ) /*如果初始化時出現錯誤*/
{
printf("Graphics System Error: %s\n",grapherrormsg( ErrorCode ) ); /*顯示錯誤代碼*/
exit(1); /*退出*/
}
/*讀取最大顏色數,最大橫縱座標*/
Maxcolor=getmaxcolor();
Maxx=getmaxx();
Maxy=getmaxy();
}
/** **** *** ** ***** *繪制窗口界面***** ** ** ***** *****/
void windows(void)
{
int i,j;
char btext[30][6]={"QUIT"," MC"," MR"," MS"," M+"," \033 "," 7 "," 4 "," 1 "," 0 "," C "," 8 "," 5 "," 2 ","+/-","ADV"," 9 "," 6 "," 3 "," . "," % "," / "," * "," - "," + ","EXP","X^Y","y\0373X","1/X"," = "};/*定義各鍵的顯示符號*/
int ctext[30]={RED,GREEN,GREEN,GREEN,GREEN,RED,BLUE,BLUE,BLUE,BLUE,RED,BLUE,BLUE,BLUE,BLUE,RED,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,RED}; /*定義各鍵的顯示顏色*/
setbkcolor(WHITE); /*定義背景色*/
setcolor(BLUE); /*設定藍色模式*/
rectangle(10,10,Maxx-10,Maxy-10); /*畫計算器邊框*/
line(10,300,400,300);
line(400,10,400,300);
bar(150,0,245,20);
outtextxy(160,7,"Calculator");
for (i=0;i<=5;i+=1)
for (j=0;j<=4;j+=1)
button(25+i*(BWIDTH+10),100+j*(BHEIGHT+10),WHITE,ctext[i*5+j],ctext[i*5+j],btext[i*5+j]); /*畫按鍵的矩形條*/
scr(Num[Flag],0);
}
/** **** ***** *** ***繪制按鈕** ****** ******** *****/
void button(int x,int y,int c1,int c2,int c3,char *bt)
{
setfillstyle(SOLID_FILL,c1); /*用c1顏色填充*/
bar(x,y,x+BWIDTH,y+BHEIGHT); /*畫按鍵的條形圖*/
setcolor(c2); /*設置c2顏色模式*/
rectangle(x,y,x+BWIDTH,y+BHEIGHT); /*畫矩形框*/
setcolor(c3); /*設置c3顏色模式*/
outtextxy(x+13,y+13,bt); /*字元輸出定位函數*/
}
/** **** ****** ***計算器屏幕顯示** ******* **** *****/
void scr(char scr_main[MAX_SCR],int error)
{
char memory_s[20]; /*定義內存數組來存儲內存數據*/
bar(25,25,375,75); /*畫屏顯的條形圖*/
setcolor(BLUE); /*設置藍色模式*/
rectangle(25,25,375,75); /*畫屏顯的邊框*/
setcolor(GREEN); /*設置綠色模式*/
settextstyle(0,0,3); /*改變字元大小方向函數*/
if (error) {strcpy(scr_main,"error"); setcolor(RED); Flag=0; Num_flag=0; clrnum(0,1); }
outtextxy(30,50,scr_main); /*字元輸出定位函數scr_main中存儲的是主屏數據*/
setcolor(RED); /*設置紅色模式*/
settextstyle(0,0,2); /*改變字元大小方向函數*/
sprintf(memory_s,"M[%f]",Memory); /*將Memory拷貝到memory-s中再按"M[0.000000]"格式化輸出*/
outtextxy(30,30,memory_s); /*字元輸出定位函數,內存顯示*/
}
/** **** **** **** ***鼠 標** ****** **** *****/
/*顯示滑鼠*/
void visbilemouse()
{
union REGS inregs,outregs;
inregs.x.ax=0x01; /*顯示滑鼠*/
int86(0x33,&inregs,&outregs); /*通用軟中斷庫函數*/
}
/*滑鼠消息*/
int mouse_message()
{
drawmouse(&Mx,&My,&Mkey); /*調用畫滑鼠函數*/
for (;Mk0==Mkey;)
{
getmouse(&Mx,&My,&Mkey); /*調用獲得滑鼠函數*/
}
if (Mk0==1)
{Mk0=-1;return jd1;}
if (Mk0==2)
{Mk0=-1;return jd1;}
}
/*獲取滑鼠位置和按鍵,key=1是左鍵,key=2是右鍵*/
void getmouse(int *x,int *y,int *key)
{
union REGS inregs,outregs;
inregs.x.ax=3; /*獲取滑鼠位置和狀態也可以用3*/
int86(0x33,&inregs,&outregs); /*中斷調用*/
*x=outregs.x.cx; /*cx寄存器中存的是橫坐標*/
*y=outregs.x.dx; /*dx寄存器中存的是列坐標*/
*key=outregs.x.bx; /*bx寄存器是按鍵狀態*/
}
/*按鍵後,返回當前滑鼠的x,y和按鍵狀態,直到按鍵後才返回*/
void drawmouse(int *x,int *y,int *z) /*畫滑鼠是利用將一個空矩形存入內存中,然後再在該空矩形中畫滑鼠形狀*/
{
int a=0,b=0,c=0,a_old=0,b_old=0; /*a,b的值可以隨便*/
int *ball; /*定義指向內存的存儲圖形的指針*/
ball=malloc(imagesize(a,b,a+20,b+20)); /*返回矩形的大小*/
getimage(a,b,a+20,b+20,ball); /*第一次將圖形(一個空矩形)存入到內存中,內存中存入的是一個空矩形*/
while(c==0) /*直到按鍵後才返回,不按鍵一直循環*/
{
getmouse(&a,&b,&c); /*a,為橫坐標,b,為列坐標,c為按鍵狀態*/
if(a<0) a=0; /*保證滑鼠左邊不出界*/
if(b<0) b=0; /*保證上面不出界*/
if(a>Maxx-20) a=Maxx-20; /*保證右邊不出界*/
if(b>Maxy-20) b=Maxy-20; /*保證下邊不出界*/
if(a!=a_old || b!=b_old) /*當滑鼠移動時*/
{
putimage(a_old,b_old,ball,0); /*在a_old,b_old輸出圖形,用來擦掉原來的滑鼠*/
jd(a,b);
getimage(a,b,a+20,b+20,ball); /*這條語句是將目前滑鼠所在位置的圖形存貯到ball裡面試著看著有無這條語句的區別*/
/*不需要在獲取了*/
setcolor(BLUE);
setlinestyle(0,0,1);
line(a,b,a+15,b+15/2);
line(a,b,a+15/2,b+15);
line(a+15/2,b+15,a+10,b+25/2);
line(a+15,b+15/2,a+25/2,b+10);
line(a+10,b+25/2,a+15,b+35/2);
line(a+25/2,b+10,a+35/2,b+15);
line(a+15,b+35/2,a+35/2,b+15);/*畫滑鼠*/
}
a_old=a;b_old=b;
} /*while()結束*/
Mk0=c;
*x=a;*y=b;*z=c; /*返回按鍵後滑鼠的位置*/
putimage(a,b,ball,0); /*將滑鼠擦掉,因為存在ball裡面的是一個背景為預設狀態下的一個空矩形*/
free(ball);
}
/** **** **** *** ***按鈕焦點*** *** ** *** *****/
void jd(int x,int y)
{
int i;
jd1=(y-95)/(BHEIGHT+10)+(x-20)/(BWIDTH+10)*5; /*確定滑鼠具體在哪個鍵上,得到編號來對應鍵*/
if (jd0==jd1) return; /*編號未變即滑鼠未移位,返回*/
if (!((x>20&&x<380) && (y>95&&y<295))) jd1=-1; /*超出邊界,編號為-1*/
if (jd0!=-1)
{setcolor(WHITE);
setlinestyle(0,0,3);
rectangle(jd0/5*(BWIDTH+10)+20,jd0%5*(BHEIGHT+10)+95,jd0/5*(BWIDTH+10)+30+BWIDTH,jd0%5*(BHEIGHT+10)+105+BHEIGHT);
} /*將上次突出顯示的黃色擦除*/
if (jd1!=-1)
{setcolor(YELLOW);
setlinestyle(0,0,3);
rectangle((x-20)/(BWIDTH+10)*(BWIDTH+10)+20,(y-95)/(BHEIGHT+10)*(BHEIGHT+10)+95,(x-20)/(BWIDTH+10)*(BWIDTH+10)+30+BWIDTH,(y-95)/(BHEIGHT+10)*(BHEIGHT+10)+105+BHEIGHT);
} /*突出顯示滑鼠所在鍵為黃色*/
jd0=jd1; /*將上次的滑鼠位置賦予jd0,以用於滑鼠位置變化的判斷和突出顯示黃色的擦除*/
}
/** **** ****** ****實現計算器功能* ****** * *****/
void calculator(int fun_code)
{
int i,error=0;
int dot_num=0,e_num=0;
int len=0;
char temp_s[20]={0};
for (i=0;Num[Flag][i];i++) { dot_num+=Num[Flag][i]=='.'?1:0; e_num+=Num[Flag][i]=='e'?1:0; len++;}
Num_flag=len;
for (i=Num_flag;i<MAX_SCR;i++) Num[Flag][i]=0;
switch(function[fun_code])
{case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': if (Num_flag<MAX_SCR-1) Num[Flag][Num_flag++]=function[fun_code]; break;
case '0': if (Num_flag<MAX_SCR-1 && (atof(Num[Flag])!=0 || Num[Flag][0]=='.'))
Num[Flag][Num_flag++]=function[fun_code]; break;
case '.': if (Num_flag<MAX_SCR-1 && dot_num==0) Num[Flag][Num_flag++]=function[fun_code]; dot_num++; break;
case 'e': if (Num_flag<MAX_SCR-1 && e_num==0) Num[Flag][Num_flag++]=function[fun_code]; e_num++; break;
case 'F':
if (Num[Flag][0]=='-')
{for (i=0;i<MAX_SCR-1;i++) Num[Flag][i]=Num[Flag][i+1];}/*左移一位*/
else if (Num_flag<MAX_SCR-1)
{for (i=MAX_SCR-2;i>0;i--) Num[Flag][i]=Num[Flag][i-1]; Num[Flag][0]='-';}/*右移一位*/
break;
case '+':
case '-':
case '*':
case '/':
case '%':
case '^':
case 'K': Flag=1; Num_flag=0; fun=function[fun_code]; clrnum(Flag,Flag); break;
case 'B': if (Num_flag>0) Num[Flag][--Num_flag]=0; break;
case 'A': closegraph();adv(); break;
case 'C': Flag=0; Num_flag=0; clrnum(0,1); break;
case 'M': Memory=0; break;
case 'R': clrnum(Flag,Flag); gcvt(Memory,10,temp_s);strcpy(Num[Flag],temp_s); break;
case 'S': Memory=atof(Num[Flag]); break;
case 'P': Memory+=atof(Num[Flag]); break;
case 'D': if (atof(Num[Flag]))
gcvt(1/atof(Num[Flag]),10,Num[Flag]);
else
error=1;
break;
case '=': Flag=0; Num_flag=0;
switch(fun)
{case '+': gcvt(atof(Num[0])+atof(Num[1]),10,Num[0]); break;
case '-': gcvt(atof(Num[0])-atof(Num[1]),10,Num[0]); break;
case '*': gcvt(atof(Num[0])*atof(Num[1]),10,Num[0]); break;
case '/': if (atof(Num[1]))
gcvt(atof(Num[0])/atof(Num[1]),10,Num[0]);
else error=1;
break;
case '%': gcvt((long)atof(Num[0])%(long)atof(Num[1]),10,Num[0]); break;
case '^': gcvt(pow(atof(Num[0]),atof(Num[1])),10,Num[0]); break;
case 'K': if (atof(Num[1]))
gcvt(pow(atof(Num[0]),1/atof(Num[1])),10,Num[0]);
else error=1;
break;
}
break;
}
scr(Num[Flag],error);
}
/*清空Num數組*/
void clrnum(int n0,int n1)
{
int i;
for (i=0;i<MAX_SCR;i++) Num[n0][i]=Num[n1][i]=0;
}
/*高級功能*/
void adv()
{
char *i;
printf("For example:\n[1+(2-3)]*4/{5%6}+1e3+sin(pi/4)-arctan(1)*4+3^4+5!+ln2.718-log(2+3)|(10^3)\nInput esc to quit\n");
for (;1;)
{
printf("Please input:\n");
gets(Adv_ch);
if (!strcmp(Adv_ch,"quit") || !strcmp(Adv_ch,"esc")) exit(0);
for (i=Adv_ch;i<Adv_ch+strlen(Adv_ch);i++)
{
if (*i=='[' || *i=='{') *i='(';
if (*i==']' || *i=='}') *i=')';
}
printf("=%f\n",qiu_(Adv_ch,Adv_ch+strlen(Adv_ch)-1));
}
}
/*求表達式的值*/
double qiu_(char *bds_start,char *bds_end)
{
char *now;
char temp[100]={0};
int kuo_hao=0,i=0;
for (now=bds_start+1;now<=bds_end;now++)
{if (*now=='+' || *now=='-' || *now=='*' || *now=='/' || *now=='%') i++;
if (*now=='^' || *now=='!' || *now=='s' || *now=='c' || *now=='t' || *now=='l' || *now=='g' || *now=='n') i++;
}
if (!i)
{
now=bds_start;
for (;now<=bds_end;now++) temp[now-bds_start]=*now;
if (temp[0]=='p' && temp[1]=='i') return PI;
return (atof(temp));
}
for (now=bds_end;now>=bds_start;now--)
{
kuo_hao+=(*now==')'?1:0); kuo_hao-=(*now=='('?1:0);
if (*now=='+' && kuo_hao==0) return(qiu_(bds_start,now-1)+qiu_(now+1,bds_end));
if (*now=='-' && kuo_hao==0) return(qiu_(bds_start,now-1)-qiu_(now+1,bds_end));
}
for (now=bds_end;now>=bds_start;now--)
{
kuo_hao+=(*now==')'?1:0); kuo_hao-=(*now=='('?1:0);
if (*now=='*' && kuo_hao==0) return(qiu_(bds_start,now-1)*qiu_(now+1,bds_end));
if (*now=='/' && kuo_hao==0) return(qiu_(bds_start,now-1)/qiu_(now+1,bds_end));
if (*now=='%' && kuo_hao==0) return((long)qiu_(bds_start,now-1)%(long)qiu_(now+1,bds_end));
}
for (now=bds_end;now>=bds_start;now--)
{
kuo_hao+=(*now==')'?1:0); kuo_hao-=(*now=='('?1:0);
if (*(now-3)=='a' && *(now-2)=='r' && *(now-1)=='c' && *now=='s' && *(now+1)=='i' && *(now+2)=='n' && kuo_hao==0)
return(asin(qiu_(now+3,bds_end)));
if (*(now-3)=='a' && *(now-2)=='r' && *(now-1)=='c' && *now=='c' && *(now+1)=='o' && *(now+2)=='s' && kuo_hao==0)
return(acos(qiu_(now+3,bds_end)));
if (*(now-3)=='a' && *(now-2)=='r' && *(now-1)=='c' && *now=='t' && *(now+1)=='a' && *(now+2)=='n' && kuo_hao==0)
return(atan(qiu_(now+3,bds_end)));
if (*(now-3)=='a' && *(now-2)=='r' && *(now-1)=='c' && *now=='c' && *(now+1)=='s' && *(now+2)=='c' && kuo_hao==0)
return(asin(1/qiu_(now+3,bds_end)));
if (*(now-3)=='a' && *(now-2)=='r' && *(now-1)=='c' && *now=='s' && *(now+1)=='e' && *(now+2)=='c' && kuo_hao==0)
return(acos(1/qiu_(now+3,bds_end)));
if (*(now-3)=='a' && *(now-2)=='r' && *(now-1)=='c' && *now=='c' && *(now+1)=='o' && *(now+2)=='t' && kuo_hao==0)
return(atan(1/qiu_(now+3,bds_end)));
if (*now=='s' && *(now+1)=='i' && *(now+2)=='n' && kuo_hao==0) return(sin(qiu_(now+3,bds_end)));
if (*now=='c' && *(now+1)=='o' && *(now+2)=='s' && kuo_hao==0) return(cos(qiu_(now+3,bds_end)));
if (*now=='t' && *(now+1)=='a' && *(now+2)=='n' && kuo_hao==0) return(tan(qiu_(now+3,bds_end)));
if (*now=='c' && *(now+1)=='s' && *(now+2)=='c' && kuo_hao==0) return(1/sin(qiu_(now+3,bds_end)));
if (*now=='s' && *(now+1)=='e' && *(now+2)=='c' && kuo_hao==0) return(1/cos(qiu_(now+3,bds_end)));
if (*now=='c' && *(now+1)=='o' && *(now+2)=='t' && kuo_hao==0) return(1/tan(qiu_(now+3,bds_end)));
}
for (now=bds_end;now>=bds_start;now--)
{
char *x;
kuo_hao+=(*now==')'?1:0); kuo_hao-=(*now=='('?1:0);
if (*now=='l' && *(now+1)=='n' && kuo_hao==0) return(log(qiu_(now+2,bds_end)));
if (*now=='|' && kuo_hao==0)
{x=now;
for (;x>=bds_start;x--)
if (*x=='l' && *(x+1)=='o' && *(x+2)=='g') break;
return(log10(qiu_(now+1,bds_end))/log10(qiu_(x+3,now-1)));
}
}
for (now=bds_end;now>=bds_start;now--)
{
kuo_hao+=(*now==')'?1:0); kuo_hao-=(*now=='('?1:0);
if (*now=='^' && kuo_hao==0) return(pow(qiu_(bds_start,now-1),qiu_(now+1,bds_end)));
if (*now=='!' && kuo_hao==0) return(jie_cheng((long)qiu_(bds_start,now-1)));
}
if (*bds_start=='(' && *bds_end==')') return qiu_(bds_start+1,bds_end-1);
printf("error");
}
/*計算階乘*/
long jie_cheng(long n)
{
long jc=n;
for (n--;n>0;n--) jc*=n;
return jc;
}
『陸』 高級語言程序設計B大作業求幫助
教你一個好辦法,找你學長要一下,一般大學里邊老師給每一屆的學生作業都差不多,當時我們就這么干。
『柒』 Java程序設計大作業
由於這個問題的界面比較簡單,所以就沒有在代碼中做任何優化,樓主可以根據自己的需要調整。主要就是在界面中點擊按鈕,出發相應的功能,然後輸出。大概代碼如下(由於寫的比較快,不足之處還請指出):
package main;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
@SuppressWarnings("serial")
public class Program extends JFrame implements ActionListener {
private int[] numbers;
private JButton maxButton;
private JButton minButton;
private JButton averageButton;
private JButton sumButton;
private JButton sortButton;
private JButton saveButton;
private JButton exitButton;
public void init() {
setLayout(new FlowLayout());
setTitle("學生成績管理系統");
setSize(500, 300);
maxButton = new JButton("最大值");
add(maxButton);
maxButton.addActionListener(this);
minButton = new JButton("最小值");
add(minButton);
minButton.addActionListener(this);
averageButton = new JButton("平均值");
add(averageButton);
averageButton.addActionListener(this);
sumButton = new JButton("總和");
add(sumButton);
sumButton.addActionListener(this);
sortButton = new JButton("排序");
add(sortButton);
sortButton.addActionListener(this);
saveButton = new JButton("保存");
add(saveButton);
saveButton.addActionListener(this);
exitButton = new JButton("退出");
add(exitButton);
exitButton.addActionListener(this);
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void read(int n) {
numbers = new int[n];
for (int i = 0; i < n; i++) {
System.out.println("請輸入第" + i + "個數");
Scanner scanner = new Scanner(System.in);
int temp = scanner.nextInt();
numbers[i] = temp;
}
}
public int max() {
int temp = numbers[0];
int length = numbers.length;
for (int i = 1; i < length; i++) {
temp = (temp >= numbers[i]) ? temp : numbers[i];
}
return temp;
}
public int min() {
int temp = numbers[0];
int length = numbers.length;
for (int i = 1; i < length; i++) {
temp = (temp <= numbers[i]) ? temp : numbers[i];
}
return temp;
}
public double sum() {
double sum = 0;
int length = numbers.length;
for (int i = 0; i < length; i++) {
sum += numbers[i];
}
return sum;
}
public double average() {
double sum = sum();
int length = numbers.length;
return (sum / length);
}
public int[] sort() {
int length = numbers.length;
for (int i = 0; i < length; i++) {
for (int j = i; j < length; j++) {
if (numbers[i] > numbers[j]) {
int temp = numbers[i];
numbers[i] = numbers[j];
numbers[j] = temp;
}
}
}
return numbers;
}
public void save() {
File file = new File("output/data.txt");
try {
FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter osw = new OutputStreamWriter(fos);
for (int i = 0; i < numbers.length; i++) {
osw.write(numbers[i] + " ");
}
osw.flush();
osw.close();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void exit() {
System.exit(0);
}
public static void main(String[] args) {
System.out.println("請輸入學生的人數: ");
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
Program program = new Program();
program.read(n);
program.init();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == maxButton) {
int max = max();
System.out.println("最大值:" + max);
} else if (e.getSource() == minButton) {
int min = min();
System.out.println("最小值:" + min);
} else if (e.getSource() == averageButton) {
double average = average();
System.out.println("平均值:" + average);
} else if (e.getSource() == sumButton) {
double sum = sum();
System.out.println("總和:" + sum);
} else if (e.getSource() == sortButton) {
int[] result = sort();
System.out.println("排序後結果為:");
for (int i = 0; i < result.length; i++) {
System.out.print(((int) result[i]));
System.out.print(" ");
}
} else if (e.getSource() == saveButton) {
save();
System.out.println("保存成功!");
} else if (e.getSource() == exitButton) {
exit();
}
}
}
『捌』 C語言程序設計 【0039】 B卷 大作業2019
這個的話,你們高中班應該有人,是上大學以後學的計算機的,他們應該可以會給你一份比較好的答案。