Question

IN C++!! Program 2: BACK AWAY FROM THE TV! If you sat close enough to an...

IN C++!!

Program 2: BACK AWAY FROM THE TV! If you sat close enough to an old TV, you could see individual (R)ed, (G)reen and (B)lue (or RGB) “phosphors” that could represent just about any color you could imagine (using “additive color model”). When these three color components are at their maximum values, the resulting color is white from a distance (which is amazing – look at your screen with a magnifying glass!). When all are off, the color results in black. If red and green are fully on, you’d get a shade of yellow; red and blue on would result in purple, and so on. For computers, each color component is usually represented by one byte (8 bits), and there are 256 different values (0-255) for each. To find the “inverse” of a color (like triple-clicking your iFone® button), you subtract the RGB values from 255. The “luminance” (or brightness) of the color = (0.2126*R + 0.7152*G + 0.0722*B).

For this program, you need to design (pseudocode) and implement (source code) a Color class that has R, G and B attributes (which can be ints). The constructor should take three parameters representing the initial color of (R:254, G:2, B:100). You should include 6 methods to increase and decrease each component, not to exceed 255 or be less than 0. You should include a method (usually called “toString”) that returns a string representing the current values for each component as well as the luminance. Finally, you should include a method that calculates and prints the inverse color.

Next, create a “driver” (or main) that creates a default color, prints its values to the screen, and enables the user to increase/decrease values as well as print the inverse. It should behave like below.

Sample run:

R:254 G:2 B:100 L:62.6508

Do you want to:

1) Increase Red, 2) Decrease Red

3) Increase Green, 4) Decrease Green

5) Increase Blue, 6) Decrease Blue

7) Print the inverse

or 8) Quit

1

R:255 G:2 B:100 L:62.8634

Do you want to:

1) Increase Red, 2) Decrease Red

3) Increase Green, 4) Decrease Green

5) Increase Blue, 6) Decrease Blue

7) Print the inverse

or 8) Quit

1

R:255 G:2 B:100 L:62.8634

Do you want to:

1) Increase Red, 2) Decrease Red

3) Increase Green, 4) Decrease Green

5) Increase Blue, 6) Decrease Blue

7) Print the inverse

or 8) Quit

7

Inverse is R:0 G:253 B:155

R:255 G:2 B:100 L:62.8634

Do you want to:

1) Increase Red, 2) Decrease Red

3) Increase Green, 4) Decrease Green

5) Increase Blue, 6) Decrease Blue

7) Print the inverse

or 8) Quit

8

R:255 G:2 B:100 L:62.8634

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include
#include
#include
#include
using namespace std;

class MyColor{
private:
double luminance;
  
void setLuminance(){
luminance = 0.2126*R + 0.7152*G + 0.0722*B;
}
public:
static const int MAX = 255;
static const int MIN = 0;
int R,G,B;
  
MyColor(int r, int g, int b){
R = r;
G = g;
B = b;
setLuminance();
}
void increaseRed(){
if(R < MAX)
R++;
setLuminance();
}
void decreaseRed(){
if(R > MIN)
R--;
setLuminance();
}
  
void increaseGreen(){
if(G < MAX)
G++;
setLuminance();
}
void decreaseGreen(){
if(G > MIN)
G--;
setLuminance();
}
  
void increaseBlue(){
if(B < MAX)
B++;
setLuminance();
}
void decreaseBlue(){
if(B > MIN)
B--;
setLuminance();
}
void printInverse(){
cout << "R: "<< (255-R) <<" G: "<< (255-G) <<" B: "<< (255-B);
cout << " L:" << (0.2126*(255-R) + 0.7152*(255-G) + 0.0722*(255-B));
}
  
string toString() const{
return "R:" + to_string(R) +" G: " + to_string(G) + " B:" + to_string(B) + " L:" + to_string(luminance);
}
};


int main(){
MyColor col(155,254,2);
cout << col.toString();
int choice = 0;
  
while(choice != 8) {
//col.printColor();
cout << "\nDo you want to:"
<< "\n1) Increase Red, \n2) Decrease Red"
<< "\n3) Increase Green, \n4) Decrease Green"
<< "\n5) Increase Blue, \n6) Decrease Blue"
<< "\n7) Print the inverse"
<< " or \n8) Quit";
cout << "\nPlease enter your choice: ";
cin >> choice;
switch(choice){
  
case 1:
col.increaseRed();
break;
case 2:
col.decreaseRed();
break;
case 3:
col.increaseGreen();
break;
case 4:
col.decreaseGreen();
break;
case 5:
col.increaseBlue();
break;
case 6:
col.decreaseBlue();
break;
case 7:
col.printInverse();
break;
case 8:
cout<< "Thank You!";
break;
default:
cout << "Invalid Choice";
}
cout << endl<< col.toString()< }

return 0;
}

75 cout \ndo vou want to. R:155 G: 254 B:2 1:214.758200 Do you want to: 1) Increase Red, 2) Decrease Red 3) Increase Green,

