| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3349 人关注过本帖, 1 人收藏
标题:血型遗传
取消只看楼主 加入收藏
zh7744123
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2020-5-2
结帖率:100%
收藏(1)
 问题点数:0 回复次数:3 
血型遗传
能不能修改一下这个源代码?血型遗传的。#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;
}
搜索更多相关主题的帖子: int break count 输入 printf 
2020-05-27 18:59
zh7744123
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2020-5-2
收藏
得分:0 
这源代码是对的,我就想能不能有其他的写法。
根据血型遗传关系,编程实现:○1.输入父亲或母亲一个人的血型时,输出子女可能的血型,○2.输入子女的血型时,输出其父母可能的血型,○3.同时输入父亲和母亲的血型时,输出子女可能的血型, ○4.同时输入父母和子女血型时能判断是否具有血型血缘关系。
○1.程序运行时有友好的操作提示界面;
○2.可进行多人次输入,将血型关系总表输入文件保持,在主菜单中能选择查看血型关系总表;
    ○3.有输入错误检查,并限制出错次数,如:应输入字母时输入其它内容,能提示错误并要求重新输入;
○4.程序中有详细的注释说明;
2020-05-27 19:25
zh7744123
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2020-5-2
收藏
得分:0 
能不能改成指针类型啊
2020-05-27 21:48
zh7744123
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2020-5-2
收藏
得分:0 
哪个大佬帮我写一下呀,呜呜呜
2020-05-27 21:57
快速回复:血型遗传
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026093 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved