Pls include code to copy for c CS 109CIC Programming for Eng

Pls include code to copy for c++
CS 109-CIC Programming for Engineers w. Matlab-Fall 2016 Homework Assignment 7 Generating Vectors and Tables in C++ for Data Analysis and Plotting Using MatLab Due: Wednesday 30 November at 8:00 AM. optional hard copy may be tumed in to the TA. overall Assignment In an earlier assignment we examined the trigonometric identity shown in (1) for a single set of (u, v) values. For this assignment you will calculate the function for a range of u values and a range ofv values, using functions to perform calculations, store the results in arrays, and save the results to a data file which can then be read in and analyzed using Matlab. sin(u) +sin(v)- 2 sin cos File Format The end goal is a data file containing data in the following format: 0.0 table r l e o The first row contains a zero followed by a vector v murfrontain one plement of a yeonoru followed hs one row of a matrix

Solution

#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <fstream>
#include <iomanip>
#define MAXCOLS 10
#define MAXROW 10
#define ARRAYSIZE 10
using namespace std;

double u[ARRAYSIZE]; // u array
double v[ARRAYSIZE]; // v array
double table[MAXROW][MAXCOLS]; // create table matrix
double minU, minV, maxU, maxV;
int nU, nV;
double trigIdentity(double u, double v){
return sin(u) + sin(v) - 2*(sin(.5*(u + v) * cos(.5*(u - v))));
}

int linespace(double data[], double dataMin, double dataMax, int nPoints){
// if data length is not equal to nPoints return negative values
if(ARRAYSIZE < nPoints){
return -1;
}

// if dataMin > dataMAX return -1;
if( dataMin > dataMax)return -1;

// if npoints = 0
if(nPoints == 0)return -1;

// fill data array
double delta = (dataMax - dataMin) / (nPoints - 1);
for(int i = 0;i < nPoints; ++i){
data[i] = min(dataMin + i*delta, dataMax); // so that data does not overflow as the value is double
}
return 0;
}

int fillTable(double table[][MAXCOLS], double u[], double v[], int nRows, int nCols){
// if MAXCOLS is less than nCols or MAXROW is less than nRows return -1
if(MAXCOLS < nCols || MAXROW < nRows)return -1;

// if no of rows is less than size of u or no of columns is less than size of v return -1
if(nU < nRows || nV < nCols)return -1;

for(int i = 0;i < nRows; ++i){
for(int j = 0;j < nCols; ++j){
table[i][j] = trigIdentity(u[i], v[j]);
}
}
return 0;
}

int writeResults(string filename, double table[][MAXCOLS], double u[], double v[], int nRows, int nCols){
// if MAXCOLS is less than nCols return -1
if(MAXCOLS < nCols)return -1;

// if no of rows is less than size of u or no of columns is less than size of v return -1
if(nU < nRows || nV < nCols)return -1;

ofstream fout;
fout.open(filename.c_str());
if(!fout){
cout << \"Error in creating the file\" << endl;
exit(1);
}

// write 0 and v array
fout << 0 << \"\\t\";
for(int i = 0;i < nCols; ++i){
fout <<setw(15) << v[i];
}
fout << endl;
for(int i = 0;i < nRows; ++i){
fout << u[i];
for(int j = 0;j < nCols; ++j){
fout <<setw(15)<< table[i][j];
}
fout << endl;
}
return 0;
}
int writeToConsole(double table[][MAXCOLS], double u[], double v[], int nRows, int nCols){
// if MAXCOLS is less than nCols return -1
if(MAXCOLS < nCols)return -1;

// if no of rows is less than size of u or no of columns is less than size of v return -1
if(nU < nRows || nV < nCols)return -1;

// write 0 and v array
cout << 0 << \"\\t\";
for(int i = 0;i < nCols; ++i){
cout <<setw(15) << v[i];
}
cout << endl;
for(int i = 0;i < nRows; ++i){
cout << u[i] << \"\\t\";
for(int j = 0;j < nCols; ++j){
cout << setw(15)<< table[i][j];
}
cout << endl;
}
return 0;
}

int main(){

cout << \"Enter the minimum V, maximum V and number of V values respectively in this order\ \";
cin >> minV >> maxV >> nV;
if(linespace(v, minV, maxV, nV) == -1){
cout << \"Problem with the V input, please check it again\" << endl;
exit(1);
}

cout << \"Enter the minimum U, maximum U and number of U values respectively in this order\ \";
cin >> minU >> maxU >> nU;
  
if(linespace(u, minU, maxU, nU) == -1){
cout << \"Problem with the U input, please check it again\" << endl;
exit(1);
}
  
if(fillTable(table, u, v, nU, nV) == -1){
cout << \"Check out the input for table, it contains error\" << endl;
exit(1);
}

string filename;
cout << \"Enter the filename to write the output\ \";
cin >> filename;

writeResults(filename, table, u, v, nU, nV);
writeToConsole(table, u, v, nU, nV);
  

system(\"pause\");
return 0;
}

Enter the minimum V, maximum V and number of V values respectively in this order

3 9 4

Enter the minimum U, maximum U and number of U values respectively in this order

4 8 5

Enter the filename to write the output

abc.txt

0      3 5 7 9

4      -0.755675 -0.270565 -0.858444 -2.10458

5   -2.47923 0 -0.101831 -0.093646

6      -0.764233 0.748607 1.47178 -0.879276

7      2.54366 -0.101831 0 2.91895

8      -0.776554 -0.857089 1.05782 -0.444878

I have changed the code so that you can write to console. I think you are using visual studio. please ask me if your code does not run.

Pls include code to copy for c++ CS 109-CIC Programming for Engineers w. Matlab-Fall 2016 Homework Assignment 7 Generating Vectors and Tables in C++ for Data An
Pls include code to copy for c++ CS 109-CIC Programming for Engineers w. Matlab-Fall 2016 Homework Assignment 7 Generating Vectors and Tables in C++ for Data An
Pls include code to copy for c++ CS 109-CIC Programming for Engineers w. Matlab-Fall 2016 Homework Assignment 7 Generating Vectors and Tables in C++ for Data An

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site