Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem B: More Colors (30 points) Simple color analysis occurs in many applications. For example, a pixel in a satellite image might be some shade

image text in transcribed
image text in transcribed
Problem B: More Colors (30 points) Simple color analysis occurs in many applications. For example, a pixel in a satellite image might be some shade of green for an area covered with vegetation, but a different color if deforestation has occurred. An astronomical image might have a star or planet of a certain color, and that can indicate something about that bodies' characteristics. This problem asks you to construct a C++ program to work with color again. First have the user input some values. You may assume the values input are always integers, not doubles or characters, etc. To begin the input, have the user input a tolerance. Validate that tolerance: if it is negative ask the user to input a nonnegative tolerance. Do this repeatedly until they enter a nonnegative number. Then ask the user to input red, green, and blue components. Each should be an integer between 0 and 255, inclusive. Validate these: if any is outside that range, have the user input three new components. Do this repeatedly until the user enters three valid components Once the user has input all valid values, then check if the color is a "near gray," i.e., all the components are within (i.e., less than or equal to) the tolerance of each other, and output a message telling if they are or are not. For example, if the tolerance is 5 and the color is (199, 201, 204), then the components are within 5 of each other. But if the tolerance is 3 and the components as (101, 99, 103), then the components are not since the green and blue components differ by 4 If the components are within the tolerance of each other, then your program should also identify which component or components have the largest value, and thien output a message identifying that component or components. (If the components are not within tolerance your program should not do this part.) For example, for the color (28, 100, 97) the largest component is green. For the color (0, 100, 100), the largest are green and blue. Note there are a number of possibilities your program needs to be able to handle all the possibl cases Here are four examples of input and output that show the desired program behavior as well input and output format and language. As usual, user input is underlined. Also usual, make sure you follow this output carefully. For example, notice that the language changes slightly when there is a single largest component versus when there are two or three First example: Input tolerance: 2 Input red, green, and blue components: 255 255 255 The color is a near gray. A1l components are equal Second Example: Input tolerance: Q Input red, green, and blue components: 100 110 100 The color is not a near gray Third Example: Input tolerance: -1 Tolerance must be nonnegative. Input tolerance: 4 Input red, green, and blue components: 99 103 103 The color is a near gray. The green and blue components are largest. Fourth Example: Input tolerance:-2 Tolerance must be nonnegative. Input tolerance:-1 Tolerance must be nonnegative. Input tolerance: 5 Input red, green, and blue components: 00 257 All components must be between 0 and 255, inclusive. Input red, green, and blue components: 99 100 104 The color is a near gray. The blue component is largest

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

Step: 3

blur-text-image

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions