#include <math.h>
#include <iostream>
#include <iomanip>
usingnamespace std;
#define PI 3.14159265
int main ()
{
double rate, result;
rate = 30.0;
result = sin (rate*PI/180);
cout<<"The sine of " << rate << " degrees is " << result <<endl;
return 0;
}
// Text File Writing (SIN and COS).cpp : main project file.
define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
FILE *f;
double x,y,z,t;
f=fopen("c:/data.txt","a+t");
///is this where my excel file goes??
for(t = 0.0; t <= 6.0; t += 0.01)
{
// Make calculations based on t
x = sin(2*M_PI*t);
y = 2*sin(16*M_PI*t/3) + cos (2*M_PI*t/3);
z = x*y;
// Write a data point to the file
fprintf(f,"%.5lf %.5lf %.5lf\n",x,y,z); //5 decimal places of precision
//want to change this to cout? how do i do this?
}
fclose(f);
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
// Some math headers define M_PI for you; some do not
#ifndef M_PI
constdouble M_PI = 3.14159265358979323846;
#endif
usingnamespace std;
int main()
{
double x, y, z, t;
double omega = 2.0 * M_PI;
char *outname = "data.txt";
ofstream outfile(outname);
if (!outfile) {
cout << "Can't open file " << outname << " for writing." << endl;
exit(EXIT_FAILURE);
}
cout << "Opened file " << outname << " for writing." << endl;
outfile << fixed << setprecision(5);
cout << fixed << setprecision(5);
for (t = 0.0; t <= 6.0; t += 0.01) {
// Make calculations based on t
x = sin(omega * t);
y = 2 * sin(8.0*omega * t / 3.0) + cos(omega * t / 3.0);
z = x * y;
// Show the output stuff on the console
// After debugging, you may want to comment out the following line
// I'll write the value of t as well as the computed
// values
cout << t << " " << x << " " << y << " " << z << endl;
// Write a data point to the file
// This puts spaces between the fields. If you want
// commas or tabs, then use "," or "\t" between
// the output values instead of " "
outfile << t << " " << x << " " << y << " " << z << endl;
}
outfile.close();
return 0;
}
Write a C++ program to generate the sampled values of x(t), y(t), and z(t) at the sample rate of 0.01 for 0 less than or equal to t less than or equal to 600. Store the sampled values in their respective files and use Excel program to plot the sampled x(t), y(t), and z(t).
x(t) = sin (2*pi*t)
y(t) = 2*sin (16*pi*t/3) + cos (2*pi*t/3)
z(t) = x(t) * y(t)
Do not use for loop:
for (t=0; t less than 600; t=t+0.01)
instead
use for loop:
for (i=0; t less than 600; i++)
{
}
*Send this character to file '/t'
x[i] << '/t' << y[i] << '/t' << z[i] << endl;