单独编译

自编头文件+几个文件一起编译

  • 在参考书的帮助下,成功实现第一次
    test.h
#include<iostream>
#ifndef TEST
#define TEST
struct polar{
	double distance;
	double angle;
};
struct rect{
	double x;
	double y;
};
polar rect_to_polar(rect xypos);
void show_polar(polar dapos);
#endif

file1

#include<iostream>
#include"test.h"
#include<cmath>
#include"file2.cpp" 
using namespace std;//要在主函数这里编译 
int main()
{
	rect rplace;
	polar pplace;
	cout<<"enter x and y ";
	while(cin>>rplace.x>>rplace.y)
	{
		pplace=rect_to_polar(rplace);
		show_polar(pplace);
		cout<<"next two numbers (q to quit): ";
		
	}
	cout<<"Bye!\n";
	return 0;
 } 

file2

#include<iostream>
#include<cmath>
#include"test.h"
polar rect_to_polar(rect xypos)
{
	using namespace std;
	polar answer;
	answer.distance=sqrt(xypos.x*xypos.x+xypos.y*xypos.y);
	answer.angle=atan2(xypos.y,xypos.x);
	return answer;
};
void show_polar(polar dapos)
{
	using namespace std;
	const double Rad_to_deg=57.29577951;
	cout<<"distance = "<<dapos.distance;
	cout<<", angle = "<<dapos.angle*Rad_to_deg;
	cout<<" degrees\n";
}

posted on 2020-04-09 16:26  2002ljy  阅读(107)  评论(0编辑  收藏  举报

导航

Live2D