Big C ++ Reading Notes

Source: Internet
Author: User

Chapter 2 Basic Control Flow

Zero warning Compilation

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

Enter OK

 

# 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;
}
}

Function annotation Style

/**

Computing

@ Param x

@ Param y

@ Return

**/

 

 

# Include <iostream>
# Include <string>
# Include <cmath>
Using namespace STD;

/**
Test whether two floating point numbers are similar.
@ Param x
@ Param y
@ Return true if near phase recognition is 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;
}

 

Chapter 9

 

1. There is a better way to achieve data item sequence in C ++: vector structure.

2. Vector <double> salaries;

Salaries [0] = 32000;

If a vector is defined without a length parameter, it will be empty and cannot retain elements.

3.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.