努力超越,追求卓越:如何在VisualC++6.0中编译链接多文件程序?

来源:百度文库 编辑:高校问答 时间:2024/05/01 00:58:36
各位老大,这里有一个直角坐标转换极坐标的程序,由两个源程序和一个头文件构成,程序如下:
// coodin.h -- structure templates and function prototypes
#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

//file1.cpp -- example of a three-file program
#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)
{
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"

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";
}
请问怎样在VisualC++6.0中创建,单独编译再链接执行程序呢?多谢啦!

创建一个工程,在把这些文件都引入到工程中