《C++ Primer Plus》3.7編程練習

来源:互联网 发布:龙芯支持linux 编辑:程序博客网 时间:2024/06/01 17:18

題目

例一

这里写图片描述

int_tall.cpp–英呎英吋轉換,下劃線指示

//int_tall.cpp--英呎英吋轉換,下劃線指示//作者:黃子涵//日期:2016.10.25#include<iostream>using namespace std;int main(){    const Ft_in=12;    int in;    cout<<"請以英吋為單位輸入你的身高:__\b\b";    cin>>in;    cout<<"你的身高:"<<in/Ft_in<<"英呎"<<in%Ft_in<<"英吋"<<endl;;    return 0;}

这里写图片描述

例二

这里写图片描述

BMI.cpp–體重指數

//BMI.cpp--體重指數//作者:黃子涵//日期:2016.10.25#include<iostream>using namespace std;int main(){    const double in_m=0.0254;    const double kg_b=2.2;    const int ft_in=12;    int ft,in;    double a,b,m,kg;    cout<<"請以幾英呎幾英吋輸入你的身高:"<<endl;    cout<<"先輸入英呎:"<<endl;    cin>>ft;    cout<<"再輸入英吋:"<<endl;    cin>>in;    cout<<"請以磅輸入你的體重:"<<endl;    cin>>b;    kg=b/kg_b;    m=(in+ft*ft_in)*in_m;    a=kg/(m*m);    cout<<"你的BMI是:"<<a<<endl;    return 0;}

这里写图片描述

例三

这里写图片描述

d_m_s.cpp–度分秒

//d_m_s.cpp--度分秒//作者:黃子涵//日期:2016.10.25#include<iostream>using namespace std;int main(){    const int d_m=60;    const int m_s=60;    double d,m,s,a;    cout<<"請以度秒分輸入一個緯度:"<<endl;    cout<<"先輸入度:";    cin>>d;    cout<<"再輸入分:";    cin>>m;    cout<<"最後輸入秒:";    cin>>s;    a=d+(m/d_m)+(s/m_s/d_m);    cout<<d<<"度"<<m<<"分"<<s<<"秒"<<"="<<a<<"度"<<endl;    return 0;}

例四

这里写图片描述

d_h_m_s.cpp–天小時分秒

//d_h_m_s.cpp--天小時分秒//作者:黃子涵//日期:2016.10.25#include<iostream>using namespace std;int main(){    const int d_h=24;    const int h_m=60;    const int m_s=60;    long s,sec;    int d,h,m,a;    cout<<"請秒數:"<<endl;    cin>>s;    d=s/m_s/h_m/d_h;    sec=s-d*d_h*h_m*m_s;    h=sec/m_s/h_m;    sec=s-d*d_h*h_m*m_s-h*h_m*m_s;    m=sec/m_s;    a=s-d*d_h*h_m*m_s-h*h_m*m_s-m*m_s;    cout<<s<<"秒="<<d<<"天"        <<h<<"小時"<<m<<"分"<<a<<"秒"<<endl;    return 0;}

这里写图片描述

例五

这里写图片描述

population.cpp–show the percentage of US’populatian

//population.cpp--show the percentage of US'populatian//author:Huang Zihan//date:2016.10.25#include<iostream>using namespace std;int main(){    long long world,us;    double a;    cout<<"Enter the world's populatian:";    cin>>world;    cout<<"Enter the populatian of the US:";    cin>>us;    a=(double)us/(double)world*100.0;    cout<<"The populatian of the US is "<<a;    cout<<"% of the world's populatian"<<endl;    return 0;}

这里写图片描述

例六

这里写图片描述

#

0 0
原创粉丝点击