fork download
  1. //Sam Partovi CS1A Chapter 4, P. 223, #17
  2. //
  3. /*******************************************************************************
  4. *
  5. * CATEGORIZE ELECTROMAGNETIC WAVELENGTH
  6. * ____________________________________________________________
  7. * This program categorizes a given wavelength of electromagnetic waves and
  8. * determines the type of electromagnetic radiation that is present at the
  9. * specified wavelengths.
  10. *
  11. * The analysis is based on the following table (reported in meters):
  12. * 1E-2 and larger = Radio wave 1E-2 to 1E-3 = Microwave
  13. * 1E-3 to 7E-7 = Infrared wave 7E-7 to 4E-7 = Visible light
  14. * 4E-7 to 1E-8 = Ultraviolet 1E-8 to 1E-11 = X ray
  15. * 1E-11 and smaller = Gamma ray
  16. * ____________________________________________________________
  17. * INPUT
  18. * wavelength : Given wavelength in meters
  19. *
  20. * OUTPUT
  21. * Category of electromagnetic radiation
  22. *
  23. ******************************************************************************/
  24. #include <iostream>
  25. #include <iomanip>
  26.  
  27. using namespace std;
  28. int main ()
  29. {
  30. float wavelength; //Given wavelength in meters
  31.  
  32. //Prompt user for wavelength input
  33. cout << "Enter the wavelength of an electromagnetic wave in meters.\n";
  34. cout << "Input can be expressed as a decimal value (e.g. 0.0001) or as "
  35. "scientific notation (e.g. 1E-5)\n";
  36. cout << "------------------------------------------------------\n";
  37. cout << "Wavelength (m): ";
  38. cin >> wavelength;
  39.  
  40. //Determine the type of electromagnetic radiation
  41.  
  42. //Analyze if radio waves present
  43. if (wavelength <= 1E-11) {
  44. cout << "\nAt a wavelength of " << wavelength <<
  45. " meters, gamma rays are present.\n";
  46. }
  47.  
  48. //Analyze if microwave radiation is present
  49. else if (wavelength < 1E-8) {
  50. cout << "\nAt a wavelength of " << wavelength <<
  51. " meters, X rays are present.\n";
  52. }
  53.  
  54. //Analyze if infrared radiation is present
  55. else if (wavelength < 4E-7) {
  56. cout << "\nAt a wavelength of " << wavelength <<
  57. " meters, ultraviolet radiation is present.\n";
  58. }
  59.  
  60. //Analyze if visible light is present
  61. else if (wavelength < 7E-7) {
  62. cout << "\nAt a wavelength of " << wavelength <<
  63. " meters, visible light is present.\n";
  64. }
  65.  
  66. //Analyze if ultraviolet radiation is present
  67. else if (wavelength < 1E-3) {
  68. cout << "\nAt a wavelength of " << wavelength <<
  69. " meters, infrared radiation is present.\n";
  70. }
  71.  
  72. //Analyze if X rays are present
  73. else if (wavelength < 1E-2) {
  74. cout << "\nAt a wavelength of " << wavelength <<
  75. " meters, microwave radiation is present.\n";
  76. }
  77.  
  78. //Analyze if gamma rays are present
  79. else if (wavelength >= 1E-2) {
  80. cout << "\nAt a wavelength of " << wavelength <<
  81. " meters, radio waves are present.\n";
  82. }
  83.  
  84. //Input validation: Display error if wavelength less than or equal to 0
  85. else if (wavelength <= 0) {
  86. cout << "\nError! Your wavelength value must be greater than 0 meters.\n";
  87. }
  88.  
  89. return 0;
  90. }
  91.  
  92.  
Success #stdin #stdout 0.01s 5272KB
stdin
1e-8
stdout
Enter the wavelength of an electromagnetic wave in meters.
Input can be expressed as a decimal value (e.g. 0.0001) or as scientific notation (e.g. 1E-5)
------------------------------------------------------
Wavelength (m): 
At a wavelength of 1e-08 meters, X rays are present.