Problem You are to create a program to help in the analysis

Problem: You are to create a program to help in the analysis of data obtained from an x-ray powder diffractometer used to characterize materials. In the diffractometer a sample is exposed to x-rays of a specific wavelength and a detector placed on a goniometer is used to measure the angles where constructive interference of the diffracted beam occurs (called peaks) and the intensity of these peaks. The location of these peaks is dependent on the atomic structure of the material being examined. This relationship is given by Bragg\'s law which states where n is the harmonic of the diffracted beam (n = 1 for these experiments), is the wavelength of the x-ray, d is the interplanar spacing between planes of specific orientation in the material and (theta) is the angle between the x-ray beam and the sample of the material. What is measured the goniometer is actually twice the angle (e) used Bragg\'s law and is referred to as two-theta or 20. You are to create a program that will read the 2-theta values and the intensities from a file and create a table that will contain the 2-theta values, the intensities, the d values and Q values where (Q 1/(sin())2. The first line of the data file will contain the sample name which should be stored as a string object (note that this name may contain spaces). The second line will contain the anode (the elemental source of the x-ray) as a 2-character symbol which should also be stored as a string object. You will need to use this symbol to determine the wavelength of the x-ray using the table below. You should assume the format of the 2-character symbol will be an upper case letter followed by a lower case letter and the symbol will be one of those listed in the table belovw Anode Wavelength 1.54059 2.28973 1.93604 1.78900 0.70932 0 Mo The 2-theta (first column) and intensity values (second column) will start on the third line and continue on subsequent lines. The intensity values are whole numbers. You should design your program so it will continue to read data until the end of file is reached and count the number of peaks observed. Your output should be a file that contains the name of the sample, the wavelength and a table containing the 2-theta and intensity values from the file plus the calculated d and Q values. The

Solution

Solution:

code:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#define PI 3.14159265
using namespace std;

double calcQ(double theta)
{
/* using the equation Q = 1/(sin(theta))^2 */
double val = sin(theta*PI/180);
return 1/pow(val,2);
}

double calcD(double theta, double wl)
{
/* using the equation d = (n*lambda)/(2*sin(theta)), where n=1 */
double val = sin(theta*PI/180);
return wl/(2*val);
}

int main()
{
string sampleName, anode;
double theta, intensity,wl, d, Q;
int in;
const char separator = \' \';
const int nameWidth = 14;
const int numWidth = 14;

FILE *fp1 = freopen(\"input.txt\", \"r\", stdin);
FILE *fp2 = freopen(\"output.txt\", \"w\", stdin);

getline(cin, sampleName);
cin >> anode;

string anode_arr[5] = {\"Cu\", \"Cr\", \"Fe\", \"Co\", \"Mo\"};
double wl_arr[5] = {1.54059, 2.28973, 1.93604, 1.78900, 0.70932 };

if(anode == \"Cu\") in=0;
else if(anode == \"Cr\") in=1;
else if(anode == \"Fe\") in=2;
else if(anode == \"Co\") in=3;
else if(anode == \"Mo\") in=4;

wl = wl_arr[in];

cout << \"For sample \" << sampleName << \" with anode of \" << anode << \" and wavelength of \" << setprecision(5) << fixed << wl << \"the values are\ \";
cout << left << setw(nameWidth) << setfill(separator) << \"2-theta\";
cout << left << setw(nameWidth) << setfill(separator) << \"Intensity\";
cout << left << setw(nameWidth) << setfill(separator) << \"d values\";
cout << left << setw(nameWidth) << setfill(separator) << \"Q values\";
cout<<\"\ \";

while(fp1 != EOF)
{
cin >> theta >> intensity;
d = calcD(theta, wl);
Q = calcQ(theta);
cout << left << setprecision(4) << fixed << setw(numWidth) << setfill(separator) << theta;
cout << left << setw(numWidth) << setfill(separator) << intensity;
cout << left << setprecision(5) << fixed << setw(numWidth) << setfill(separator) << d;
cout << left << setprecision(6) << fixed << setw(numWidth) << setfill(separator) << Q;
cout<<\"\ \";
}

cout << theta << intensity << d << Q ;

return 0;
}

Please, please upvote and ask your doubts in the comments


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site