//Sam Partovi CS1A Chapter 4, P. 223, #17
//
/*******************************************************************************
*
* CATEGORIZE ELECTROMAGNETIC WAVELENGTH
* ____________________________________________________________
* This program categorizes a given wavelength of electromagnetic waves and
* determines the type of electromagnetic radiation that is present at the
* specified wavelengths.
*
* The analysis is based on the following table (reported in meters):
* 1E-2 and larger = Radio wave 1E-2 to 1E-3 = Microwave
* 1E-3 to 7E-7 = Infrared wave 7E-7 to 4E-7 = Visible light
* 4E-7 to 1E-8 = Ultraviolet 1E-8 to 1E-11 = X ray
* 1E-11 and smaller = Gamma ray
* ____________________________________________________________
* INPUT
* wavelength : Given wavelength in meters
*
* OUTPUT
* Category of electromagnetic radiation
*
******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
float wavelength; //Given wavelength in meters
//Prompt user for wavelength input
cout << "Enter the wavelength of an electromagnetic wave in meters.\n";
cout << "Input can be expressed as a decimal value (e.g. 0.0001) or as "
"scientific notation (e.g. 1E-5)\n";
cout << "------------------------------------------------------\n";
cout << "Wavelength (m): ";
cin >> wavelength;
//Determine the type of electromagnetic radiation
//Input validation: Display error if wavelength less than or equal to 0
if (wavelength <= 0) {
cout << "\nError! Your wavelength value must be greater than 0 meters.\n";
}
else {
//Analyze if radio waves present
if (wavelength < 1E-11) {
cout << "\nAt a wavelength of " << wavelength <<
" meters, gamma rays are present.\n";
}
//Analyze if microwave radiation is present
else if (wavelength < 1E-8) {
cout << "\nAt a wavelength of " << wavelength <<
" meters, X rays are present.\n";
}
//Analyze if infrared radiation is present
else if (wavelength < 4E-7) {
cout << "\nAt a wavelength of " << wavelength <<
" meters, ultraviolet radiation is present.\n";
}
//Analyze if visible light is present
else if (wavelength < 7E-7) {
cout << "\nAt a wavelength of " << wavelength <<
" meters, visible light is present.\n";
}
//Analyze if ultraviolet radiation is present
else if (wavelength < 1E-3) {
cout << "\nAt a wavelength of " << wavelength <<
" meters, infrared radiation is present.\n";
}
//Analyze if X rays are present
else if (wavelength < 1E-2) {
cout << "\nAt a wavelength of " << wavelength <<
" meters, microwave radiation is present.\n";
}
//Analyze if gamma rays are present
else {
cout << "\nAt a wavelength of " << wavelength <<
" meters, radio waves are present.\n";
}
}
return 0;
}