血型遗传
能不能修改一下这个源代码?血型遗传的。#include<stdio.h>int receive()
{
int in;
int count = 4;
while(count>0)
{
scanf("%d",&in);
if(in>0 && in<5) break;
else
{
count--;
printf("\t\t输入错误!!!您还有%d次输入机会!\n\t\t请输入1、2、3或4:",count);
}
}
return in;
}
void func1(int bloodType[][6])
{
int in, i, j;
int subTable[4] = {0,0,0,0};
printf("\t\t++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t+ 父亲或母亲血型如下:\n");
printf("\t\t+ 1、A型血\n");
printf("\t\t+ 2、B型血\n");
printf("\t\t+ 3、AB型血\n");
printf("\t\t+ 4、O型血\n");
printf("\t\t++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t输入:");
in = receive();
for(i=0; i<16; i++)
{
if(bloodType[i][0] == in)
{
for(j=2; j<6; j++)
{
if(bloodType[i][j] == 1)
subTable[j-2] = 1;
}
}
}
printf("\t\t子女可能出现的血型为:");
if(subTable[0] == 1) printf("\tA型 ");
if(subTable[1] == 1) printf("\tB型 ");
if(subTable[2] == 1) printf("\tAB型 ");
if(subTable[3] == 1) printf("\tO型 ");
printf("\n");
}
void func2(int bloodType[][6])
{
int in, i, j;
char subTable[3] = {'A','B','O'};
printf("\t\t++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t+ 子女血型如下:\n");
printf("\t\t+ 1、A型血\n");
printf("\t\t+ 2、B型血\n");
printf("\t\t+ 3、AB型血\n");
printf("\t\t+ 4、O型血\n");
printf("\t\t++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t输入:");
in = receive();
printf("\t\t父母可能的血型为:\n");
for(i=0; i<10; i++)
{
if(bloodType[i][in+1] == 1)
{
if(bloodType[i][0] == 1) printf("\t\t\tA型 ");
else if(bloodType[i][0] == 2) printf("\t\t\tB型 ");
else if(bloodType[i][0] == 3) printf("\t\t\tAB型 ");
else printf("\t\t\tO型");
if(bloodType[i][1] == 1) printf("+ A型 \n");
else if(bloodType[i][1] == 2) printf("+ B型 \n");
else if(bloodType[i][1] == 3) printf("+ AB型 \n");
else printf("+ O型 \n");
}
}
printf("\n");
}
void func3(int bloodType[][6])
{
int in1, in2;
int i, j;
printf("\t\t++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t+ 血型如下:\n");
printf("\t\t+ 1、A型血\n");
printf("\t\t+ 2、B型血\n");
printf("\t\t+ 3、AB型血\n");
printf("\t\t+ 4、O型血\n");
printf("\t\t++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t请输入父亲血型的选项:");
in1 = receive();
printf("\t\t请输入母亲血型的选项:");
in2 = receive();
for(i=0; i<16; i++)
{
if(bloodType[i][0] == in1 && bloodType[i][1] == in2)
{
printf("\t\t子女可能的血型为:");
for(j=2; j<6; j++)
{
if(bloodType[i][j] == 1)
{
if(j == 2) printf("A型 ");
if(j == 3) printf("B型 ");
if(j == 4) printf("AB型 ");
if(j == 5) printf("O型 ");
}
}
printf("\n");
break;
}
}
}
void func4(int bloodType[][6])
{
int in1, in2, in3;
int i, j, flag = 0;
printf("\t\t++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t+ 血型选择如下:\n");
printf("\t\t+ 1、A型血\n");
printf("\t\t+ 2、B型血\n");
printf("\t\t+ 3、AB型血\n");
printf("\t\t+ 4、O型血\n");
printf("\t\t++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t请输入父亲血型的选项:");
in1 = receive();
printf("\t\t请输入母亲血型的选项:");
in2 = receive();
printf("\t\t请输入子女血型的选项:");
in3 = receive();
for(i=0; i<16; i++)
{
if(bloodType[i][0] == in1 && bloodType[i][1] == in2)
{
if(bloodType[i][in3+1] == 1)
{
printf("\t\t父母和子女有血缘关系\n\n");
flag = 1;
}
break;
}
}
if(flag == 0) printf("\t\t父母和子女没有血缘关系\n\n");
}
void console(int bloodTable[][6])
{
int in, count, isEnd = 0;
while(isEnd != 2)
{
printf("\t\t++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t+ 1、输入父亲或母亲一个人的血型\n");
printf("\t\t+ 2、输入子女的血型\n");
printf("\t\t+ 3、同时输入父亲和母亲的血型\n");
printf("\t\t+ 4、输入父母和子女血型,确认血缘关系\n");
printf("\t\t++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t输入:");
in = receive();
switch(in)
{
case 1 : func1(bloodTable); break;
case 2 : func2(bloodTable); break;
case 3 : func3(bloodTable); break;
case 4 : func4(bloodTable); break;
default : break;
}
printf("\t\t是否要继续查询?\n");
printf("\t\t++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t+ 1、继续\n");
printf("\t\t+ 2、结束\n");
printf("\t\t++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t输入:");
count = 4;
while(count>0)
{
count--;
scanf("%d",&isEnd);
if(isEnd == 1 || isEnd == 2) break;
else printf("\t\t输入错误!!!您还有%d次输入机会!\n\t\t请输入1或2:",count);
}
}
printf("\t\t查询结束!!\n");
}
int main()
{
int table[16][6] = {{1,1,1,0,0,1}, {1,2,1,1,1,1}, {1,3,1,1,1,0}, {1,4,1,0,0,1}, {2,2,0,1,0,1}, {2,3,1,1,1,0}, {2,4,0,1,0,1}, {3,3,1,1,1,0},
{3,4,1,1,0,0},{4,4,1,1,1,0},{2,1,1,1,1,1}, {3,1,1,1,1,0}, {4,1,1,0,0,1}, {3,2,1,1,1,0}, {4,2,0,1,0,1}, {4,3,1,1,0,0}};
console(table);
return 0;
}