?? zhuhanshu.cpp
字號:
#include "douwenjian1.h"
#include "touwenjian2.h"
main()
{
int j=0,i,funnumber,blank=0,remark=0,sum=0;
float remark1,blank1,sum1,total;
float average;
FILE *fp;
char c2;
struct linkst list;
i=1;
printf("為了測試程序正確與否方便,該程序自帶一個待測試的程序,可以選擇自行輸入或用本程序所自帶的測試程序進行測試\n");
printf("若想用本程序自帶的文件程序測試請按Y,否則按N\n");
c2=getchar();
switch(c2)
{
case 'N':
// 自行輸入程序進行測試
(list.date[i]).ch[0]=getchar();
printf("輸入的函數請以@結束\n");
while( ( (list.date[i]).ch[0] ) !='@'){
//創建程序
list.date[i].row=i;
while((list.date[i]).ch[j] != '\n' && (list.date[i]).ch[j] != '@'){
j++;
(list.date[i]).ch[j]=getchar();
}
(list.date[i]).character=j;
j=0;
i++;
(list.date[i]).ch[j]=getchar();
}
list.mrow=i-1;
break;
case 'Y':
// 用本程序自帶的待測程序進行測試
if((fp=fopen("sum.txt","r"))==NULL){
printf("Can't open the file!\n");
exit(0);
}
(list.date[i]).ch[0]=fgetc(fp);
while( ( (list.date[i]).ch[0] ) !='@'){
//創建程序
list.date[i].row=i;
while((list.date[i]).ch[j] != '\n' && (list.date[i]).ch[j] != '@'){
j++;
(list.date[i]).ch[j]=fgetc(fp);
}
(list.date[i]).character=j;
j=0;
i++;
(list.date[i]).ch[j]=fgetc(fp);
}
list.mrow=i-1;
break;
}
for(i=1;i<=list.mrow;i++)
if((list.date[i]).ch[0]=='\n') blank++;
//計算空行的行數
else if((list.date[i]).ch[0]=='/' && (list.date[i]).ch[1]=='/') remark++;
//計算注釋行的行數
funnumber=accountfun(list);
//每個函數所占的長度,返回函數的個數
sum=list.mrow - blank - remark;
//計算代碼的在程序中所占的行數
printf("Lines of code : %d\n",sum);
printf("Lines of comments: %d\n",remark);
printf("Blank lines: %d\n\n",blank);
average=CountFunAver(sum,funnumber);
//返回程序中函數的平均行數
printf("The program includes %d functions.\n",funnumber);
printf("The average length of a section of code is %7.2f lines\n\n",average);
total=(float)list.mrow;
sum1=(float)sum;
remark1=(float)remark;
blank1=(float)blank;
//將整形數據強制類型轉換為浮點型
JudgeFun(sum1,remark1,blank1,total);
//評價函數風格
return(0);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -