0

これまでのところ、これは私の C++ コードです。

プログラムは、ユーザーにグループ名を入力するように求めます。名前が c4 の場合、プログラムは x 座標と y 座標、形状内の円の半径、および線に沿った各ポイント間の間隔を要求します。次に、プログラムは形状の点と角度を計算します。形状は、22.5 度、45 度、および 67.5 度の円の端から 3 本の線が引かれている円である必要があります。

/ computinggroup.cpp : Defines the entry point for the console application.
        //

#include "stdafx.h"
#include <iostream> //necessary for cout and endl
#include <cmath> //necessary for mathematic calculations
#include <string> //necessary for declaration of letters
#include <iomanip>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//group project
//Group c4
//date: 22/03/2013

{
string c; //declaration of letter
int d = 0; //inisialise group name elements
int i, b;
double pi = 3.141592654; //define pi for trig calculations
double r, a = 0;
double x, x1 = 0;
double y, y1 = 0;
double xa, xb, ya, yb = 0;
double increment, spacing, numofpoints;
double AngleB;
double AngleV;
double AngleTheta1;
double AngleTheta2;

/****************************************************************************
* SECTION 1 - Group name is entered by user, the programme continues if it is
* the correct name, if not a message displays and the programme stops
*****************************************************************************/

cout << "Enter letter from group name: ";
cin >> c;
cout << "Enter number from group name: ";
cin >> d;
if (c == "C", d == 4)
{ 
cout << "Group " << c << d;
cout << endl;
}
else
{
cout << "Incorrect group name entered, the programme cannot continue. Press any key to exit";
cin >> d;
return 0;
}

/****************************************************************************
* SECTION 2 - User enters values for centre point of the circle 
* and radius, the programme creates x and y coordinate points for 360 points
* around a circle
*****************************************************************************/

cout << "Enter x coordinate for the centre of the circle: ";
cin >> x1;
cout << "Enter y coordinate for the centre of the circle: ";
cin >> y1;
cout << "Enter radius of the circle: ";
cin >> r;
cout << "Enter spacing required between each point along the lines: ";
cin >> spacing;
numofpoints = (2 * pi * r)/spacing;
increment = 360/numofpoints;
for (i = 0; i < 360 ; i+=increment) //loop the calculation for values of x for i = 0 to 360 in intervals of 'increment'
{
x = x1 + (r * cos((i * pi)/180));
cout << "(" << x << ","; 
y = y1 + (r * sin((i * pi)/180));
cout << y << ")";
cout << endl;
AngleB = acos(x/pow((pow(x, 2))+(pow(y, 2)), 0.5))*(180/pi);
cout<<"\nAngle 'B' = "<<AngleB<<" Degrees"<<endl;
AngleV = acos(((pow(x, 2))+(pow(y, 2))+(10000)-(4225))/(200*(pow(((pow(x, 2))+(pow(y, 2))), 0.5))))* (180/pi);
cout<<"Angle 'V' = "<<AngleV<<" Degrees"<<endl;
AngleTheta1 = AngleB - AngleV;
cout<<"Theta 1 = "<<AngleTheta1<<" Degrees"<<endl;
AngleTheta2 =(asin(pow(((sin(AngleV*pi/180))*(pow(((pow(x, 2))+(pow(y, 2))), 0.5))/65), 0.5)))*(180/pi);
cout<<"Theta 2 = "<<AngleTheta2<<" Degrees"<<endl;
}
/****************************************************************************
* SECTION 3 - start and end coordinates for each of the 3 lines 
* The naming is as follows: example, 'xa'; 'x' means the x coordinate, 
* 'a' means start point as oppossed to 'b' for end point
*****************************************************************************/
cout << endl;
cout << "Coordinates of three lines: ";
cout << endl;
//the first line is at 22.5 deg, trigonometry is used to create the function
{
double a = 22.5;
xa = x1 + (r * cos((a * pi)/180));
ya = y1 + (r * sin((a * pi)/180));
AngleB = acos(xa/pow((pow(xa, 2))+(pow(ya, 2)), 0.5))*(180/pi);
cout<<"\nAngle 'B' = "<<AngleB<<" Degrees"<<endl;
AngleV = acos(((pow(xa, 2))+(pow(ya, 2))+(10000)-(4225))/(200*(pow(((pow(xa, 2))+(pow(ya, 2))), 0.5))))* (180/pi);
cout<<"Angle 'V' = "<<AngleV<<" Degrees"<<endl;
AngleTheta1 = AngleB - AngleV;
cout<<"Theta 1 = "<<AngleTheta1<<" Degrees"<<endl;
AngleTheta2 =(xa*sin(pow(((sin(AngleV*pi/180))*(pow(((pow(xa, 2))+(pow(ya, 2))), 0.5))/65), 0.5)))*(180/pi);
cout<<"Theta 2 = "<<AngleTheta2<<" Degrees"<<endl;
xb = x1 + (2 * r + (r * cos((a * pi)/180)));
yb = y1 + (2 * r + (r * sin((a * pi)/180)));
AngleB = acos(xb/pow((pow(xb, 2))+(pow(yb, 2)), 0.5))*(180/pi);
cout<<"\nAngle 'B' = "<<AngleB<<" Degrees"<<endl;
AngleV = acos(((pow(xb, 2))+(pow(yb, 2))+(10000)-(4225))/(200*(pow(((pow(xb, 2))+(pow(yb, 2))), 0.5))))* (180/pi);
cout<<"Angle 'V' = "<<AngleV<<" Degrees"<<endl;
AngleTheta1 = AngleB - AngleV;
cout<<"Theta 1 = "<<AngleTheta1<<" Degrees"<<endl;
AngleTheta2 =(xb*sin(pow(((sin(AngleV*pi/180))*(pow(((pow(xb, 2))+(pow(yb, 2))), 0.5))/65), 0.5)))*(180/pi);
cout<<"Theta 2 = "<<AngleTheta2<<" Degrees"<<endl;
cout << "Line at " << a << " degrees = (" << xa << ", " << ya << ") to (" << xb << ", " << yb << ")";
cout << endl;
}
//the second line is at 45 deg
{
double a = 45;
xa = x1 + (r * cos((a * pi)/180));
ya = y1 + (r * sin((a * pi)/180));
AngleB = acos(xa/pow((pow(xa, 2))+(pow(ya, 2)), 0.5))*(180/pi);
cout<<"\nAngle 'B' = "<<AngleB<<" Degrees"<<endl;
AngleV = acos(((pow(xa, 2))+(pow(ya, 2))+(10000)-(4225))/(200*(pow(((pow(xa, 2))+(pow(ya, 2))), 0.5))))* (180/pi);
cout<<"Angle 'V' = "<<AngleV<<" Degrees"<<endl;
AngleTheta1 = AngleB - AngleV;
cout<<"Theta 1 = "<<AngleTheta1<<" Degrees"<<endl;
AngleTheta2 =(xa*sin(pow(((sin(AngleV*pi/180))*(pow(((pow(xa, 2))+(pow(ya, 2))), 0.5))/65), 0.5)))*(180/pi);
cout<<"Theta 2 = "<<AngleTheta2<<" Degrees"<<endl;
xb = x1 + (2 * r + (r * cos((a * pi)/180)));
yb = y1 + (2 * r + (r * sin((a * pi)/180)));
AngleB = acos(xb/pow((pow(xb, 2))+(pow(yb, 2)), 0.5))*(180/pi);
cout<<"\nAngle 'B' = "<<AngleB<<" Degrees"<<endl;
AngleV = acos(((pow(xb, 2))+(pow(yb, 2))+(10000)-(4225))/(200*(pow(((pow(xb, 2))+(pow(yb, 2))), 0.5))))* (180/pi);
cout<<"Angle 'V' = "<<AngleV<<" Degrees"<<endl;
AngleTheta1 = AngleB - AngleV;
cout<<"Theta 1 = "<<AngleTheta1<<" Degrees"<<endl;
AngleTheta2 =(xb*sin(pow(((sin(AngleV*pi/180))*(pow(((pow(xb, 2))+(pow(yb, 2))), 0.5))/65), 0.5)))*(180/pi);
cout<<"Theta 2 = "<<AngleTheta2<<" Degrees"<<endl;
cout << "Line at " << a << " degrees = (" << xa << ", " << ya << ") to (" << xb << ", " << yb << ")";
cout << endl;
}
//the third line is at 67.5 deg
{
double a = 67.5;
xa = x1 + (r * cos((a * pi)/180));
ya = y1 + (r * sin((a * pi)/180));
AngleB = acos(xa/pow((pow(xa, 2))+(pow(ya, 2)), 0.5))*(180/pi);
cout<<"\nAngle 'B' = "<<AngleB<<" Degrees"<<endl;
AngleV = acos(((pow(xa, 2))+(pow(ya, 2))+(10000)-(4225))/(200*(pow(((pow(xa, 2))+(pow(ya, 2))), 0.5))))* (180/pi);
cout<<"Angle 'V' = "<<AngleV<<" Degrees"<<endl;
AngleTheta1 = AngleB - AngleV;
cout<<"Theta 1 = "<<AngleTheta1<<" Degrees"<<endl;
AngleTheta2 =(xa*sin(pow(((sin(AngleV*pi/180))*(pow(((pow(xa, 2))+(pow(ya, 2))), 0.5))/65), 0.5)))*(180/pi);
cout<<"Theta 2 = "<<AngleTheta2<<" Degrees"<<endl;
xb = x1 + (2 * r + (r * cos((a * pi)/180)));
yb = y1 + (2 * r + (r * sin((a * pi)/180)));
AngleB = acos(xb/pow((pow(xb, 2))+(pow(yb, 2)), 0.5))*(180/pi);
cout<<"\nAngle 'B' = "<<AngleB<<" Degrees"<<endl;
AngleV = acos(((pow(xb, 2))+(pow(yb, 2))+(10000)-(4225))/(200*(pow(((pow(xb, 2))+(pow(yb, 2))), 0.5))))* (180/pi);
cout<<"Angle 'V' = "<<AngleV<<" Degrees"<<endl;
AngleTheta1 = AngleB - AngleV;
cout<<"Theta 1 = "<<AngleTheta1<<" Degrees"<<endl;
AngleTheta2 =(xb*sin(pow(((sin(AngleV*pi/180))*(pow(((pow(xb, 2))+(pow(yb, 2))), 0.5))/65), 0.5)))*(180/pi);
cout<<"Theta 2 = "<<AngleTheta2<<" Degrees"<<endl;
cout << "Line at " << a << " degrees = (" << xa << ", " << ya << ") to (" << xb << ", " << yb << ")";
cout << endl;
}
cout << "Press any key to exit ... "; //the user has the option to exit
cin >> b;
return 0;
}

return 0;
}
4

1 に答える 1

0

私は C++ をまったく理解していないので、実際にファイルを書き込む方法を説明することはできません。

ファイルを明示的に開きたくない場合は、stdout を使用できますか?

コマンドラインからプログラムを実行し、結果をファイルにパイプできます。

例えば:mymathapp.exe > result.csv

CSV 形式を理解するのは難しくありません。

すべての行は行を表し、列データはその行の区切りリストです。(コンマやタブなどを使用できます)。通常、文字列値は"Quoted"必要ですが、通常は必須ではありません (Excel やその他のアプリは一般的にかなり寛容です)。

行を stdout に出力する方法の例。

fprintf(stdout, "%d, %d, %d, %d\n", val1, val2, val3, val4);

于 2013-03-24T23:52:15.987 に答える