big c++ 读书笔记

第4章 基本控制流

  零警告编译

  int pennies = static_cast<int>(100 * (amount_due - amount_paid));

 输入确定

 

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
 double area;
 cout<< "Please enter the area of a square:";
 cin>>area;


 if(cin.fail())
 {
  cout<<"error:bad input\n";
  return 1;
 }

 if( area < 0)
 {
  cout<<"error : negaive area\n";
  return 1;
 }
}

 函数注释风格

  /**

   计算

  @param  x

  @param y

  @return

 **/

 

 

#include<iostream>
#include<string>
#include<cmath>
using namespace std;

/**
 测试两个浮点数是否相近
 @param x
 @param y
 @return true 若近识相等则为真
 **/

bool approx_equal(double x,double y)
{
 const double EPSION = 1E-14;
 if(x==0) return fabs(y) <= EPSION;
 if(y==0) return fabs(x) <= EPSION;
 return fabs(x-y) / max(fabs(x),fabs(y)) <= EPSION;
}
int main()
{
  double x;
  cout<<"Enter a number;";
  cin >>x;

  double y;
  cout<<"Enter another number;";
  cin>>y;

  if(approx_equal(x,y))
   cout<<"the numbers are approximately equal.\n";
  else
   cout<<" the numbers are different.\n";
  return 0;
}

 

 第九章

 

  1. C++中 实现数据项序列有更好的办法: 向量结构。

  2.vector<double> salaries;

  salaries[0] = 32000;

 若定义向量时不带长度参数,它将是空的并不能保持元素。

  3.

 

 

 

转载于:https://www.cnblogs.com/alon/archive/2010/01/23/1654535.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值