黄老师 实验报告五 1
#include <stdio.h>
#include <stdlib.h>
enum Sex
{
Female = 1,
Male
};
typedef struct Input_In
{
enum Sex sex;
char name[20];
unsigned int Height[3];
} Informa;
void Print_Show(void);
void Informa_Gain(Informa *ptr_i);
void Forecast(Informa *ptr_i);
int main(void)
{
Informa *informa;
informa = (Informa *)malloc(sizeof(Informa));
Print_Show();
Informa_Gain(informa);
Forecast(informa);
free(informa);
system("pause");
return 0;
}
void Print_Show(void)
{
printf("*******************************************\n\
* Welcome to Use Height Prediction System *\n\
*******************************************\n\
Please choose the sex:\n1.Female\n2.Male\n");
}
void Informa_Gain(Informa *ptr_i)
{
Informa *p = ptr_i;
int sex_temp;
printf("Your choice is: ");
scanf("%d", &sex_temp);
fflush(stdin);
p->sex = (enum Sex)sex_temp;
printf("May I know your Surname? ");
scanf("%s", p->name);
fflush(stdin);
printf("Hi, Miss %s!\n", p->name);
printf("Could you please input your mother's height(cm): ");
scanf("%d", &p->Height[0]);
fflush(stdin);
printf("Could you please input your father's height(cm): ");
scanf("%d", &p->Height[1]);
}
void Forecast(Informa *ptr_i)
{
Informa *p = ptr_i;
switch (ptr_i->sex)
{
case Female:
p->Height[2] = (p->Height[1] * 0.923 + p->Height[0]) / 2;
break;
case Male:
p->Height[2] = (p->Height[1] + p->Height[0]) * 0.54;
break;
default:
break;
}
printf("Your predicted height is %dcm\n", p->Height[2]);
printf("Thank you for use our “Height Prediction System”!\n");
}