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. //Input validation: Display error if wavelength less than or equal to 0
  43. if (wavelength <= 0) {
  44. cout << "\nError! Your wavelength value must be greater than 0 meters.\n";
  45. }
  46. else {
  47. //Analyze if radio waves present
  48. if (wavelength < 1E-11) {
  49. cout << "\nAt a wavelength of " << wavelength <<
  50. " meters, gamma rays are present.\n";
  51. }
  52.  
  53. //Analyze if microwave radiation is present
  54. else if (wavelength < 1E-8) {
  55. cout << "\nAt a wavelength of " << wavelength <<
  56. " meters, X rays are present.\n";
  57. }
  58.  
  59. //Analyze if infrared radiation is present
  60. else if (wavelength < 4E-7) {
  61. cout << "\nAt a wavelength of " << wavelength <<
  62. " meters, ultraviolet radiation is present.\n";
  63. }
  64.  
  65. //Analyze if visible light is present
  66. else if (wavelength < 7E-7) {
  67. cout << "\nAt a wavelength of " << wavelength <<
  68. " meters, visible light is present.\n";
  69. }
  70.  
  71. //Analyze if ultraviolet radiation is present
  72. else if (wavelength < 1E-3) {
  73. cout << "\nAt a wavelength of " << wavelength <<
  74. " meters, infrared radiation is present.\n";
  75. }
  76.  
  77. //Analyze if X rays are present
  78. else if (wavelength < 1E-2) {
  79. cout << "\nAt a wavelength of " << wavelength <<
  80. " meters, microwave radiation is present.\n";
  81. }
  82.  
  83. //Analyze if gamma rays are present
  84. else {
  85. cout << "\nAt a wavelength of " << wavelength <<
  86. " meters, radio waves are present.\n";
  87. }
  88. }
  89. return 0;
  90. }
  91.  
  92.  
Success #stdin #stdout 0s 5288KB
stdin
1e-5
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-05 meters, infrared radiation is present.