2015-10-18 43 views
-4

將健康記錄計算機化可以使患者更容易在他們的各種健康護理專業人員中分享他們的健康概況和病史。一個健康診所需要你的幫助來電腦化病人的健康記錄。病人的記錄包括名字,中間名,姓(包括SR。JR等),性別,出生日期,身高(英寸),體重(以磅計)。該診所要求程序的以下功能:數據結構和患者記錄

  1. 從文件中讀取每個病人的記錄是一個單行條目用逗號分隔每個數據
  2. 添加其他記錄到文件
  3. 一個函數來計算現有記錄並返回患者年齡在3年
  4. 一個函數,計算身體質量指數與給定的公式BMI =(體重磅X 703)/(身高英寸X 2)或BMI =(體重公斤數)/(身高米X 2)
  5. 搜索患者姓名並顯示患者信息wi個年齡和BMI值,包括類
  6. 更新病人的出生,身高和/或體重的最新信息,並保存更新文件
  7. 顯示在表格格式的所有記錄

到目前爲止,我所取得的:

#include<stdio.h> 
#include<stdlib.h> 

main(){ 
FILE*fin; 
char name,fname,mname,lname,ename,gender,ch,getch,patient; 
int dob,month,day,year,height,weight; 
fin=fopen("oldrec.c","w");{ 
printf("Error: File does not exists"); 
return 0; 
} 
{ 
printf("Add Record? y/n"); 
ch=toupper(getch); 
if(ch='y') 
break; 
}while (1); 

struct patient{ 
char name; 
char fname[20]; 
char mname[20]; 
char lname[20]; 
char gender; 
int dob; 
int month; 
int day; 
int year; 
int height; 
int weight; 

printf("/n Patient's Name"); 
printf("First Name: "); 
scanf("%s", &patient.fname); 
printf("Middle Name: "); 
scanf("%s", &patient.mname); 
printf("Last Name: "); 
scanf("%s", &patient.lname); 
printf("Gender: "); 
scanf("%s", &patient.gender); 
printf("Date of Birth"); 
printf("Month: "); 
scanf("&d", &patient.month); 
printf("Day: "); 
scanf("&d", &patient.day); 
printf("Year: "); 
scanf("%s", %patient.year); 
printf("Height: "); 
scanf("%d", & patient.height); 
printf("Weight: "); 
scanf("%d", &patient.weight); 

} 

我做了另一個文件了,但是當我運行代碼,它說:「錯誤:文件不存在」。什麼是錯的,其他問題的代碼是什麼?請幫幫我!這是我對數據結構主題的最終要求。

+2

請編輯您的代碼,無論是C++或C – amdixon

+5

一個健康診所需要*我的幫助?好傢伙! –

+0

您需要格式化該代碼並使其能夠編譯。那麼你需要就特定問題尋求幫助,而不是「其他問題的代碼是什麼?」你不應該讓人們爲你做功課。你如何期望學習? – ChiefTwoPencils

回答

2
fin=fopen("oldrec.c","w");{    // no if 
    printf("Error: File does not exists");  // all statements will be executed 
    return 0;     // and function will terminate here 
} 

當然它會顯示消息,沒有條件。無論fopen是否成功,沒有if所有語句都將被執行。

將它置於具有條件的if塊中。

這樣寫 -

fin=fopen("oldrec.c","w");    
if(fin==NULL){     // check if fin is NULL 
    printf("Error: File does not exists"); 
    return 0; 
} 

其他問題是這些語句 -

scanf("%s", &patient.fname); 
... 
scanf("%s", &patient.mname); 
... 
scanf("%s", &patient.lname); 
...  
scanf("%s", &patient.gender);  // use %c for reading char variable 
... 
scanf("%s", %patient.year);  // use %d to read int 
      ^whats this 

這樣寫這些statemetns -

scanf("%s", patient.fname); 
... 
scanf("%s", patient.mname); 
... 
scanf("%s", patient.lname); 
...  
scanf("%c", &patient.gender);  
... 
scanf("%d", &patient.year); 
+0

@MOehm是的,這很好,我會這樣做:) – ameyCU

+1

謝謝。在我看來,現在看起來好多了。 :-) –

+0

非常感謝。爲什麼沒有名字? –