C艹函数与结构体
2024-09-16 19:35:32
传递指针
代码:
#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';
}
最新文章
- Linked List Start!
- SpringMVC 400 Bad Request 问题
- Swift实现截屏并保存相册
- Hadoop2.6.0伪分布环境搭建
- 【转】Mybatis 3.1中 Mapper XML 文件 的学习详解
- linux服务之irqbalance
- Linux 进程间通信
- sql的内连接 左外连接 右外连接 全外连接等连接查询的关系图
- html 元素添加 class
- [Angular 2] Managing State in RxJS with StartWith and Scan
- javascript 中 nodeValue 、value 、text 的区别
- 20151226--easyUI
- 蓝缘管理系统第二个版本号开源了。springMVC+springSecurity3.x+Mybaits3.x 系统
- jquery字体更改后的鼠标-影像学改变//凝视内容
- JavaScript里利用DOM获取宽高大全
- .NET产品源码保护,.NET防止反编译,c#/vb.net 防反编译
- 使用 Python &; Flask 实现 RESTful Web API
- 3分钟看完Java 8——史上最强Java 8新特性总结之第二篇 Stream API
- 【Spring】29、SpringBoot中@SpringBootApplication的使用
- xampp 搭建好本地服务器以后手机无法访问
热门文章
- Debugging Java Native Memory Leaks
- Oracle根据表生成系统流水号
- SQL Server 2008 R2:error 26 开启远程连接详解
- 服务器搭建5 Samba实现文件共享
- android 调用系统相机拍照 获取原图
- mac下增加eclipse内存
- 【转】Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file:
- LeetCode: Reverse Nodes in k-Group 解题报告
- 【Ubuntu】服务器状态命令
- spacemacs怎样配置编辑器显示行号?