#include
#include
#include
#define size 99
struct record
{
int id;
char name[20];
double data, ration;
struct record *next;
};
struct record *in_node(); /*宣告副程式*/
void out_link_list(struct record *);
void delete_node(struct record *);
void pig();
void mode(int a[],const int an[]); struct record *search_tail(struct record *);
void main(void)
{
char ch;
int count=0,answer;
struct record *lastnode, *head, *up;
FILE *fptr;
fptr= fopen("hw1.txt","r"); // 開檔
if (fptr != NULL){
while ((ch= getc(fptr)) != EOF){ //判斷是否到達檔尾
cout<id=-1;
head->next=NULL;
do
{
cout<<"1.加入新資料:\n";
cout<<"2.刪除資料:\n";
cout<<"3.列印資料:\n";
cout<<"4.計算次數分配表、繪製直方圖:\n";
cout<<"5.計算平均數、中位數、眾數:\n";
cout<<"6.計算全距、標準差、變異係數:\n";
cout<<"7.結束:\n";
cout<<"請輸入選擇功能:";
cin>>answer;
system("cls");
switch(answer)
{
case 1:
up=search_tail(head);
lastnode=in_node();
up->next=lastnode;
system("cls");
break;
case 2:
delete_node(head);
system("cls");
break;
case 3:
out_link_list(head->next);
system("cls");
break;
case 4:
pig();
system("cls");
break;
case 5:
void mode(int a[],const int an[]);
system("cls");
break;
case 6:
system("cls");
break ;
case 7:
exit(0);
default:
cout<<"輸入錯誤!\n";
}
} while(true);
}
struct record *in_node()
{
struct record *newnode;
newnode=(struct record *) malloc(sizeof(struct record));
if(!newnode) exit(0);
cout<<"新增資料筆數:";
cin>>newnode->id;
cout<<"新增資料內容:";
cin>>newnode->name;
newnode->next=NULL;
return newnode;
}
void out_link_list(struct record *thisnode)
{
while(thisnode)
{
cout <<"第"<id<<"筆資料"<<"\t"<<"內容為:"<name<<"\n";
thisnode=thisnode->next;
}
system("cls");
}
void delete_node(struct record *thisnode)
{
int ID;
struct record *up;
cout<<"請輸入欲刪除的筆數:";
cin>>ID;
up=thisnode;
thisnode=thisnode->next;
while(thisnode)
{
if(thisnode->id==ID)
{
up->next=thisnode->next;
break;
}
else
{
up=thisnode;
thisnode=thisnode->next;
}
}
}
struct record *search_tail(struct record *thisnode)
{
do
{
if(thisnode->next==NULL)
break;
else
thisnode=thisnode->next;
} while(true);
return(thisnode);
} void pig()
{
int name[10]={1,1,5,4,2,1,4,5,2,3};
int i,j;
int k;
int b[6]={0};
for(i=0;i<10;i )
{
b[name[i]];
}
cout<<"筆數:"<<"\t"<<"數值:"<<"\t"<<"直方圖:\n";
for(j=1;j<6;j )
{
cout<l)
{
l=a[r];
m=r;
}
for(int h=1;h<=a[r];h )
{
cout<<"*";
}
cout<<"\n";
}
cout<<"\n"<<"眾數為:"< 以上是我的程式碼 我想請問一下 該如何才能把所有case裡的副程式給串起來勒?? 要怎麼改才能讓所有已經打好程式的功能都能讀取到我的txt檔的內容?? 另外... case 5我執行的時候都沒反應 該怎麼修改ㄋ?? 請指教~ 謝謝