C++ - need help in compiling this version of MP6 can you help in completing this
ID: 3573043 • Letter: C
Question
C++ - need help in compiling this version of MP6
can you help in completing this?
/************************************************************************
* Name: CSC 171
* Date: Today's date MP 6
************************************************************************
* Statement: Produce vector sum, difference, unit vectors, cross product
* and the angle between to R^3 vectors
* Specifications:
* Input - v and w, two vectors in R^3
* Output - v+w, v-w, vxw, unitv, unitw, theta between v and w
*************************************************************************/
#include
#include
#include
using namespace std;
//function declarations
void output(const char [], const double []);
void input(const char[], double[]);
double dot(const double[], const double[]);
int main()
{
// vector declarations
double v[3], w[3], vsum[3], vdiff[3], vcross[3], uv[3], uw[3];
// scalar declarations
double theta, nv, nw;
// 1) prompt and read vectors
input("v", v);
input("w", w);
// 2) determine mangnitude of vectors
nv = sqrt(dot(v, v));
nw = sqrt(dot(w, w));
// 3) loop over dimension of the space
for (int i = 0; i < 3; i++)
{
// 4) vector sum
vsum[i] = v[i] + w[i];
// 5) vector difference
vdiff[i] = v[i] - w[i];
// 6) unit vector v
uv[i] = v[i] / nv;
// 7) unit vector w
uw[i] = w[i] / nw;
}
// 8) vector cross product
vcross[0] = v[1]*w[2]-v[2]*w[1];
vcross[1] = v[2]*w[0]-v[0]*w[2];
vcross[2] = v[0]*w[1]-v[1]*w[0];
// 9) angle theta
theta = acos(dot(v,w)/(nv*nw));
//10) display vectors
output("v" , v);
//PLACE CODE HERE TO OUTPUT VECTOR w
output("w", w);
//PLACE CODE HERE TO OUTPUT unit VECTOR uv
output("unit v", uv);
//PLACE CODE HERE TO OUTPUT unit VECTOR uw
output("unit w", uw);
//PLACE CODE HERE TO OUTPUT VECTOR SUM v + w
output("v + w", vsum);
//PLACE CODE HERE TO OUTPUT VECTOR DIFFERENCE v â w
output("v - w", vdiff);
//PLACE CODE HERE TO OUTPUT VECTOR CROSS PRODUCT v x w
output("v x w", vcross);
//11) display scalar theta
cout << "theta = " << theta << endl;
}
/* Function dot
*
* receives - two R^3 vector reference parameters
* returns - dot product
*************************************************************************/
// Define function dot below
double dot(const double x[], const double y[])
{ double d;
d = 0.0;
for(int i=0; i<3; i++)
d = d + x[i]*y[i];
return d;
}
/* function output
*
* receives - string description value parameter
* - R^3 vector value parameter
* purpose - displays description and formatted vector
*************************************************************************/
void output(const char s[], const double vec[])
{
// display vector and description
cout << s << " = ";
for (int i = 0; i < 3; i++)
cout << setiosflags(ios::fixed || ios::showpoint) << setw(8)
<< setprecision(2) << vec[i];
cout << endl;
}
/* Function input
*
* receives - string description value parameter
* - R^3 vector reference parameter
* purpose - prompts with string
* - inputs vector
*************************************************************************/
void input(const char s[], double vec[])
{
// prompt
cout << "Enter the components for " << s << endl;
// read
for (int i =0; i < 3; i++)
return d;
}
/* function output
*
* receives - string description value parameter
* - R^3 vector value parameter
* purpose - displays description and formatted vector
*************************************************************************/
void output(const char s[], const double vec[])
{
// display vector and description
cout << s << " = ";
for (int i = 0; i < 3; i++)
cout << setiosflags(ios::fixed || ios::showpoint) << setw(8)
<< setprecision(2) << vec[i];
cout << endl;
}
/* Function input
*
* receives - string description value parameter
* - R^3 vector reference parameter
* purpose - prompts with string
* - inputs vector
*************************************************************************/
void input(const char s[], double vec[])
{
// prompt
cout << "Enter the components for " << s << endl;
// read
for (int i =0; i < 3; i++)
cin >> vec[i];
}
( attaching an image of the error of this code)
Read 134 lines J [rsaleem csc 61$ g++ mp6. cpp o Imp6 em6298 mpo 6. cpp: In function avoid output (const char const double*) mp6.cpp 115: error: cannot convert aboola to astd: :ios base :fmtflagsa for argum ent a1a to a st d Setiosflags std setiosflags (std ios base finntflags) [rsaleem ecsc 61$ em6298Explanation / Answer
The error occured due to the operator "||" which you used in setiosflags(). It should be "|" operator. I have modified it and the code is working fine. The below is the output and your code. I have just modified the error where it occured. Your code is working fine.
Output:
Enter the components for v
1 2 3
Enter the components for w
1 2 3
v = 1.00 2.00 3.00
w = 1.00 2.00 3.00
unit v = 0.27 0.53 0.80
unit w = 0.27 0.53 0.80
v + w = 2.00 4.00 6.00
v - w = 0.00 0.00 0.00
v x w = 0.00 0.00 0.00
theta = 0.00
Code:
/************************************************************************
* Name: CSC 171
* Date: Today's date MP 6
************************************************************************
* Statement: Produce vector sum, difference, unit vectors, cross product
* and the angle between to R^3 vectors
* Specifications:
* Input - v and w, two vectors in R^3
* Output - v+w, v-w, vxw, unitv, unitw, theta between v and w
*************************************************************************/
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
//function declarations
void output(const char [], const double []);
void input(const char*, double[]);
double dot(const double[], const double[]);
int main()
{
// vector declarations
double v[3], w[3], vsum[3], vdiff[3], vcross[3], uv[3], uw[3];
// scalar declarations
double theta, nv, nw;
// 1) prompt and read vectors
input("v", v);
input("w", w);
// 2) determine mangnitude of vectors
nv = sqrt(dot(v, v));
nw = sqrt(dot(w, w));
// 3) loop over dimension of the space
for (int i = 0; i < 3; i++)
{
// 4) vector sum
vsum[i] = v[i] + w[i];
// 5) vector difference
vdiff[i] = v[i] - w[i];
// 6) unit vector v
uv[i] = v[i] / nv;
// 7) unit vector w
uw[i] = w[i] / nw;
}
// 8) vector cross product
vcross[0] = v[1]*w[2]-v[2]*w[1];
vcross[1] = v[2]*w[0]-v[0]*w[2];
vcross[2] = v[0]*w[1]-v[1]*w[0];
// 9) angle theta
theta = acos(dot(v,w)/(nv*nw));
//10) display vectors
output("v" , v);
//PLACE CODE HERE TO OUTPUT VECTOR w
output("w", w);
//PLACE CODE HERE TO OUTPUT unit VECTOR uv
output("unit v", uv);
//PLACE CODE HERE TO OUTPUT unit VECTOR uw
output("unit w", uw);
//PLACE CODE HERE TO OUTPUT VECTOR SUM v + w
output("v + w", vsum);
//PLACE CODE HERE TO OUTPUT VECTOR DIFFERENCE v â w
output("v - w", vdiff);
//PLACE CODE HERE TO OUTPUT VECTOR CROSS PRODUCT v x w
output("v x w", vcross);
//11) display scalar theta
cout << "theta = " << theta << endl;
}
/* Function dot
*
* receives - two R^3 vector reference parameters
* returns - dot product
*************************************************************************/
// Define function dot below
double dot(const double x[], const double y[])
{ double d;
d = 0.0;
for(int i=0; i<3; i++)
d = d + x[i]*y[i];
return d;
}
/* function output
*
* receives - string description value parameter
* - R^3 vector value parameter
* purpose - displays description and formatted vector
*************************************************************************/
void output(const char s[], const double vec[])
{
// display vector and description
cout << s << " = ";
for (int i = 0; i < 3; i++)
cout << setiosflags(ios::fixed | ios::showpoint) << setw(8)
<< setprecision(2) << vec[i];
cout << endl;
}
/* Function input
*
* receives - string description value parameter
* - R^3 vector reference parameter
* purpose - prompts with string
* - inputs vector
*************************************************************************/
void input(const char* s, double vec[])
{
// prompt
cout<<"Enter the components for "<<s<< endl;
// read
for (int i =0; i < 3; i++)
cin>>vec[i];
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.