I am writing a c++, I got every thing. But this program giving me error \"Initia
ID: 3782105 • Letter: I
Question
I am writing a c++, I got every thing. But this program giving me error "Initialzation of point is skipped by case lable". Can you help me to creat a menu.
Pease include sample output..
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
# define M_PI 3.14159 //this # define the pie values
using namespace std;
//creating class for three desmial points
class TDpoint
{
public:
//delacring the constructor funnctions
double new_x, new_y, new_z, thata;
TDpoint(double x, double y, double z);
//delcaring the variables for the member functions for x,y and z
double Input_x() const { return x; }
double InPut_y() const { return y; }
double Input_z() const { return z; }
//delacring variabke for shifiting the point and rotating the value
void shiftPoint(double delta_x, double delta_y, double delta_z);
void rotate_x(double angle);
void rotate_y(double angle);
void rotate_z(double angle);
private:
//in private delcaring the value for x,y and z
double x, y, z;
};
TDpoint::TDpoint(double x, double y, double z)
{
//setting the value for equal to other same value
this->x = x;
this->y = y;
this->z = z;
}
void TDpoint::shiftPoint(double delta_x, double delta_y, double delta_z)
{
x = x + delta_x;
y = y + delta_y;
z = z + delta_z;
}
//this functions will rotate for x
void TDpoint::rotate_x(double angle)
{
//calculation
thata = (angle*M_PI) / 180;
new_x = x;
new_y = y*cos(thata) - z*sin(thata);
new_z = y*sin(thata) + z*cos(thata);
//setting value for the x eqal to newer value
x = new_x;
y = new_y;
z = new_z;
}
void menu()
{
//displaying the menu to user
cout << "Press 1 to enter the corrdinate." << endl;
cout << "Press 2 to display the orginal corrdinate points." << endl;
cout << "Press 3 to enter the degrees to roate the a-axis." << endl;
cout << "Press 4 to display the after rotation corrdinate points." << endl;
cout << "Press 3 to enter the new points." << endl;
cout << "Press 4 to exit."<<endl;
}
//this functions will rotate for y
void TDpoint::rotate_y(double angle)
{
//calculation
thata = (angle*M_PI) / 180;
new_x = x*cos(thata) + z*sin(thata);
new_y = y;
new_z = y*sin(thata) - z*cos(thata);
//setting value for the x eqal to newer value
x = new_x;
y = new_y;
z = new_z;
}
//this functions will rotate for z
void TDpoint::rotate_z(double angle)
{
//calculation
thata = (angle*M_PI) / 180;
new_x = x*cos(thata) + z*sin(thata);
new_y = y*cos(thata) - z*sin(thata);
new_z = z;
//setting value for the x eqal to newer value
x = new_x;
y = new_y;
z = new_z;
}
int main()
{
double x, y, z, degree, Shiftpoints;
char choice, axis;
bool again = false;
//program desprictions
cout << "This program will keep track of the postions of a point in three-dimensional space." << endl;
while (!again)
{
menu();
cout << "Choose an options from menu.";
cin >> choice;
switch (choice)
{
case 0:
{
//asking user to enter the three corrdinate points
cout << "Please enter the three points." << endl;
cout << "x = ";
cin >> x;
cout << "y = ";
cin >> y;
cout << "z=";
cin >> z;
TDpoint Points(x, y, z);
break;
case 1:
cout << showpoint << fixed << setprecision(2);
//displaying the three points
cout << "Original corrdinate poitns are: " << endl;
cout << "x =" << Points.Input_x() << endl;
cout << "y= " << Points.InPut_y() << endl;
cout << "z = " << Points.Input_z() << endl;
break;
case 2:
//asking user how many degree they x-axis
cout << "Please enter a number for x-axis: ";
cin >> degree;
Points.rotate_x(degree);
cout << endl;
break;
case 3:
//this will display the rotaions for a-axis
cout << "After a " << degree << " degree rataion around the a-axis" << endl;
cout << "New coordinate points are: ";
cout << endl;
cout << "x =" << Points.Input_x() << endl;
cout << "y = " << Points.InPut_y() << endl;
cout << "z = " << Points.Input_z() << endl;
break;
case 4:
//need help with shift numbers
//is that going to work on work
cout << "Enter the point that you would like to shift." << endl;
cout << "x = ";
cin >> x;
cout << "y = ";
cin >> y;
cout << "z = ";
cin >> z;
Points.shiftPoint(x, y, z);
break;
case 5:
cout << "x =" << Points.Input_x() << endl;
cout << "y= " << Points.InPut_y() << endl;
cout << "z = " << Points.Input_z() << endl;
default:
break;
}
}
system("pause");
return 0;
}
}
Explanation / Answer
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#define M_PI 3.14159
using namespace std;
//creating class for three desmial points
class TDpoint
{
public:
//delacring the constructor funnctions
double new_x, new_y, new_z, thata;
TDpoint(double x, double y, double z);
//delcaring the variables for the member functions for x,y and z
double Input_x() const { return x; }
double InPut_y() const { return y; }
double Input_z() const { return z; }
//delacring variabke for shifiting the point and rotating the value
void shiftPoint(double delta_x, double delta_y, double delta_z);
void rotate_x(double angle);
void rotate_y(double angle);
void rotate_z(double angle);
private:
//in private delcaring the value for x,y and z
double x, y, z;
};
TDpoint::TDpoint(double x, double y, double z)
{
//setting the value for equal to other same value
this->x = x;
this->y = y;
this->z = z;
}
void TDpoint::shiftPoint(double delta_x, double delta_y, double delta_z)
{
x = x + delta_x;
y = y + delta_y;
z = z + delta_z;
}
//this functions will rotate for x
void TDpoint::rotate_x(double angle)
{
//calculation
thata = (angle*M_PI) / 180;
new_x = x;
new_y = y*cos(thata) - z*sin(thata);
new_z = y*sin(thata) + z*cos(thata);
//setting value for the x eqal to newer value
x = new_x;
y = new_y;
z = new_z;
}
void menu()
{
//displaying the menu to user
cout << "Press 1 to enter the corrdinate." << endl;
cout << "Press 2 to display the orginal corrdinate points." << endl;
cout << "Press 3 to enter the degrees to roate the a-axis." << endl;
cout << "Press 4 to display the after rotation corrdinate points." << endl;
cout << "Press 3 to enter the new points." << endl;
cout << "Press 4 to exit."<<endl;
}
//this functions will rotate for y
void TDpoint::rotate_y(double angle)
{
//calculation
thata = (angle*M_PI) / 180;
new_x = x*cos(thata) + z*sin(thata);
new_y = y;
new_z = y*sin(thata) - z*cos(thata);
//setting value for the x eqal to newer value
x = new_x;
y = new_y;
z = new_z;
}
//this functions will rotate for z
void TDpoint::rotate_z(double angle)
{
//calculation
thata = (angle*M_PI) / 180;
new_x = x*cos(thata) + z*sin(thata);
new_y = y*cos(thata) - z*sin(thata);
new_z = z;
//setting value for the x eqal to newer value
x = new_x;
y = new_y;
z = new_z;
}
int main()
{
double x, y, z, degree, Shiftpoints;
char axis;
int choice;
bool again = false;
TDpoint *ptr;
//program desprictions
cout << "This program will keep track of the postions of a point in three-dimensional space." << endl;
while (!again)
{
menu();
cout << "Choose an options from menu.";
cin >> choice;
switch (choice)
{
case 0:
{//asking user to enter the three corrdinate points
cout << "Please enter the three points." << endl;
cout << "x = ";
cin >> x;
cout << "y = ";
cin >> y;
cout << "z=";
cin >> z;
TDpoint Points(x,y,z);
ptr=&Points;
break;
}
case 1:
cout << showpoint << fixed << setprecision(2);
//displaying the three points
cout << "Original corrdinate poitns are: " << endl;
cout << "x =" << ptr->Input_x() << endl;
cout << "y= " << ptr->InPut_y() << endl;
cout << "z = " << ptr->Input_z() << endl;
break;
case 2:
//asking user how many degree they x-axis
cout << "Please enter a number for x-axis: ";
cin >> degree;
ptr->rotate_x(degree);
cout << endl;
break;
case 3:
//this will display the rotaions for a-axis
cout << "After a " << degree << " degree rataion around the a-axis" << endl;
cout << "New coordinate points are: ";
cout << endl;
cout << "x =" << ptr->Input_x() << endl;
cout << "y = " << ptr->InPut_y() << endl;
cout << "z = " << ptr->Input_z() << endl;
break;
case 4:
//need help with shift numbers
//is that going to work on work
cout << "Enter the point that you would like to shift." << endl;
cout << "x = ";
cin >> x;
cout << "y = ";
cin >> y;
cout << "z = ";
cin >> z;
ptr->shiftPoint(x, y, z);
break;
case 5:
cout << "x =" << ptr->Input_x() << endl;
cout << "y= " << ptr->InPut_y() << endl;
cout << "z = " << ptr->Input_z() << endl;
default:
break;
}
return 0;
}
}
=========================================================
Now it is working without any error
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.