单独编译

///头文件中常包含的内容:
///函数原型
///使用#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;
}

///file2.cpp -- contains functions called in file1.cpp
#include<iostream>
#include<cmath>
#include"coordin.h"

///convert rectangular to polar coordinates
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; /// return a polar structure
}

///show polar coordinates, converting angle to degrees
void show_polar (polar dapos) /// 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";
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值