C艹函数与结构体
传递指针
代码:
#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';
}
C艹函数与结构体的更多相关文章
- 【AT91SAM3S】SAM3S-EK Demo工程中,LCD驱动程序的加载(函数指针结构体)
为了调试LCD,在英倍特的板子上烧Atmel的sam3s-ek_demo_1.4_source示例代码.LCD显示正常了,却找不到LCD的驱动究竟在哪. 花了好久,追踪到了这个执行过程. 进入main ...
- struct--------构造函数对结构体初始化的影响
struct--------构造函数对结构体初始化的影响. 没有构造函数时使用如下: struct ClassBook{ int number; int age; }; int main() { ...
- 【Unity Shader】---常用帮助函数、结构体和全局变量
[Unity Shader]---常用帮助函数.结构体和全局变量 一.内置包含文件 Unity中有类似于C++的包含文件.cginc,在编写Shader时我们可以使用#include指令把这些文件包含 ...
- <algorithm>里的sort函数对结构体排序
题目描述 每天第一个到机房的人要把门打开,最后一个离开的人要把门关好.现有一堆杂乱的机房签到.签离记录,请根据记录找出当天开门和关门的人. 输入描述: 每天的记录在第一行给出记录的条目数M (M &g ...
- 获取网络接口信息——ioctl()函数与结构体struct ifreq、 struct ifconf
转载请注明出处:windeal专栏 Linux 下 可以使用ioctl()函数 以及 结构体 struct ifreq 结构体struct ifconf来获取网络接口的各种信息. ioctl 首先看 ...
- C语言笔记 08_函数指针&回调函数&字符串&结构体&位域
函数指针 函数指针是指向函数的指针变量. 通常我们说的指针变量是指向一个整型.字符型或数组等变量,而函数指针是指向函数. 函数指针可以像一般函数一样,用于调用函数.传递参数. 函数指针变量的声明: / ...
- Golang 笔记 2 函数、结构体、接口、指针
一.函数 Go中函数是一等(first-class)类型.我们可以把函数当作值来传递和使用.Go中的函数可以返回多个结果. 函数类型字面量由关键字func.由圆括号包裹声明列表.空格以及可以由圆括号 ...
- go 学习 (三):函数 & 指针 & 结构体
一.函数 函数声明 // 声明语法 func funcName (paramName paramType, ...) (returnType, returnType...) { // do somet ...
- go 函数传递结构体
我定义了一个结构体,想要在函数中改变结构体的值,记录一下,以防忘记 ep: type Matrix struct{ rowlen int columnlen int list []int } 这是一个 ...
随机推荐
- redhat7.2 安装docker
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # sed -i ' ...
- 服务器搭建5 Samba实现文件共享
Samba服务器工作原理 客户端向Samba服务器发起请求,请求访问共享目录,Samba服务器接收请求,查询smb.conf文件,查看共享目录是否存在,以及来访者的访问权限,如果来访者具有相应的权限, ...
- DPDK(mtcp)vs RDMA/ROCE
0. 缠论: http://52investing.com/ 1. 简书.DPDK: http://www.jianshu.com/p/dcb6ccc83ea52. mTCP 和 DPDK 构造百万千 ...
- 20、uwp打包失败(All app package manifests in a bundle must declare the same values under the XPath *[local-name()='Package']/*[local-name()='Dependencies'])
在给 uwp工程打商店包的时候,遇到了一个异常: Error info: error 80080204: All app package manifests in a bundle must decl ...
- 【消息】linux之消息队列
1.机制 消息队列的运行方式与命名管道非常相似. 欲与其他进程通信的进程只需要将消息发送到消息队列中,目的进程就从消息队列中读取需要的消息. 2.源码 1)发送方 //msg_send.c #in ...
- 搜索页面scroll下拉时候进行刷新,显示更多搜索值
1.封装扩展scroll.vue功能: //props传值 pullup:{ type:Boolean, default:false } _initScroll(){ if(!this.$refs.w ...
- ftell函数使用注意事项
ftell函数的原型如下: long ftell(FILE *stream); 主要功能是获取FILE指针在当前文件中的位置. 但在使用文本模式打开文件时,ftell函数返回值不一定跟FILE文件指针 ...
- Ubuntu上搭建Hadoop环境(单机模式+伪分布模式)【转】
[转自:]http://blog.csdn.net/hitwengqi/article/details/8008203 最近一直在自学Hadoop,今天花点时间搭建一个开发环境,并整理成文. 首先要了 ...
- Python3求笛卡尔积的两种方法
[本文出自天外归云的博客园] 电影异次元杀阵三部曲中密室线索反复出现笛卡尔积的运用.百度百科: 笛卡尔乘积是指在数学中,两个集合X和Y的笛卡尓积(Cartesian product),又称直积,表示为 ...
- celery 实例进阶
认识 这里有几个概念,task.worker.broker.顾名思义,task 就是老板交给你的各种任务,worker 就是你手下干活的人员. 那什么是 Broker 呢? 老板给你下发任务时,你需要 ...