YTU 2953: A代码填充--学画画

2953: A代码填充--学画画

时间限制: 1 Sec  内存限制: 128 MB
提交: 62  解决: 52

题目描述

最近小平迷上了画画,经过琨姐的指导,他学会了RGB色彩的混合方法。对于两种颜料1和颜料2,其对应的RGB色彩表示分别为(R1,G1,B1)和(R2,G2,B2)。
将m份颜料1和n份颜料2进行混合,混合后色彩的RGB表示为 ((m*R1+n*R2)/(m+n),(m*G1+n*G2)/(m+n),(m*B1+n*B2)/(m+n))。

注:本题只需要提交填写部分的代码,请按照C++方式提交。

#include <iostream>
using namespace std;
class RGB
{
public:
    RGB(int r=0,int g=0,int b=0);
    friend RGB operator+(RGB &,RGB &);
    friend RGB operator*(int ,RGB &);
    friend RGB operator/(RGB &,int);
    friend ostream& operator<<(ostream&,RGB&);
    friend istream& operator>>(istream&,RGB&);
    RGB RGBmix(RGB &rgb1,RGB &rgb2,int m,int n);
private:
    int red,green,blue;
};
RGB::RGB(int r,int g,int b)
{
    red=r;
    green=g;
    blue =b;
}
istream& operator>>(istream &in,RGB &rgb)
{
    in>>rgb.red>>rgb.green>>rgb.blue;
    return in;
}
ostream& operator<<(ostream &out,RGB &rgb)
{
    out<<rgb.red<<","<<rgb.green<<","<<rgb.blue<<endl;
    return out;
}
RGB operator*(int n,RGB &rgb)
{
    return RGB(n*rgb.red,n*rgb.green,n*rgb.blue);
}
/*
    请在该部分补充缺少的代码
*/

RGB RGB::RGBmix(RGB &rgb1,RGB &rgb2,int m,int n)
{
    RGB t,t1,t2;
    t=(t1=m*rgb1)+(t2=n*rgb2);
    return t/(m+n);
}

int main()
{
    RGB rgb1,rgb2,rgb;
    int m,n;
    cin>>rgb1>>rgb2;
    cin>>m>>n;
    rgb =rgb.RGBmix(rgb1,rgb2,m,n);
    cout<<rgb<<endl;
    return 0;
}

输入

颜料1和颜料2的 R,G,B 成分(均为整数)
颜料1和颜料2的份数(均为整数)

输出

混合颜料的 R,G,B 成分(均为整数,不进行四舍五入)

样例输入

0 0 0 255 255 255
1 1

样例输出

127,127,127

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

#include <iostream>
using namespace std;
class RGB
{
public:
    RGB(int r=0,int g=0,int b=0);
    friend RGB operator+(RGB &,RGB &);
    friend RGB operator*(int ,RGB &);
    friend RGB operator/(RGB &,int);
    friend ostream& operator<<(ostream&,RGB&);
    friend istream& operator>>(istream&,RGB&);
    RGB RGBmix(RGB &rgb1,RGB &rgb2,int m,int n);
private:
    int red,green,blue;
};
RGB::RGB(int r,int g,int b)
{
    red=r;
    green=g;
    blue =b;
}
istream& operator>>(istream &in,RGB &rgb)
{
    in>>rgb.red>>rgb.green>>rgb.blue;
    return in;
}
ostream& operator<<(ostream &out,RGB &rgb)
{
    out<<rgb.red<<","<<rgb.green<<","<<rgb.blue<<endl;
    return out;
}
RGB operator*(int n,RGB &rgb)
{
    return RGB(n*rgb.red,n*rgb.green,n*rgb.blue);
}
RGB operator+(RGB &a,RGB &b)
{
    RGB c;
    c.blue=a.blue+b.blue;
    c.green=a.green+b.green;
    c.red=a.red+b.red;
    return c;
}
RGB operator/(RGB &a,int b)
{
    RGB c;
    c.blue=a.blue/b;
    c.green=a.green/b;
    c.red=a.red/b;
    return  c;
}
RGB RGB::RGBmix(RGB &rgb1,RGB &rgb2,int m,int n)
{
    RGB t,t1,t2;
    t=(t1=m*rgb1)+(t2=n*rgb2);
    return t/(m+n);
}
int main()
{
    RGB rgb1,rgb2,rgb;
    int m,n;
    cin>>rgb1>>rgb2;
    cin>>m>>n;
    rgb =rgb.RGBmix(rgb1,rgb2,m,n);
    cout<<rgb<<endl;
    return 0;
}


原文地址:https://www.cnblogs.com/im0qianqian/p/5989646.html