Add a comment
Know the answer?
Add Answer to:
IN C++!! Program 2: BACK AWAY FROM THE TV! If you sat close enough to an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C ++ Exercises (TV)

    Program 2: BACK AWAY FROM THE TV!  If you sat close enough to an old TV, you could see individual (R)ed, (G)reen and (B)lue (or RGB) “phosphors” that could represent just about any color you could imagine (using “additive color model”).  When these three-color components are at their maximum values, the resulting color is white from a distance (which is amazing – look at your screen with a magnifying glass!).  When all are off, the color results in black.  If...

  • 7.5 The R, G, and B component images of an RGB image have the horizontal intensity profiles shown...

    7.5 The R, G, and B component images of an RGB image have the horizontal intensity profiles shown in the following diagram. What color would a person see in the middle column of this image? 1.0 Red Green 0.5 N/2 Position N/2 Position Blue · 0.5 N-1 N/2 Position 0 7.5 The R, G, and B component images of an RGB image have the horizontal intensity profiles shown in the following diagram. What color would a person see in the...

  • WRITE A C++ PROGRAM TO ANSWER THE QUESTIONS BELOW. You are provided with an image in...

    WRITE A C++ PROGRAM TO ANSWER THE QUESTIONS BELOW. You are provided with an image in a new file format called JBC Here is an example of the format: 2 3 100 50 40 200 66 56 12 45 65 23 67 210 0 255 100 45 32 123 The first line means that this is a 2 (width) by 3 (height) image of pixels. Then, each line represents the color of a pixel. The numbers are from 0 to...

  • Task In this challenge you parse RGB colors represented by strings. The formats are primarily used...

    Task In this challenge you parse RGB colors represented by strings. The formats are primarily used in HTML and CSS. Your task is to implement a function which takes a color as a string and returns the parsed color as a map (see Examples). Input represents one of the following: color The input string 1.6-digit hexadecimal "#RRGGBB" - Each pair of digits represents a value of the channel in hexadecimal: 00 to FF 2.3-digit hexadecimal "#RGB" - Each digit represents...

  • lab3RGB.c file: #include <stdio.h> #define AlphaValue 100 int main() { int r, g,b; unsigned int rgb_pack...

    lab3RGB.c file: #include <stdio.h> #define AlphaValue 100 int main() { int r, g,b; unsigned int rgb_pack; int r_unpack, g_unpack,b_unpack; int alpha = AlphaValue; printf("enter R value (0~255): "); scanf("%d",&r); printf("enter G value (0~255): "); scanf("%d",&g); printf("enter B value (0~255): "); scanf("%d",&b); while(! (r<0 || g<0 || b <0) ) { printf("A: %d\t", alpha); printBinary(alpha); printf("\n"); printf("R: %d\t", r); printBinary(r); printf("\n"); printf("G: %d\t", g); printBinary(g); printf("\n"); printf("B: %d\t", b); printBinary(b); printf("\n"); /* do the packing */ //printf("\nPacked: value %d\t", rgb_pack); printBinary(rgb_pack);printf("\n");...

  • Write a program which will Ask the user a series of questions using the Scanner object Based on t...

    Write a program which will Ask the user a series of questions using the Scanner object Based on the input, draw a grid of star figures on the DrawingPanel You program should ask your user: . What R, G & B values to create a color to draw the figure? How many stars across should the fgure be? How many stars tall should the figure be? Note that your program does not need to error check the users responses Your...

  • 4. Write a function extract(pixels, rmin, rmax, cmin, cmax) that takes the 2-D list pixels contai...

    Please design the function in version 3 of python 4. Write a function extract(pixels, rmin, rmax, cmin, cmax) that takes the 2-D list pixels containing pixels for an image, and that creates and returns a new 2-D list that represents the portion of the original image that is specified by the other four parameters. The extracted portion of the image should consist of the pixels that fall in the intersection of the rows of pixels that begin with row rmin...

  • In this lab, you will exercise 2 things: programming interrupts and configuring/using the timers. It's assumed...

    In this lab, you will exercise 2 things: programming interrupts and configuring/using the timers. It's assumed you are already well versed in I/O This assignment will be worth 10 points 2 point Configuring timer(s) correctly l point- Configuring interrupts correctly 3 point-Implementing ISRs correctly 1 point- All other required configurations 3 points-Correct program behavior Create a new project in Keil, named "Lab5". In this project, you should: 1 - Disable the Watchdog timer! 2- Configure the LEDs (P1.0 and P2.0,...

  • programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate...

    programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate a game of Roulette. Roulette is a casino game of chance where a player may choose to place bets on either a single number, the colors red or black, or whether a number is even or odd. (Note: bets may also be placed on a range of numbers, but we will not cover that situation in this program.) A winning number and color is...

  • USE MATLAB TO SOLVE 1. Snap a close-up color picture of a person with your phone...

    USE MATLAB TO SOLVE 1. Snap a close-up color picture of a person with your phone or download a picture of your preference in JPG format, transfer/save it to a preferred location on your computer and import the picture into MATLAB. 2. Display the Red, Green and Blue components of the imported pictures in three subplots arranged horizontally; 3. Calculate the minimum and maximum values of the R, G, B components and display them in the titles of each subplots...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT