CPP_Basic_Code_P3.1-PP3.7.6

CPP_Basic_Code_P3.1-PP3.7.6

//  The Notes Created by Z-Tech on 2017/2/17.
//  All Codes Boot on 《C++ Primer Plus》V6.0
//  OS:MacOS 10.12.4
//  Translater:clang/llvm8.0.0 &g++4.2.1
//  Editer:iTerm 2&Sublime text 3
//  IDE: Xcode8.2.1&Clion2017.1

//P3.1
#include 
#include 
int main()
{
    using namespace std;
    int n_int=INT_MAX;
    short n_short=SHRT_MAX;//指定最大值
    long n_long=LONG_MAX;
    long long n_llong=LLONG_MAX;
    cout<<"int is "<-32768;整形溢出跳转
    sue++;//32767+1=32768
    cout<<"Sam has "<65535,整形溢出跳转
    cout<<"Sam has "<
int main()
{
    using namespace std;
    int chest=42;//十进制
    int waist=0x42;//十六进制
    int inseam=042;//八进制
    cout<<"Monsieur cuts a striking figure!\n";//默认情况下,cout始终以十进制输出
    cout<<"chest= "<
using namespace std;
int main()
{
    int chest=42;
    int waist=42;
    int inseam=42;

    cout<<"Monsieur cuts a striking figure!"<
int main()
{
    using namespace std;
    char ch;
    cout<<"Enter a character: "<>ch;
    cout<<"Hola! ";
    cout<<"Thank you for the "<
int main()
{
    using namespace std;
    char ch='M';//如果没有''则将被视为一个未声明的变量
    int i=ch;
    cout<<"The ASCII code for "<
int main()
{
    using namespace std;
    cout<<"\aOperation \"HypeHype\" is now activated!\n";// \a为振铃符
    cout<<"Enter your agent code:________\b\b\b\b\b\b\b\b";// \b为退格符,可移动光标的位置
    long code;
    cin>>code;
    cout<<"\ayou entered "<< code <<"...\n";
    cout<<"\aCode verified! Proceed with Plan Z3!\n";
    return 0;
}

//P3.7.extra
#include 
int main()
{
    using namespace std;
    int k\u00F6rper;//变量名为Körper
    cout<<"Let them eat g\u00E2teau.\n";//gâteau
    return 0;
}

//P3.8
#include 
int main()
{
    using namespace std;
    cout.setf(ios_base::fixed,ios_base::floatfield);//强制显示小数点,不显示e表示法
    float tub=10.0/3.0;//均被初始化为3.333333
    double mint=10.0/3.0;
    const float million=1.0e6;//十的六次方

    cout<<"tub="<>hats;
    cout<<"Enter another number: ";
    cin>>heads;
    cout<<"hats = "<>lbs;
    int stone=lbs/Lbs_per_stn;//计算整的Stone
    int pounds=lbs%Lbs_per_stn;//计算余下的英镑数
    cout<
int main()
{
    using namespace std;
    cout.setf(ios_base::fixed,ios_base::floatfield);
    float tree=3;
    int guess(3.9832);//括号赋值法
    int debt=7.2E12;//每一个编译器均不同
    cout<<"Tree = "<(ch)<将ch强制类型转换为int
    return 0;
}

//PP3.7.1
#include 
int main()
{
    using namespace std;
    cout<<"Enter your height by foot:__\b\b";//两个删除符号
    int height;
    cin>>height;
    const int inchV=12;//转换因子inchV
    int inch=height/inchV;
    int foot=height%inchV;
    cout<<"So your height is "<
int main()
{
    using namespace std;
    cout<<"Please enter your height by inch and foot(Use Space between them): ";
    float inch,foot;//参考身高数据:5 inch&7.9 foot,约1.72m
    cin>>inch>>foot;//参考体重数据:120 pound,约54.5kg
    cout<<"Please enter your Weight by Pound : ";
    float pound;
    cin>>pound;
    const int hcv=12;
    const float wcv=2.2;
    float mi=(inch*hcv+foot)*0.0254;
    float kg=pound/2.2;
    float bmi=kg/(mi*mi);
    cout<<"So your height is "<
int main()
{
    using namespace std;
    cout<<"Enter a latitude in degrees,minutes,and seconds: ";
    cout<<"First,enter the degrees: ";
    float degrees;
    cin>>degrees;
    cout<<"Next,enter the minutes: ";
    float minutes;
    cin>>minutes;
    cout<<"Finally,enter the seconds: ";
    float seconds;
    cin>>seconds;
    const int sv=60;//const定义需要指明具体的常量类型
    cout<
int main()
{
    using namespace std;
    cout<<"Enter the numbers of seconds: ";
    long allseconds;
    cin>>allseconds;
    int allhours=allseconds/3600;//全部小时数
    short days=allhours/24;//除法计算天数
    short hours=allhours%24;//求模算出小时数
    long allminutes=allseconds/60;//全部分钟数
    short minutes=allminutes%(allhours*60);//求模算出分钟数
    short seconds=allseconds%60;//求模算出秒数
    cout<
int main()
{
    using namespace std;
    cout.setf(ios_base::fixed, ios_base::floatfield);
    cout<<"Enter the world's population: ";
    long double wpplt;
    cin>>wpplt;
    cout<<"Enter the population of the U.S: ";
    long double upplt;
    cin>>upplt;
    cout<<"The population of U.S is "<<(upplt/wpplt)*100<<"% of the world population.";//百分比要*100
    return 0;
}

//PP3.7.6
#include 
int main()
{
    using namespace std;
    cout<<"Enter your drive distance: ";
    double distance;
    cin>>distance;
    cout<<"Next,enter the oil by 升: ";
    float oil;
    cin>>oil;
    cout<<"100km run out of "<<(oil/distance)*100<<"升。";
    return 0;
}

你可能感兴趣的:(CPP_Basic_Code_P3.1-PP3.7.6)