English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

題目要求如下如下(遵守的規範):
INPUT: 資料由檔案輸入
OUTPUT: 1.格式化輸出至標準輸出。 2.格式化輸出至檔案。
作法:用fscanf()和fprintf(),配合陣列運算。
PS:請符合以下INPUT和OUTPUT內容~~~~
===========================================================
以下是INPUT(檔案)內容:

學號 姓名 小考(30%)Mid_exam(30%)Final_Exam (40%)
49041140 陳柏翰 80 65 76
49121126 許祐達 56 45 55
49121137 黃帥捷 71 55 25
49121149 劉興文 25 13 45
49121157 張瓊方(女) 21 88 98
49121228 陳宗佑 85 98 88

以下是OUTPUT(檔案)內容

學號 姓名 小考(30%) Mid_exam(30%) Final_Exam (40%) 學期成績

49041140 陳柏翰 80 65 76 73.6
49121126 許祐達 56 45 55 52
49121137 黃帥捷 71 55 25 49.3
49121149 劉興文 25 13 45 27.6
49121157 張瓊方(女) 21 88 98 69
49121228 陳宗佑 85 98 88 90.3
平均: 44.3 60.6 64.5 60.3
註:由於縮排原因,成績與文字無法對其欄位,所以請把檔案的內容欄位當作已對齊

PS:麻煩各位高手用C語言寫,不要用C++或VB之類的寫~~我看不懂,我只會C語言
雖然我很想給更多點數,但是最多只能給20點~希望各位高手可以留您的即時 通,教導能夠更方便快速~~我身上也有題目可以傳送!!

2006-08-15 22:26:06 · 4 個解答 · 發問者 Saxon~ 2 in 電腦與網際網路 程式設計

如果我會就不用發問啦~"~....課本的例題只有一個..而且太簡單...我根本不知道~~陣列要怎用在檔案裡

2006-08-15 23:47:17 · update #1

我看不懂啦=.=...........我才初學ㄝ!!
可不可以幫我做出這個作業呢~??
因為是暑休..所以很趕..拜託啦!!

2006-08-16 11:07:32 · update #2

4 個解答

//Power by Microsoft Visual Studio 2005//可以使用 Dev-C++ 編譯此程式#include #include #define MAX_MEMBER 6//人員數目int main(int argc, char *argv[]){ //=====START=====// void funAverage(const char *FILENAME); char *fileNAME="a.txt";//來源檔名 funAverage(fileNAME); //=====END=====// system("PAUSE"); return 0;}void funAverage(const char *FILENAME){ FILE *fInput,*fOutput;//檔案指標 unsigned int NUMBER,j=0; double S1st,S2nd,S3rd,S4th,dblAverage[4]={0}; char STRING[128],NAME[20];//暫存陣列 fInput=fopen(FILENAME,"r");//開啟檔案 fOutput=fopen("Output.txt","w");//目的檔案名稱 if(fInput!=NULL&&fOutput!=NULL){  fgets(STRING,128,fInput);  fputs(STRING,fOutput);//直接複製第一行  while(!feof(fInput)){//未讀完來源檔案進入迴圈   fscanf(fInput,"%d %s %lf %lf %lf\n",&NUMBER,NAME,&S1st,&S2nd,&S3rd);   //讀取來源   fprintf(fOutput,"%d %s %.1lf %.1lf %.1lf %.1lf\n",NUMBER,NAME,S1st,S2nd,S3rd,(S1st+S2nd+S3rd)/3);   //寫入資料   dblAverage[j]+=S1st;//累加成績數值   dblAverage[j+1]+=S2nd;   dblAverage[j+2]+=S3rd;   dblAverage[j+3]+=(S1st+S2nd+S3rd)/3;//人員成績平均  }//讀完來源檔案則跳出迴圈  for(;j<4;j++){//最後平均   dblAverage[j]/=MAX_MEMBER;  }//寫入最後平均數值  fprintf(fOutput,"平均:%.1lf %.1lf %.1lf %.1lf\n",dblAverage[0],dblAverage[1],dblAverage[2],dblAverage[3]);  fclose(fInput);//關閉檔案  fclose(fOutput); }else{//讀檔建檔失敗  printf("Reading and Building File failed.\n"); }}縮排部分請自行多加幾個空格或 Tab 鍵來區隔!
圖片參考:http://www.geocities.com/linuxhmj/picture/e2.png

2006-08-16 15:58:13 · answer #1 · answered by Big_John-tw 7 · 0 0

到下面的網址看看吧

▶▶http://qoozoo09260.pixnet.net/blog

2014-10-14 13:00:27 · answer #2 · answered by Anonymous · 0 0

//這是以前有幫人家寫的大概
//可以改改看
//這是計算整數的

#include
#include
#include

#define size 5

typedef struct student_t{
char name[100];
int num;
int ch;
int ma;
int en;
}student_p;

int main(){
FILE *fp = NULL;
student_p student[size];
int i=0;
char tmp[1024] = {};
int max=0;
int max_flag=0;
int total=0;

fp = fopen("test.txt","r");
if(fp!=NULL)
while( fscanf(fp,"%i%s%i%i%i",&student[i].num,student[i].name,&student[i].ch,&student[i].ma,&student[i].en) != -1)
i++;

fclose(fp);

fp = fopen("result.txt","w+");
if(fp!=NULL){
for(i=0;i sprintf(tmp,"%i%s%s%s%i%s%i%s%i%s%i%s%i%s",student[i].num," ",student[i].name," ",\
student[i].ch," ",student[i].ma," ",student[i].en,\
" ",student[i].ch+student[i].ma+student[i].en," ",(student[i].ch+student[i].ma+student[i].en)/3,"\n");
fputs(tmp,fp);
memset(tmp,0,1024);
}
sprintf(tmp,"%s","average:");
total=0;
for(i=0;i total = total + student[i].ch;
sprintf(tmp,"%s%i%s",tmp,total/size," ");

total=0;
for(i=0;i total = total + student[i].ma;
sprintf(tmp,"%s%i%s",tmp,total/size," ");

total=0;
for(i=0;i total = total + student[i].en;
sprintf(tmp,"%s%i%s",tmp,total/size," ");

total=0;
for(i=0;i total = total + (student[i].ch+student[i].ma+student[i].en)/3;
sprintf(tmp,"%s%i%s",tmp,total/size," ");

fputs(tmp,fp);
memset(tmp,0,1024);
fclose(fp);
}

return 1;

}

/* test.txt 來源檔 */
123 cosmo 55 66 77
234 dcd1204 66 7 88
345 tretre 100 99 98
893 test 98 65 12
234 klo 26 03 76

/* result.txt 輸出檔 */
123 cosmo 55 66 77 198 66
234 dcd1204 66 7 88 161 53
345 tretre 100 99 98 297 99
893 test 98 65 12 175 58
234 klo 26 3 76 105 35
average:69 48 70 62

2006-08-16 06:52:48 · answer #3 · answered by 3 · 0 0

C語言我不會寫~"~
C++我"可能"寫的出來
看起來不會很難
我想你花些時間因該就會了
課本因該都有些範例吧??
寫程式就是要慢慢學囉^^

2006-08-15 23:42:01 · answer #4 · answered by 老鄧 3 · 0 0

fedest.com, questions and answers