9) Isaac Newton discovered that a glass prism can split white light apart into i
ID: 3606962 • Letter: 9
Question
9) Isaac Newton discovered that a glass prism can split white light apart into its constituent colors. Red Violet Wavelengths of visible light fall approximately into the range 400-700 nm (nm = nano-meter = 10 meter). 700 nm 400 nm 10 10 10 1 104 10 1 frequency (Hz) wavelength (nm) 10 10010" 10° 107 106 103 10-10-10-3 The table below shows the relationship between wavelength and color Color Wavelength range (nm) 400-424 424-491 491 575 575 -585 585 -647 647-700 Violet Blue Yellow Orange Red Write a C+program that inputs a wavelength and then displays the associated light color. If the wavelength is shorter than 400 nm or longer than 700 nm, display the message "Wavelength outside visual range". Classify boundary wavelengths as the lower-wavelength color. For example, label a wavelength of 424 nm as violet.Explanation / Answer
In this code we are using if else to check for the range for wavelength and the prints the light color associated with it. If the range is above 700 or below 400 error is shown on screen.
*********************************************************************************************************
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Enter the wavelength: ";
int w;
cin >> w;
if(w<400 || w>700)
cout << "Wavelength outside visual range" <<endl;
else if(w<=424)
cout <<"The associated light color is Violet" << endl;
else if(w<=491)
cout <<"The associated light color is Blue" << endl;
else if(w<=575)
cout <<"The associated light color is Green" << endl;
else if(w<=585)
cout <<"The associated light color is Yellow" << endl;
else if(w<=647)
cout <<"The associated light color is Orange" << endl;
else if(w<=700)
cout <<"The associated light color is Red" << endl;
return 0;
}
**************************************************************************************************************
Sample outputs:
***********************************************************************************************************************
I hope this helps you.
If you find my answer helpful,
Kindly rate the answer.
All the best :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.