Write a C function with the following prototype: void fillColor(struct Color *p

Place your order now for a similar assignment and have exceptional work written by our team of experts, At affordable rates

For This or a Similar Paper Click To Order Now

Write a C function with the following prototype:
void fillColor(struct Color *p, struct Data d, char type)
This function assigns values to the Color structure ‘p’s members
based on the value in the char variable ‘type’ as follows:
char
type: assigned struct Color *p values:
‘R’ sets p’s name to “Red” and copies d’s struct members ‘r’, ‘g’, and ‘b’ to
p’s ‘red’, ‘green’, and ‘blue’ members respectively.
‘G’ sets p’s name to “Red” and copies d’s struct members ‘r’, ‘g’, and ‘b’ to
p’s ‘red’, ‘green’, and ‘blue’ members respectively.
‘B’ sets p’s name to “Red” and copies d’s struct members ‘r’, ‘g’, and ‘b’ to
p’s ‘red’, ‘green’, and ‘blue’ members respectively.
Q2. Write a C function with the following prototype:
void displayHexCodeAsString(const struct Color *s, int n)
This function accepts ‘n’ Color structures and displays the structure’s ‘name’ and the value
in each of the Color’s integer members (red, green, and blue) as a string in hexadecimal
notation as follows (see below) followed by a newline:
Color:color R:hexString G:hexString B:hexString
You may assume that no integer value will exceed 2147483647 or 7FFFFFFF in Hexadecimal.
Recall, the hexadecimal number system is base16 and contains 16 digits (0 to 9)
and (A to F; where A=10, B=11, C=12, D=13, E=14, and F=15).
HEXADECIMAL 0 1 2 3 4 5 6 7 8 9 A B C D E F
DECIMAL 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
CONVERTING DECIMAL TO HEXADECIMAL
Steps:
1. Divide the decimal number by 16 and treat the division as an integer division
(i.e. the whole number portion only).
2. Compute the remainder by using the modulus operator.
3. Divide the result again by 16 and treat the division as an integer division.
4. Repeat step 2 and 3 until result is 0.
5. The hex value is the digit sequence of the remainders from last to first.
Note: The remainder here refers to the left over value after performing
the integer division. (see example below).
Example: Convert integer 177 to hexadecimal
Solution: Divide 177 by 16 until the quotient is zero.
177/16 = 11, with a remainder of 1
11/16 = 0, with a remainder of 11 (11 is B in hexadecimal)
The remainders from bottom to top would be B1
(so 177 in decimal is B1 in hexadecimal) and the function would display
the output as a string: “B1″ using %s with printf( ).
HINT: Consider using the following char array in your solution:
char hex[17]=”0123456789ABCDEF”;
Given that the position of each char digit in the array parallels its actual
integer value!
/ Your solution may ONLY use functions from the following
// included C library header files.
#include
#include
#define NUM 3
struct Color {
char name[12];
int red, green, blue;
};
struct Data {
int r, g, b;
};
// function prototypes:
void fillColor(struct Color *p, struct Data d, char type);
void displayHexCodeAsString(const struct Color *s, int n);
int main( ) {
char types[NUM] = { ‘G’, ‘B’, ‘R’ };
// hex strings 4000 10 B1 7FFFFFFF 24E 0 BC 100 ABCD
int values[NUM*3] = { 16384, 16, 177, 2147483647, 590, 0, 188, 256, 43981 }, i;
struct Color myColors[NUM];
struct Data myData[NUM];
for(i=0; i<NUM; i++) {
myData[NUM].r = values[i*NUM];
myData[NUM].g = values[i*NUM+1];
myData[NUM].b = values[i*NUM+2];
}
for(i=0; i<NUM; i++)
fillColors(&myColors[i], myData[i], types[i]);
displayHexCodeAsString(myColors, NUM);
return 0;
}
/* ========== CODE TO PLACE IN YOUR SOURCE FILE FOR SUBMISSION STARTS BELOW ========== */
// You may add your own helper functions or symbolic constants here.
// Functions that you add to this code MUST also be prototyped here.
// Correct Program OUTPUT should be:
/*
Color:Green R:4000 G:10 B:B1
Color:Blue R:7FFFFFFF G:24E B:0
Color:Red R:BC G:100 B:ABCD
*/

For This or a Similar Paper Click To Order Now

SmiteWriter
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.