传递指针

代码:

#include <iostream>
#include <cmath> struct polar{
double distance;
double angle;
}; struct rect{
double x;
double y;
}; void rect_to_polar(const rect * pxy, polar * pda);
void show_polar(const polar * pda); int main(int argc, char const *argv[]) {
using namespace std;
rect rplace;
polar pplace;
std::cout << "Enter the x and y values:";
while (cin >> rplace.x >> rplace.y)
{
rect_to_polar(&rplace, &pplace);
show_polar(&pplace);
std::cout << "Next two numbers (q to quit)" << '\n';
}
std::cout << "Done." << '\n';
return ;
} void show_polar(const polar * pda)
{
using namespace std;
const double Rad_to_deg = 57.29577951; std::cout << "distance = " << pda->distance;
std::cout << ", angle = " << pda->angle * Rad_to_deg;
std::cout << " degrees" << '\n';
} void rect_to_polar(const rect * pxy, polar * pda)
{
using namespace std;
pda->distance = sqrt(pxy->x * pxy->x + pxy->y * pxy->y);
pda->angle = atan2(pxy->y, pxy->x);
}

传递结构体

#include <iostream>
#include <cmath> struct polar{
double distance;
double angle;
}; struct rect{
double x;
double y;
}; polar rect_to_polar(rect xypos);
void show_polar(polar dapos); int main(int argc, char const *argv[]) {
using namespace std; rect rplace;
polar pplace; std::cout << "Enter the x and y values: " << '\n'; while (cin >> rplace.x >> rplace.y){
pplace = rect_to_polar(rplace);
show_polar(pplace);
std::cout << "Next two numbers (q to quit) :" << '\n';
} return ;
} 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; std::cout << "distance = " << dapos.distance << '\n';
std::cout << ", angle = " << dapos.angle * Rad_to_deg << '\n';
}

最新文章

  1. Linked List Start!
  2. SpringMVC 400 Bad Request 问题
  3. Swift实现截屏并保存相册
  4. Hadoop2.6.0伪分布环境搭建
  5. 【转】Mybatis 3.1中 Mapper XML 文件 的学习详解
  6. linux服务之irqbalance
  7. Linux 进程间通信
  8. sql的内连接 左外连接 右外连接 全外连接等连接查询的关系图
  9. html 元素添加 class
  10. [Angular 2] Managing State in RxJS with StartWith and Scan
  11. javascript 中 nodeValue 、value 、text 的区别
  12. 20151226--easyUI
  13. 蓝缘管理系统第二个版本号开源了。springMVC+springSecurity3.x+Mybaits3.x 系统
  14. jquery字体更改后的鼠标-影像学改变//凝视内容
  15. JavaScript里利用DOM获取宽高大全
  16. .NET产品源码保护,.NET防止反编译,c#/vb.net 防反编译
  17. 使用 Python &amp; Flask 实现 RESTful Web API
  18. 3分钟看完Java 8——史上最强Java 8新特性总结之第二篇 Stream API
  19. 【Spring】29、SpringBoot中@SpringBootApplication的使用
  20. xampp 搭建好本地服务器以后手机无法访问

热门文章

  1. Debugging Java Native Memory Leaks
  2. Oracle根据表生成系统流水号
  3. SQL Server 2008 R2:error 26 开启远程连接详解
  4. 服务器搭建5 Samba实现文件共享
  5. android 调用系统相机拍照 获取原图
  6. mac下增加eclipse内存
  7. 【转】Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file:
  8. LeetCode: Reverse Nodes in k-Group 解题报告
  9. 【Ubuntu】服务器状态命令
  10. spacemacs怎样配置编辑器显示行号?