Professional Documents
Culture Documents
Three Dimension Coordinate Systems Converter Source Code
Three Dimension Coordinate Systems Converter Source Code
Three Dimension Coordinate Systems Converter Source Code
com
https://www.cprogramming.com/snippets/source-code/three-dimensional-coordinate-converter 1/3
3/1/2019 Three Dimension Coordinate Systems Converter source code - Cprogramming.com
83 friend void disp(convt&);
84 };
85 void disp(convt &conv)
86 {
87 cout << endl << conv.cr.str << endl;//display rectangular
88 cout <<"-------------------------------\n";
89 cout << conv.cr.str1[0] << conv.cr.d1 << conv.cr.str1[1] << endl;
90 cout << conv.cr.str2[0] << conv.cr.d2 << conv.cr.str2[1] << endl;
91 cout << conv.cr.str3[0] << conv.cr.d3 << conv.cr.str3[1] << endl;
92
93 cout << conv.cc.str << endl;//display cylindrical
94 cout <<"-------------------------------\n";
95 cout << conv.cc.str1[0] << conv.cc.d1 << conv.cc.str1[1] << endl;
96 cout << conv.cc.str2[0] << FAC1 * conv.cc.d2 << conv.cc.str2[1] << endl;
97 cout << conv.cc.str3[0] << conv.cc.d3 << conv.cc.str3[1] << endl;
98
99 cout << conv.cs.str << endl;//display spherical
100 cout <<"-------------------------------\n";
101 cout << conv.cs.str1[0] << conv.cs.d1 << conv.cs.str1[1] << endl;
102 cout << conv.cs.str2[0] << FAC1 * conv.cs.d2 << conv.cs.str2[1] << endl;
103 cout << conv.cs.str3[0] << FAC1 * conv.cs.d3 << conv.cs.str3[1] << endl << endl;
104 }
105 int main()
106 {
107 convt con;
108 double dx1,dx2,dx3;
109 char ch;
110
111 for(;;)
112 {
113 cout << "\nThree Dimension Coordinate Systems Converter" << endl;
114 cout << "\n\t1) Rectangular Coordinate System (x, y, z) " << endl;
115 cout << "\t2) Cylinderical Coordinate System (Rho, Phi, z)" << endl;
116 cout << "\t3) Spherical Coordinate System (R, Theta, Phi)" << endl;
117 cout << "\t4) Exit " << endl << endl;
118 cout << "Hint: The used angles are in degrees" << endl << endl;
119 cout << "Choose one option : ";
120 cin >> ch;
121
122 if(ch == '1' || ch == '2' || ch == '3' )
123 {
124 cout << "\nEnter coordinates of the chosen system:";
125 cout << "\nEnter 1st axis :";
126 cin >> dx1;
127 cout << "Enter 2nd axis :";
128 cin >> dx2;
129 cout << "Enter 3rd axis :";
130 cin >> dx3;
131 switch(ch)
132 {
133 case '1':
134 {
135 con.setVarr(dx1,dx2,dx3);
136 con.convertr_c();
137 con.convertc_s();
138 disp(con);
139 break;
140 }
141 case '2':
142 {
143 dx2 = dx2 * FAC2;
144 con.setVarc(dx1,dx2,dx3);
145 con.convertc_s();
146 con.converts_r();
147 disp(con);
148 break;
149 }
150 case '3':
151 {
152 dx2 = dx2 * FAC2;
153 dx3 = dx3 * FAC2;
154 con.setVars(dx1,dx2,dx3);
155 con.converts_r();
156 con.convertr_c();
157 disp(con);
158 break;
159 }
160 }
161 }
162 else if( ch == '4')
163 break;
164 else
165 cout << "Wrong number choosen. Try to choose right option :" << endl << endl;
166 }
167 return 0;
168 }
10 Rate it
https://www.cprogramming.com/snippets/source-code/three-dimensional-coordinate-converter 2/3
3/1/2019 Three Dimension Coordinate Systems Converter source code - Cprogramming.com
https://www.cprogramming.com/snippets/source-code/three-dimensional-coordinate-converter 3/3