> 文章列表 > C++ primer plus(第六版)编程练习答案 第9章 内存空间和名称空间

C++ primer plus(第六版)编程练习答案 第9章 内存空间和名称空间

C++ primer plus(第六版)编程练习答案 第9章 内存空间和名称空间

一、程序清单

coordin.h

// coordin.h -- structure templates and function prototypes
// structure templates
#ifndef COORDIN_H_
#define COORDIN_H_struct polar
{double distance;    // distance from origindouble angle;        // direction from origin
};
struct rect
{double x;        // horizontal distance from origindouble y;        // vertical distance from origin
};// prototypes
polar rect_to_polar(rect xypos);
void show_polar(polar dapos);#endif

file1.cpp 

// 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