![]() |
#2
rjsp2019-01-31 19:57
|
头文件: coordin.h

#ifndef COORDIN_H_
#define COORDIN_H_
struct polar
{
double distance; // distance 形式的起源
double angle; // 方向从起源
};
struct rect
{
double x; // 水平距离原点
double y; // 垂直距离原点
};
// 原型
polar rec_to_polar(rect xypos);
void show_polar(polar dapos);
#endif // !COORDIN_H_
C++文件1: file1.cpp

#include <iostream>
#include "coordin.h" // 结构模板,函数原型
using namespace std;
int main()
{
rect rplace;
polar pplace;
cout << "Enter the x and y values: ";
while (cin >> rplace.x >> rplace.y) // 熟练使用 cin
{
pplace = rec_to_polar(rplace);
show_polar(pplace);
cout << "Next two numbers (q to quit): ";
}
cout << "Bye!\n";
return 0;
}
C++文件2: file2.cpp

#include <iostream>
#include <cmath>
#include "coordin.h" // 结构模板,函数原型
using namespace std;
// 将直角坐标转换为 polar 坐标
polar rect_to_polar(rect xypos)
{
polar answer;
answer.distance =
sqrt(xypos.x * xypos.x + xypos.y * xypos.y);
answer.angle = atan2(xypos.y, xypos.x);
return answer; // 返回一个 polar 结构
}
// 显示 polar 坐标,将角度转换成角度
void show_polar(polar dapos)
{
const double Rad_to_deg = 57.29577951;
cout << "distance = " << dapos.distance;
cout << ", angle = " << dapos.angle * Rad_to_deg;
cout << " degrees\n";
}
编译器提示:
#include 语句中指定用 /Yc文件名源代码文件中找不到命令行选项
怎么解决呢??