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

IN C++ language You are to create a program that will convert the measured angle

ID: 664938 • Letter: I

Question

IN C++ language

You are to create a program that will convert the measured angle (given in degrees) to the corresponding d value. Your program should prompt the user to enter elemental anode source of the x-ray beam (see the table below), and the measured angle (given in degrees). Use a multiway branch to associate the anode source with the wavelength, then outside of the multiway branch calculate the interplanar spacing (d) corresponding to the entered angle assuming n is 1. For example a measured angle of 26.622 degrees corresponds to ad of 3.34573 angstroms when the anode is Cu ( = 1.54059 angstroms).

Bragg’s Law the angles can converted to interplanar spacings of the atom locations by the formula n = 2d sin()

Anode / Wavelength

Cu /1.54059

Cr / 2.28973

Fe /1.93604

Co /1.78900

Mo /0.70932

Your program may use either an if-else if structure or a switch structure Because the user may enter characters in upper or lower case, it may be easier for you to output a table corresponding numbers to the anode rather asking the user to enter a string for the anode.

Your program should use an “if without an else” (or “simple if” ) to confirm that the user enters an angle greater than or equal to 2 degrees and less than or equal to 170 degrees and prompts the user to enter the data again if their value is not within this range. (You should assume the user will not enter an invalid value for the measured angle more than once). You program should not need more than 4 variables

Explanation / Answer

#include <iostream>
#include <math.h>      
#define PI 3.14159265
using namespace std;
int main()
{

int anode_src_code, ang_degree, ang_rad;
float wavelength, inter_planar_spacing;

cout<<"Anode                     Code ";
cout<<"Cu                     1 ";
cout<<"Cr                     2 ";
cout<<"Fe                     3 ";
cout<<"Co                     4 ";
cout<<"Mo                     5 ";
cout<<"enter code for the elemental anode source of the x-ray beam ";
cin >> anode_src_code;
cout<<anode_src_code;
//cout<<"The elemental anode source of the x-ray beam is "<<anode_src;
switch(anode_src_code)
{
  case 1:
   cout<<" Anode is Cu ";
   wavelength=1.54059;
   cout<<" Wavelength is "<< wavelength;
   break;
  case 2:
   cout<<" Anode is Cr ";
   wavelength=2.28973;
   cout<<" Wavelength is "<< wavelength;
   break;
  case 3:
   cout<<" Anode is Fe ";
   wavelength=1.93604;
   cout<<" Wavelength is "<< wavelength;
   break;
  case 4:
   cout<<" Anode is Co ";
   wavelength=1.78900;
   cout<<" Wavelength is "<< wavelength;
   break;
  case 5:
   cout<<" Anode is Mo ";
   wavelength=0.70932;
   cout<<" Wavelength is "<< wavelength;
   break;
  default:
   cout<<" Please enter valid code ";
   
}
cout<<" Enter the measured angle in degrees ";
cin >> ang_degree;
cout << ang_degree;
if(ang_degree<=2 || ang_degree>170)
{

cout << " Please enter a valid angle between 2 and 170 degree ";
cin >> ang_degree;
}
ang_rad=(180/PI)*ang_degree;
cout<< "Angle in radian is "<<ang_rad;

inter_planar_spacing=wavelength/2*(sin(ang_rad));
cout<<" "<<inter_planar_spacing;
}