0 like 0 dislike
2.2k views
下面是一個顏色的結構

struct Color {

   int r;

   int g;

   int b;

};

請使用顏色的結構實作以下函數。

void initColor(struct Color *c, int r, int g, int b);

struct Color averageColor(struct Color c[], int n);

double brightness(struct Color c);

void printColor(struct Color *c);

initColor 函數會將c所指向的 Color 結構初始化成 r, g, b的值。

averageColor 函數會分別計算陣列中 r, g, b, 的平均值,函後回傳一個由 r, g, b, 平均值所構成的 Color 結構。

brightness 會計算 c 的亮度,亮度 = ( r + g + b ) / 3。

printColor 會將 c 所指到的顏色結構以 (r, g, b) brightness 的形式印出。

這次作業請把結構的宣告還有函數的宣告放在標頭檔中,實作在另一個檔案裡。
[Exercise] Essay (Open question) - asked in 作業 by (18k points)
ID: 19794 - Available when: Unlimited - Due to: Unlimited

edited by | 2.2k views

7 Answers

0 like 0 dislike
Hidden content!
#ifndef color_RGB



#define color_RGB



#include * *******



struct Color {



 


* * * * ******* **** r;





** * *** * * * * g;


* ** *


** * * * * * b;


*********



};


*** *



void * *** * Color *c, int r, int g, int b)



{


*** ** ***** ** **


*** * * * * *** * * *** * ** = r;


**


*** * ***** * ** * = g;


*** * ** * * * * *


* * *** *** * ***** ****** = b;


*** * * ** ** * * *



}


*



struct Color ** *** Color c[], int n)



{


*** *** ** ** * ***


* ***** * * ***** **** * * ** Color avg;


* *** ** * *** ** * * **


* ** ** ** * * ** ** **** * * *********


* * ** ***** * *


*** * **** * * *** ****** * (i = 0;i < n;i++){


*** ** * * ** * * * ***** ** *** **


* *** ** * * ** * * * * ** *** ** * ** ** += c[i].r;


**** * ** * ** ** **** ** ** ** ** ** * ** * *


* * ** ***** ***** ** **** *** ** * *** ****** ** += c[i].g;


*** ** *** * * * * * * * ** ** * * *


** * * *** ** *** * ** *** ***** ** ******* * += c[i].b;


* * ***** * * *** * * ** * *


* ** *** ** *** * ** * ***


* * ** *** * * * * * **


* * ***** * * * *** * * = sr/n;


** ** *** ** *** * *


* **** ** *** * * * * ** = sg/n;


* * * * * *******


****** **** * ****** ** ** * = sb/n;


*** * * ** ** * * ** * **


* *** * ** ** * ** * avg;


** *******



};


*** *



double * * *** Color c)



{


*******


* * ** *** * *** bright;


* * ** * * * * ***


* * * ** * **** ** ** * = (c.r + c.g + c.b) / 3;


*** * * * * ** **


** * *** * * ** ** ** bright;


*** ** * * * * * ** *



}


** * *



void ** * * * Color *c)



{


* ***** * * * * * * *** *


* * ** ***** ** ** * ** * * ** **** ** ** ****** ** ** * *** ** **


* ** * * * * * ** *** **



}


* ***



#endif
answered by (122 points)
0 like 0 dislike
Hidden content!
#include ** * * *****



struct Color{
* ***** ** ****** ** * * ** * * * ** * r;
* ** * * ** ** * **** * * * * **** * g;
* **** * * ** * * * ** * *** * * ** * b;

};



void initColor(struct Color *c, int r, int g, int b){
*** * *** ** * * ** *** * * *** ** = r;
* * * *** * * **** ********* ** = g;
* * ** *** * ** ** ** * ** ***** * = b;

}



double brightness(struct Color c){
* *** ** * * * * ** * *** * (c.g+c.b+c.r)/3.;

}



void printfColor(struct Color *c){
*** * * * ********* * ** * * ** **** * * *** ** * *** * ** ** ** ***

}



struct Color averageColor(struct Color c[], int n){
* * * * * ***** ** * * *** * ** * * ** * Color c_a = {0,0,0};
** * * * * * * **** * *** * * * * *** *
* ***** *** * ** * * * * * * * ** *
***** * ** * * ** *** * **** * ***** ****** *** ** * *** * * *** += c[i].r;
**** * *** ** ** * * ** ** ** * *** * * **** * * ** **** *** * *** **** += c[i].g;
*** * ***** * ** ** *** * ** * ******* *** ** * ** ** **** *** += c[i].b;
* * ** * ** * * * ** ** ** ** ***
********* ****** * * * ** * * * ** * ** c_a ;

}
answered by (-162 points)
0 like 0 dislike
Hidden content!
void * * **** ** ** ** r,int g,int b)

{ c -> r = r;
* ** * ** * -> g = g;

c -> b = b;

}

struct Color ** ** ** * Color c[],int n)

{
** * * * * * * * ***** * ** * *** Color * * ** *** * Color c[],int c)

{  
* ** * * ** ** * * * *** *** * ** *** * ** ** Color avg;
*** * * *** * * * ** ***** * ** * * * **
* * * * ** ** * ** ** * * *** **** **
*** ** * ** ** ***** ** * ** *** **** ***
** *** ** **** *** ** **** * * * * * * * * += c[i].r;
** * *** **** * ***** ** * ** * ** ** * **** ** ** * * += c[i].g;
** ** **** ** * * * * ** * *** ** ** *** ** * += c[i].b;
** ** ** * ** *** ** **** *** ******* *
* ** * * **** *** ****** * * ** *** ** = tr/n;
**** * ** * * * * * * * **** tg/n;
** * ** * * * ** * * * ** ** tb/n;
** * **** *** *** * *** * *** *** avg;

}

double ** * * Color c)

{
* ** ** ** * **** * ******** ** *** bright * * **
*** ** * * ** ***** * *** *** * *** ** * * bright;

}

void * **** Color*c)

{ * **** *** ** ** * ***** -> r,c -> g,c -> * * * *

}
answered by (-186 points)
0 like 0 dislike
Hidden content!
not finish



#include <stdio.h>



struct Color {
* *** * ** * * *** ** r;
***** ******** ** * g;

   int b;

};



void initColor(struct Color *c, int r, int g, int b){
** ** **** *** ** * * * ** *** ** = r;
* ** *** ********* * * * *** * = g;
** * * **** * * ** **** *** ** * = b;
* **** *** **** * *** * *** *
* * ** ** **** * ** * ** ** **



struct Color averageColor(struct Color c[], int n){
* *** * ******* ** * * * * j=0;
* ***** ** **** ** *** * ** **** ** ** *
** **** * * * * * **** ***** ** **** *** * * Color avg = {0,0,0};
* * * ***** ** * * * * * * * **
** **** *** * * * * * * ** ** * * * *** * (j=0; j<n; j++){
* *** * * *** * * ***** ** *** ** **** * * * *** * *** ***** * * = avg.r + j.r;
* * * ********* * * * ** * * * * * * * ***** * ** * * ** = avg.g + j.g;
** * *** * ** * **** **** ** ** ** ** *** * ** * *** ** ** ** * ** ***** = avg.b + j.b;
*** ** * ***** ** ** **** * ***** *** **** ** * * * **** ** **
* * * *** * ** *** * * * ** *
********* * * * **** * ** ******** **** ** * ** * ** = avg.r / n;
* * ** ** * * * * * * * *** * * *** = avg.g / n;
*** ** * ** * * * * * *** ** * * * ** ** = avg.b / n;
** * *** *** *** * * * * * *** *** * *** *
** * * ** ** * * **** *** * * * *** ** *** avg;
* ** *** * * * * ** * * **** * ** **
* *** * *** * ** * ***** * ***** * * *** ** ** ** *** **



double brightness(struct Color c){
***** ***** * * * ***** * ** ****** ** *** * ( c.r + c.g + c.b ) / 3;
****** * **** * **** *** ** ******



void printColor(struct Color *c){
** *** * *** *** * ** * * *** * * **** ** * ** **
*** *** * * * * *** * **
***** ** * ** * ** * * **** *
answered by (-170 points)
0 like 0 dislike
Hidden content!
#include *** ***

#include * *** *
** ** ********* *** *



 



int main(void) {


** ** * *** * * Color *c;
* ** *** **** ** *** *** *** * * *** * Color));

}

void initColor(struct Color *c, int r, int g, int b)

{
** * ** * * **** * * * ** **** ***
** * * **** *** * ** *** *
* ** * * * * *** ** * * * * *

};

struct Color averageColor(struct Color c[],int n)

{
*** * * * * * * * **** Color a;
* ** ** * * * * * ****** * i=0;
* * ** * * **** * *** * * ** * *
** *** ** * * * ***** ***
** ** * *** ** * **** * * * **** * ***** * **
** *** * ** ******* ** * ***** ********* *** * * ** ***
* * * *** * * * ** ** **** **** *** * ** * * ** *
** * *** **** * * *** * * * * *
* ** **** ** ** * ** *
* * * ** * ** *** *** *
*** ** **** * * ** * ** *
** * ** * * * ** *** ** ** a;

}

double brightness(struct Color c)

{
** *** * * * ****** * L;
* ** ** * ** * * *** * **
** ***** * *** ** * * * * ** L;

}

void printColor(struct Color *c)

{
* * *** * *** * ** ** **** * * ** is ** ****** ** *

}
answered by (-38 points)
0 like 0 dislike
Hidden content!
void initColor(struct Color *c, int r, int g, int b)
* ** **** ** * *****
* **** ** * * * * ** -> r = r;
* * ** ** *** * ** * * * -> g = g;
* **** * * * ** * ** * * -> b = b;  

}



struct Color averageColor(struct Color c[], int n)
* **** ** **
** * * ** ** ** ** * * * * ** ** i,sr = 0,sg = 0,sb = 0;
* * * ***** * * ******* ** * *** ** * *
* * * * * * ** **** ** * * *** **** * = 0;i < n;i++)
** ** *** * ** * * * ***** * * * * **
*** *** * * * ** * * ** ** ******* ******** ** * * += c[i].r;
* * ** * *** ***** ***** * * * ** *** * * += c[i].g;
*** *** * ******* ** ******* * * * **** ** += c[i].b;
* * * ** * * **** * ** **** * **** ** ** * **
* ** ** ** * * **** * * * ** ** * ** * ** * * **
*** * * * ** * ** * *** ** ** * **** = sr / n;
*** ***** ** * ** * * * ** ** ** * *** = sb / n;
** * * * ** * *** * * ** ** * ** * **** = sg / n;
* **** * ** * * * * **** ** * * ** ****
*** * *** ** ** ** ** **** * * ** * **** avg;
* * * **** * * *** ***** * * * **



double brightness(struct Color c)
* **** * ** * ***** ***

*** * *** ** ** * * ** * ** * * ** ** * * * bri = (c.r + c.g + c.b) / 3;
* ** * * * ******* * ***** * * * bri;
* ** *** * * * * * * * *

void printColor(struct Color *c)
*** *** * ***** ***** * * * ********
*** * * *** * *** ** ** **** **** * * *** * **** **** ** * %g",c -> r,c -> g,c -> b,brightness);
*** ** *** **** ** * * * ** * * * ** * ***** ***** *** ** *** **
answered by (-264 points)
0 like 0 dislike
Hidden content!
void initColor(struct Color *c, int r, int g, int b){
** ** *** * ** ** ****** ** * = r;
* * ** **** ** * ** = g;
**** ** * ** ** * ** ** ** ** ** = b;

}



struct Color averageColor(struct Color c[], int n){
* ** * ** *** **** *** *** ******* * *** * **** Color avg;
*** ****** * ****** * **** ** ** * ** i,tr=0,tg=0,tb=0;
** * ** **** * * ***** * **** * *** *** * * *
* * **** ** **** ** * * ** * ** * * **** * * += c[i].r;
** * ** ** * ** ** * *** * * ** ** ** * ** += c[i].g;
*** * * * * * * **** * * * * ** * * * * * ** ** * * * += c[i].b;
* * *** * * * * ** * * **** **** *** *
* * * ***** * * ** * * * * = tr/n;
* ** * *** ** *** * * ** * * * * * ** ** ** ** = tg/n;
*** * * * **** ** * ** ** ** * ***** = tb/n;
* * ** * ** * *** ** * * ** *
**** ** **** * ** ** ****** ** * * * ** ** * avg;

}



double brightness(struct Color c){
* ** ** * * * **** * ** * * ** ******* bright = (c.r+c.g+c.b)/3;
* *** * * ** * ** ** **** * * bright;

}



void printColor(struct Color *c){
****** * * ***** *** * ** *** **** * ** ** * * *** * * * ***

}
answered by (-216 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:104.23.197.94
©2016-2026

Related questions

0 like 0 dislike
23 answers
[Exercise] Essay (Open question) - asked Dec 22, 2016 in 作業 by Shun-Po (18k points)
ID: 19793 - Available when: Unlimited - Due to: Unlimited
| 4.8k views
0 like 0 dislike
65 answers
[Exercise] Coding (C) - asked Nov 24, 2016 in 作業 by Shun-Po (18k points)
ID: 17667 - Available when: Unlimited - Due to: Unlimited
| 10.6k views
0 like 0 dislike
20 answers
[Exercise] Essay (Open question) - asked Nov 10, 2016 in 作業 by Shun-Po (18k points)
ID: 17220 - Available when: Unlimited - Due to: Unlimited
| 3.9k views
0 like 0 dislike
31 answers
[Exercise] Essay (Open question) - asked Nov 3, 2016 in 作業 by Shun-Po (18k points)
ID: 16958 - Available when: Unlimited - Due to: Unlimited
| 6k views
0 like 0 dislike
31 answers
[Exercise] Coding (C) - asked Oct 20, 2016 in 作業 by Shun-Po (18k points)
ID: 14582 - Available when: Unlimited - Due to: Unlimited
| 5.7k views
12,783 questions
183,442 answers
172,219 comments
4,824 users