Thursday, November 24, 2016

Programming Challenge 4.19 - Spectral Analysis

/* Spectral Analysis - If a scientist knows the wavelength of an electromagnetic
   wave, he or she can determine what type of radiation it is. This program asks
   for the wavelength of an electromagnetic wave in meters and then displays what
   that wave is according to the following chart:
  
                  1 × 10^2          1 × 10^3          7 × 10^7          4 × 10^7          1 × 10^8          1 × 10^11           
    <__|__|__|__|__||__|__|__|__|__||__|__|__|__|__||__|__|__|__|__||__|__|__|__|__||__|__|__|__|__||__|__|__|__|__>
     Radio Waves    /   Microwaves /    Infrared   / Visible Light /  Ultraviolet    /     X Rays    /  Gamma Rays

   A wave with a wavelength of 1E-10 meters would be an X-ray. */

#include "Utility.h"

int main()
{
    /* Constants for ranges of minimum and maximum wavelengths in (m) */
    const double GAMMA_RAYS_MIN = 1E-15,
                 GAMMA_RAYS_MAX = 1E-11,
                 X_RAYS_MIN = 1E-11,
                  X_RAYS_MAX = 1E-8,
                 UV_LIGHT_MIN = 1E-8,
                 UV_LIGHT_MAX = 3.8E-7,
                 VISIBLE_LIGHT_MIN = 3.8E-7,
                 VISIBLE_LIGHT_MAX = 7.5E-7,
                 IR_LIGHT_MIN = 7.5E-7,
                 IR_LIGHT_MAX = 1E-3,
                 MICROWAVES_MIN = 1E-3,
                 MICROWAVES_MAX = 1E-1,
                 RADIOWAVES_MIN = 1E-1,
                 RADIOWAVES_MAX = 1E+7;

    /* Hold wavelength */
    double wavelength;

    /* Test output and validation */
    cout << "Enter wavelength in scientifc notation: ";
    cin >> wavelength;
       
    /* Determine the kind of spectrum and display the result - Due to the
       nature of overlapping occuring, to have X-Rays displayed instead of
       Gamma Rays or vice versa, the input would have to be 1.1E-11 or
       .1E-11, or 2E-11 ... as there is no other way of distinction. The
       program than displays the smaller Gamma Ray instead of the greater
       X-Ray as a result. */
        if (wavelength >= GAMMA_RAYS_MIN && wavelength <= GAMMA_RAYS_MAX)
        {
            cout << "Gamma Rays.\n";
        }
        else if (wavelength >= X_RAYS_MIN && wavelength <= X_RAYS_MAX)
        {
            cout << "X-rays.\n";
        }
        else if (wavelength >= UV_LIGHT_MIN && wavelength <= UV_LIGHT_MAX)
        {
            cout << "UV Light.\n";
        }
        else if (wavelength >= VISIBLE_LIGHT_MIN && wavelength <= VISIBLE_LIGHT_MAX)
        {
            cout << "Visible Light.\n";
        }
        else if (wavelength >= IR_LIGHT_MIN && wavelength <= IR_LIGHT_MAX)
        {
            cout << "Infrared Light.\n";
        }
        else if (wavelength >= MICROWAVES_MIN && wavelength <= MICROWAVES_MAX)
        {
            cout << "Microwaves.\n";
        }
        else if (wavelength <= RADIOWAVES_MAX && wavelength >= RADIOWAVES_MIN)
        {
            cout << "Radiowaves.\n";
        }

        pauseSystem();
    return 0;
}

No comments:

Post a Comment