Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Let color be the following structure: struct color { int red; int green; int blue; } Write functions for question a) to f) a) struct

Let color be the following structure: struct color { int red; int green; int blue; }

Write functions for question a) to f)

a) struct color make_color (int red, int green, int blue); Return a color structure containing the specified red, green, and blue values. If any argument is less than zero, the corresponding member of the structure will contain zero instead. If any argument is greater than 255, the corresponding member of the structure will contain 255.

b) int getRed(struct color c) Returns the value of cs red member

c) bool equal_color(struct color color1, struct color color2); Returns true if the corresponding members of color1 and color2 are equal. (Note: please typedef int as bool, and define true and false as Macros) 2

d) struct color brighter(struct color c); Returns a color structure that represents a brighter version of the color c. The structure is identical to c, except that each member has been divided by 0.7 (with the result truncated to an integer). However, there are three special cases: (1) If all members of c are zero, the function returns a color whose members all have the value 3. (2) If any member of c is greater than 0 but less than 3, it is replaced by 3 before the division by 0.7. (3) If dividing by 0.7 causes a member to exceed 255, it is reduced to 255.

e) struct color darker(struct color c) Returns a color structure that represents a darker version of the color c. The structure is identical to c, except that each member has been multiplied by 0.7 (with the result truncated to an integer).

f) void reset(struct color *p) Reset the red, green and blue member to 0 of the color by using a pointer pointing to it.

g) Write a declaration for a const variable named MAGENTA of type struct color and initialize its members as 255,0, and 255, respectively.

h) Write statements to declare an array of colors using pointer and allocate memory space to it using malloc. The size of the array is 5.

i) Continue the question above and write statements to initialize the colors in the array. Each member in the color should be initialized as 0.

Note: Please test the correctness of the program by writing a main function. And display the output.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions

Question

3. Comment on how diversity and equality should be managed.

Answered: 1 week ago

Question

What is group replacement? Explain with an example. (2-3 lines)

Answered: 1 week ago

Question

8. Do the organizations fringe benefits reflect diversity?

Answered: 1 week ago