Question

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 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 double-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, B:2, G:100).  You should include 6 setter methods to increase and decrease each component (e.g. increaseRed), not to exceed 255 or be less than 0.  You should include a 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
using namespace std;

class color{
public:
int r,g,b;
color(int r=254,int b=2,int g=100)
{
this->r = r;
this->g = g;
this->b = b;
}
void increaseRed()
{
if(this->r < 255)
this->r++;
}
void increaseGreen()
{
if(this->g < 255)
this->g++;
}
void increaseBlue()
{
if(this->b < 255)
this->b++;
}
void decreaseRed()
{
if(this->r > 0)
this->r--;
}
void decreaseGreen()
{
if(this->g > 0)
this->g--;
}
void decreaseBlue()
{
if(this->b>0)
this->b--;
}

string toString()
{
double luminance = (0.2126*this->r + 0.7152*this->g + 0.0722*this->b);

ostringstream str;
str << "RED : " << this->r <<" ; Green : " << this->g <<" ; Blue : " << this->b <<" ; Luminanace : " << luminance ;

return str.str();

}

void Inverse()
{
ostringstream str;
str << "RED : " << 255 - this->r <<" ; Green : " << 255 - this->g <<" ; Blue : " << 255 - this->b ;

cout< }
};

int main()
{
color clr;
cout <

int n=1;

while(n!=0)
{
cout<<"Enter Your choice\n1. Show Color \n2. Increase intensity \n3. Decrease intensity \n4. Inverse Display\n0. Exit\n";
cin>>n;
switch(n)
{
case 1: cout< case 2: { cout<<"Which Color \n1.Red \n2.Green\n3.Blue\n";
int c; cin>>c;
switch(c){
case 1: clr.increaseRed(); break;
case 2: clr.increaseGreen(); break;
case 3: clr.increaseBlue(); break;
default : cout<<"Please enter either 1 or 2 or 3"< }
break;
}
case 3: { cout<<"Which Color \n1.Red \n2.Green\n3.Blue\n";
int c; cin>>c;
switch(c){
case 1: clr.decreaseRed(); break;
case 2: clr.decreaseGreen(); break;
case 3: clr.decreaseBlue(); break;
default : cout<<"Please enter either 1 or 2 or 3"< }
break;
}
case 4: clr.Inverse(); break;
case 0: n=0; break;
default : cout<<"Please enter any number from 0 to 5"< }
}
clr.Inverse();
return 0;
}

//let me know if you find any difficulty.

Add a comment
Know the answer?
Add Answer to:
C ++ Exercises (TV)
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
  • 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...

  • WRITE IN PSEUDOCODE USING THE FOLLOWING GUIDELINES Classes Program 1: WAKA, WAKA. Pac-Man was a big...

    WRITE IN PSEUDOCODE USING THE FOLLOWING GUIDELINES Classes Program 1: WAKA, WAKA. Pac-Man was a big hit back in the 80s. One of the things he could do was “teleport” from one side of the screen to the other, and that’s what we’re going to implement here. For this program, you’re going to write a class (called “PacMan”) that only has two attributes: an X and Y location. Imagine the player is on a 10x10 grid and starts at location...

  • 3.20 LAB: Remove gray from RGB (C Language) Summary: Given integer values for red, green, and...

    3.20 LAB: Remove gray from RGB (C Language) Summary: Given integer values for red, green, and blue, subtract the gray from each value. Computers represent color by combining the sub-colors red, green, and blue (rgb). Each sub-color's value can range from 0 to 255. Thus (255, 0, 0) is bright red, (130, 0, 130) is a medium purple, (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray. (130, 50, 130) is...

  • 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...

  • In computer systems color is represented by RGB format (Red. Green and Blue color components) where...

    In computer systems color is represented by RGB format (Red. Green and Blue color components) where each component can hold a value from 0 to 255. Implement all functions and operators given in the following header file: # include using namespace std; class public://Default constructor//Constructor with parameters//Copy constructor//Getters//Setters//a function that increment all components//a print function to print all components//a function to add two private: int red; int green; int blue; Test your class with an appropriate main ()

  • Very stuck on creating a python program for the below question: Write a program that has...

    Very stuck on creating a python program for the below question: Write a program that has three functions: sepia(), remove_all_red(), and gray_scale() to process the image. Plot all four images. No global variables are allowed. Each function needs parameter(s) in order to manipulate and draw the image. Sepia Tone images are those brownish colored images that may remind you of times past. The formula for creating a sepia tone is as follows: newR = (R × 0.393 + G ×...

  • We’re sure you've seen old black-and-white (actually, grayscale) photos that, over time, have gained a yellowish...

    We’re sure you've seen old black-and-white (actually, grayscale) photos that, over time, have gained a yellowish tint. We can mimic this effect by creating sepia-tinted images. There are several different ways to sepia-tint an image. In one of the simplest techniques, the image is first converted to grayscale, and then each pixel's red and blue components are adjusted, leaving the green component unchanged. Here's the algorithm: · First, we convert the image to grayscale, because old photographic prints were grayscale....

  • Please write a code in python! Define and test a function named posterize. This function expects...

    Please write a code in python! Define and test a function named posterize. This function expects an image and a tuple of RGB values as arguments. The function modifies the image like the blackAndWhite function, but it uses the given RGB values instead of black. images.py import tkinter import os, os.path tk = tkinter _root = None class ImageView(tk.Canvas): def __init__(self, image, title = "New Image", autoflush=False): master = tk.Toplevel(_root) master.protocol("WM_DELETE_WINDOW", self.close) tk.Canvas.__init__(self, master, width = image.getWidth(), height = image.getHeight())...

  • % BACKGROUND:Image processing is the generation of a new image from one or more existing images....

    % BACKGROUND:Image processing is the generation of a new image from one or more existing images. % MATLAB makes it easy to work with images by providing some basic functions % that allow you to read and write images in standard image -file formats, such as JPEG % Locate the attached photo of a blue bird stored in JPEG format, bbird.jpg (must be on same folder as script). % Fill in the ? in the code with correct values 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...

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