C 数据结构和患者记录
将健康记录电脑化可以使患者更容易在不同的医疗保健专业人员之间分享他们的健康状况和病史。健康诊所需要你的帮助来将患者的健康记录电脑化。患者的记录包括名字、中间名、姓氏(包括小老等)、性别、出生日期、身高(英寸)、体重(磅)。该诊所需要该计划的以下特点:C 数据结构和患者记录,c,data-structures,C,Data Structures,将健康记录电脑化可以使患者更容易在不同的医疗保健专业人员之间分享他们的健康状况和病史。健康诊所需要你的帮助来将患者的健康记录电脑化。患者的记录包括名字、中间名、姓氏(包括小老等)、性别、出生日期、身高(英寸)、体重(磅)。该诊所需要该计划的以下特点: 从文件中读取现有记录,其中每个病历都是一行条目,用逗号分隔每个数据 向文件中添加其他记录 一个计算和返回3岁患者年龄的函数 使用给定公式BMI=(体重单位磅X 703)/(身高单位英寸X 2)或BMI=(体重单位千克)/(身高单位米X 2)计算体重
#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);
}
#包括
#包括
main(){
文件*fin;
字符名、fname、mname、lname、ename、性别、ch、getch、患者;
int dob、月、日、年、身高、体重;
fin=fopen(“旧记录c”、“w”){
printf(“错误:文件不存在”);
返回0;
}
{
printf(“添加记录?是/否”);
ch=toupper(getch);
if(ch='y')
打破
}而(1),;
结构病人{
字符名;
char-fname[20];
char-mname[20];
字符名称[20];
性别;
int-dob;
整月;
国际日;
国际年;
内部高度;
整数权重;
printf(“/n患者姓名”);
printf(“名字:”);
scanf(“%s”和patient.fname);
printf(“中间名:”);
scanf(“%s”和patient.mname);
printf(“姓氏:”);
scanf(“%s”和patient.lname);
printf(“性别:”);
scanf(“%s”和患者性别);
printf(“出生日期”);
printf(“月份:”);
scanf(“&d”、&patient.month);
printf(“日:”);
scanf(“&d”和患者日);
printf(“年份:”);
扫描频率(“%s”,患者年百分比);
printf(“高度:”);
扫描频率(“%d”和患者身高);
printf(“重量:”);
扫描频率(“%d”和患者体重);
}
我已经制作了另一个文件,但当我运行代码时,它会显示“错误:文件不存在”。出了什么问题,其他问题的代码是什么?请帮助我!这是我们对数据结构主题的最终要求
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
所有语句都将执行
如果块中有条件,则将其置于块中
这样写-
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("%c", &patient.gender);
...
scanf("%d", &patient.year);
其他问题是这些陈述-
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
像这样写这些陈述-
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("%c", &patient.gender);
...
scanf("%d", &patient.year);
请编辑您的标签到C++或CA健康诊所需要我的帮助吗?哦,孩子!您需要请将代码格式化并使其能够编译。然后您需要在特定问题上寻求帮助,而不是“其他问题的代码是什么?”你不应该让别人帮你做作业。你希望如何学习?请也改进文本格式。谢谢。在我看来,现在看起来好多了。:-@graced%s
期望char*
当你传递数组时,它会衰减到指针。所以如果你传递它的地址,它的类型将是char**
,而不是必修的。