2021-01-15

C++学习之旅

  • 今天学完第三章

1 byte= 8 位
short为16位,long为32位,long long为64位

sizeof返回类型或变量的长度,单位为字节

cout<<hex;//改变输出格式为16进制
cout<<oct;//改变输出格式为8进制

对字符使用单引号,对字符串使用双引号

\a表示一个振铃

/*振铃*/
#include <iostream>
using namespace std;

int main()
{
	char alarm='\a';
	
	cout << alarm<<"Don't do that again!\a\n "<<endl;
	cin.get();
	return 0;
}

当两个整数进行除法的时候,得到的结果将会被保留为整数(直接丢弃小数部分);
若其中有一个或两个是浮点数,则得到的结果也为浮点数。

第三章书后习题
3-2

/*以几英尺几英寸的方式输入身高,以磅为单位输入体重,报告其BMI值*/
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	cout << "Please input your height in foot and inch" << endl;
	
	cout << "foot:_\b ";//利用\b退格符来控制光标
	int foot;
	cin >> foot;
	cout<< "inch:_\b ";
	int inch;
	cin >> inch;
	cout << "Please input your weight in pounds" << endl;
	cout << "pounds:_\b ";
	double pounds;
	cin >> pounds;
	const int foot_to_inch = 12;
	const double inch_to_meter = 0.0254;
	const double kg_to_pound = 2.2;
	int meters;
	meters = (foot_to_inch*foot + inch)*inch_to_meter;
	double kilos;
	kilos = pounds / kg_to_pound;
	double BMI;
	BMI = kilos / (meters ^ 2);
	cout << "Your BMI is: " << BMI << endl;
	cin.get();
	cin.get();
	return 0;
}

剩下的习题和3-2类似,因此不做练习~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值