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 } 这是一个 ...
随机推荐
- spring cloud 项目相关集成简介
Spring Cloud Config 配置管理工具包,让你可以把配置放到远程服务器,集中化管理集群配置,目前支持本地存储.Git以及Subversion. Spring Cloud Bus 事件.消 ...
- adb无线网络调试
1.如果已经可以用usb连接adb,那么可以通过以下命令切换到无线连接方式. adb tcpip 5555 adb connect 192.168.0.101:5555 通过下面的命令可以切 ...
- [AWS vs Azure] 云计算里AWS和Azure的探究(4)
云计算里AWS和Azure的探究(4) ——Amazon EC2 和 Windows Azure Virtual Machine 接下来我们来看看Azure VM的创建.Azure里面虚拟机的创建跟A ...
- Python fabric实践操作
前面学习了理论,下面该练练手了.两台机器:10.1.6.186.10.1.6.159.fabric部署在10.1.6.186上面. 1 执行一个简单的task任务,显示两台机器的/home/guol ...
- 【Ensemble methods】组合方法&集成方法
机器学习的算法中,讨论的最多的是某种特定的算法,比如Decision Tree,KNN等,在实际工作以及kaggle竞赛中,Ensemble methods(组合方法)的效果往往是最好的,当然需要消耗 ...
- idea 改变version control
idea 当一个moudule拥有2个VCS的时候 如何切换其应用的VSC 如拥有 SVN 和 GIT 2个版本 ,想换回SVN则删除 git目录 将 version control vcs 设 ...
- shell脚本输出带颜色字体
#!/bin/bash # #下面是字体输出颜色及终端格式控制 #字体色范围:30-37 echo -e "\033[30m 黑色字 \033[0m" echo -e " ...
- docker简易命令
docker应用 安装 sudo yum install docker 启动 docker 进程 $ sudo service docker start Docker 默认开机启动 $ sudo ch ...
- virtualbox问题收集
The VM session was closed before any attempt to power it on. 返回 代码:E_FAIL (0x80004005)组件:SessionMach ...
- Android 异步任务——AsyncTask (附使用AsyncTask下载图片Demo)
我们编程的时候经常需要处理同步任务和异步任务,在Android里面存在一个特性,就是UI线程是不安全的线程.所谓UI线程不安全也就是我们的主线程(进程启动的第一个线程)不能在线程外操作主线程的资源.因 ...