结构体作为函数的参数
来源:互联网 发布:32寸海信网络液晶电视 编辑:程序博客网 时间:2024/05/17 04:35
①整个结构体作为函数的参数
实例:
#include <iostream>#include <cmath>using namespace std;struct rect{ float x; float y;};struct polar{ float distance; float angle;};polar rect_to_polar(rect rec);void show_polar(polar pol);int main(){ rect rec; polar pol; cout << "Enter the x and y values: "; while(cin >> rec.x >> rec.y) { pol = rect_to_polar(rec); show_polar(pol); cout << "Next two numbers(q to quit): "; } return 0;}polar rect_to_polar(rect rec){ polar pol; pol.distance = sqrt(rec.x * rec.x + rec.y * rec.y); pol.angle = atan2(rec.y, rec.x); return pol;}void show_polar(polar pol){ cout << "diatance = " << pol.distance << ", angle = " << pol.angle << " degrees" << endl;}
②结构体的指针作为函数的参数:
实例:
#include <iostream>#include <cmath>using namespace std;struct rect{ float x; float y;};struct polar{ float distance; float angle;};void rect_to_polar(rect *p_rect, polar *p_polar);void show_polar(polar *p_polar);int main(){ rect prect; polar ppolar; cout << "Enter the x and y values: "; while(cin >> prect.x >> prect.y) { rect_to_polar(&prect, &ppolar); show_polar(&ppolar); cout << "Next two numbers(q to eqit): "; } return 0;}void rect_to_polar(rect *p_rect, polar *p_polar){ p_polar->distance = sqrt(p_rect->x * p_rect->x + p_rect->y * p_rect->y); p_polar->angle = atan2(p_rect->y, p_rect->x);}void show_polar(polar *p_polar){ cout << "distance = " << p_polar->distance << ", angle = " << p_polar->angle << endl;}
0 0
- 结构体作为函数的形式参数
- 结构体作为函数的参数
- 结构体作为函数参数
- 结构体作为函数参数
- 结构体作为函数参数
- 结构体作为函数参数
- 结构体定义与作为函数参数的结构
- 结构体、结构指针作为函数参数
- 结构体变量作为函数的参数和返回值
- 结构体变量作为函数的参数和返回值 .
- 结构体类型数据作为函数参数
- 结构体变量指针作为函数参数
- c++:结构体类型作为函数参数
- 用结构体指针作为函数参数
- 用结构体指针作为函数参数
- 结构体作为参数传入函数错误
- C++结构体类型作为函数参数
- 结构体作为函数参数-malloc操作
- 【面向对象程序设计常见面试题】什么叫智能指针?
- Oracle Golden Gate 系列十二 -- GG 数据初始化装载二 基于SCN 的初始化 说明 与 示例
- 1.创建一个自定义控件
- Oracle Golden Gate 系列十一 -- 配置 GG DDL 同步 说明 与 示例
- Android开发之监听或获取手机短信内容
- 结构体作为函数的参数
- lxc的内存、网络、磁盘的监控管理(二)
- Oracle Golden Gate 系列十 -- 配置 Data Pump process 说明 与 示例
- 算法学习三----句子单词反转
- computer organization
- 如何为Eclipse安装主题
- Oracle Golden Gate 系列九 -- GG 数据初始化装载 说明 与 示例
- 嵌入式开发之旅-----OK6410开发笔记(2)----Uboot,内核,文件系统编译
- 程序 'jps' 已包含在下列软件包中