您的位置:首页 > 编程语言 > C语言/C++

编写自己的C++头文件

2013-05-10 07:50 211 查看
// 9_1.cpp : 定义控制台应用程序的入口点。

//

//定义COODIN头文件

#ifndef COORDIN_H_

#define COORDIN_H_

struct polar

{

double distance;

double angle;

};

struct rect

{

double x;

double y;

};

polar rect_to_polar(rect xypos);

void show_polar(polar dapos);

#endif

9_1_2文件

#include"stdafx.h"

#include<iostream>

#include<cmath>

#include"coordin.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 Red_to_deg=57.29577951;

cout<<"distance="<<dapos.distance;

cout<<",angle="<<dapos.angle*Red_to_deg;

cout<<"degrees\n";

}

9_1文件

// 9_1.cpp : 定义控制台应用程序的入口点。

//

#include "stdafx.h"

#include<iostream>

#include"coordin.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

return 0;

}

int main()

{

rect rplace;

polar pplace;

cout<<"Enter the x and y value:";

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  头文件 C++