栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

16-E-8&9

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

16-E-8&9

#include
#include

struct color 
{
    int red;
    int green;
    int blue;
};

struct color your_color;
struct color* p = &your_color;
struct color const MEGENTA = { .red = 255, .green=0, .blue = 255 };
struct color* q = &MEGENTA;
struct color brighter;
struct color* p_brighter=&brighter;

void check_color(int your_color);
struct color* make_color(int your_red, int your_green, int your_blue);
int get_red(struct color* p);
bool equal_color(struct color* p, struct color* q);
int revise_color(int your_color);
struct color* bighter_color(struct color* p);

int main(void)
{
    int your_red, your_green, your_blue;

    printf("Please enter red,green and blue:");
    scanf_s("%d %d %d", &your_red, &your_green, &your_blue);
    make_color(your_red, your_green, your_blue);

    printf("This is your color:n");
    printf("red:%dn", p->red);
    printf("green:%dn", p->green);
    printf("blue:%dn", p->blue);

    printf("GetRed:%dn", get_red(p));

    if (equal_color(p,q)==true)
    {
        printf("Equal!n");
    }
    else
    {
        printf("Not equal!n");
    }

    bighter_color(p);
    printf("This is the brighter color:n");
    printf("brighter red:%dn", p_brighter->red);
    printf("brighter green:%dn", p_brighter->green);
    printf("brighter blue:%dn", p_brighter->blue);
    
    return 0;
}

struct color* make_color(int your_red, int your_green, int your_blue)
{
    (void)check_color(&your_red);
    (void)check_color(&your_green);
    (void)check_color(&your_blue);
    p->red = your_red;
    p->green = your_green;
    p->blue = your_blue;
    return p;
}

void check_color(int *your_color) 
{
    if (*your_color<0)
    {
        *your_color = 0;
        return;
    }
    if (*your_color>255)
    {
        *your_color = 255;
        return;
    }
}

int get_red(struct color* p)
{
    return p->red;
}

bool equal_color(struct color* p, struct color* q)
{
    if (p->red==q->red)
    {
        if (p->green==q->green)
        {
            if (p->blue==q->blue)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    return false;
}

struct color* bighter_color(struct color* p) 
{
    if (p->red==0&&p->green==0&&p->blue==0)
    {
        p_brighter->red = 3;
        p_brighter->green = 3;
        p_brighter->blue = 3;
        return p_brighter;
    }
    p_brighter->red=revise_color(p->red);
    p_brighter->green = revise_color(p->green);
    p_brighter->blue = revise_color(p->blue);
    return p_brighter;
}

int revise_color(int your_color)
{
    if (your_color<3&&your_color>0)
    {
        return 4;
    }
    if ((int)(your_color/0.7)>255)
    {
        your_color = 255;
        return your_color;
    }
    return (int)(your_color / 0.7);
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/316966.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号