///头文件中常包含的内容:
///函数原型
///使用#define或const定义的符号常量
///结构声明
///类声明
///模板声明
///内联函数
///不要将函数定义或变量声明放到头文件中,可能带来麻烦
///例如:若在头文件中包含一个函数定义,然后在其它两个文件
///(属于同一程序)中包含该头文件,则同一个程序中将包含同一个
///函数的两个定义,除非函数是内联的,否则将出错。
///*********
///在IDE中,不要将头文件加入到项目列表中,也不要在源代码文件
///中使用#include来包含其他源代码文件。
/*#include <iostream>
using namespace std;
int main()
{
return 0;
}
*/
/// coordin.h -- structure templates and function-prototypes
///structure-templates
#ifndef COORDIN_H_
#define COORDIN_H_
struct polar
{
double distance;
double angle;
};
struct rect
{
double x;
double y;
};
///prototypes 原型:
polar rect_to_polar(rect xypos);
void show_polar(polar dapos);
#endif // COORDIN_H_
/*
Enter the x and y values: 120 80
distance = 144.222, angle = 33.6901 degrees
Next two numbers (q to quit): 120 50
distance = 130, angle = 22.6199 degrees
Next two numbers (q to quit): q
Bye!
Process returned 0 (0x0) execution time : 24.975 s
Press any key to continue.
*/
///file1.cpp -- example of a three-file program
#include<iostream>
#include"coordin.h" ///structure templates, function prototypes
using namespace std;
int main()
{
rect rplace;
polar pplace;
cout << "Enter the x and y values: ";
while(cin >> rplace.x >> rplace.y) /// slick use of cin
{
pplace = rect_to_polar(rplace);
show_polar(pplace);
cout << "Next two numbers (q to quit): ";
}
cout << "Bye!\n";
return 0;
}