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 origin
	double angle;        // direction from origin
};
struct rect
{
	double x;        // horizontal distance from origin
	double 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

猜你喜欢

转载自blog.csdn.net/qq_43445867/article/details/129781448
今日推荐