Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Use only C++) Problem: Complete Programming Challenge 4.19 in your text book (P

ID: 3869653 • Letter: #

Question

(Use only C++)

Problem: Complete Programming Challenge 4.19 in your text book (Problem 19 in the picture above). Do not accept values larger than 10 meters or smaller than 1 x 10-20 meters as input for the wavelength (check with a “simple” or “single-branched” if and ask the user to re-enter if his/her input if it is out of range). In addition to category of the wave also output the frequency and energy of the wave given the formula

= c
where is the wavelength (m), is the frequency, and c is the speed of light in a vacuum (3 x

108 m/sec) and the formula E = h

where E is the energy (J), h is Plank’s constant (6.626 x 10-34 J s), and is the frequency (s-1). Your output should be like the following with your values in the blanks:

“ ________________ meters corresponds to ________________ and has an energy of _______ joules.”

The energy should be output using 4 significant figures.

Note to enter values in scientific notation list the value followed by e and the power of 10. For example you could declare a constant for the value of Plank’s constant with the C++ statement

const double Plank = 6.626e-034;

19. Spectral Analysis mine what type of radiation it is. Write a program that asks for the wavelength of an electromagnetic wave in meters and then displays what that wave is according to the chart below. (For example, a wave with a wavelength of 1E-10 meters would be an X-ray.) 1×10-2 1×10-3 7×10-7 4x1o-7 1×10-8 1×10-11 Radio Waves/Microwaves/ Infrared /Visible Light/ Ultraviolet X-Rays /Gamma Rays

Explanation / Answer

#include <iostream>
#include<string.h>
#include<stdio.h>
#include<iomanip>
using namespace std;

int main() {
   // your code goes here
   double w;
   const double c=3e+8,h=6.626e-34; //initialize Planks constant and speed of light
   char typ[30];
   cin>>w; //input the wavelength in metre
   while(w>10 || w<1e-20) //check if wavelength > 10m or < 10^-20 m
   cin>>w; //if incorrect input, try again
   if(w>=1e-2) //condition for radio waves
   strcpy(typ,"Radio Waves");
   else if(w<1e-2 && w>=1e-3) //condition for microwaves
   strcpy(typ,"Microwaves");
   else if(w<1e-3 && w>=7e-7) //condition for Infrared
   strcpy(typ,"Infrared");
   else if(w<7e-7 && w>=4e-7) //condition for visible light
   strcpy(typ,"Visible Light");
   else if(w<4e-7 && w>=1e-8) //condition for ultraviolet
   strcpy(typ,"Ultraviolet");
   else if(w<1e-8 && w>=1e-11) //condition for X-ray
   strcpy(typ,"X-ray");
   else
   strcpy(typ,"Gamma Rays");    //condiion for gamma ray
   //setprecision(4) sets the significnt digits to 4 which is great
   //wavelength*frequency=velocity
   //Energy is h/wavelength
   cout<<setprecision(4)<<w<<" meters corresponds to "<<typ<<", has a frequency of "<<c/w<<"Hz"<<" and has an energy of "<<h*c/w<<" joules.";
  
   return 0;
}

//Hope you find the answer well. Keep Chegging, we're happy to help!