• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

c++primer第三章编程练习答案

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

3.7.1

#include<iostream>
int main() {
    using namespace std;
    const int unit = 12;
    int height,inch,foot;
    cout << "please input your height __ inch\b\b\b\b\b\b\b";
    cin >> height;
    inch = height % unit;
    foot = height / unit;
    cin.get();
    cout << "your height is " << foot << " foot " << inch << " inch";
    cin.get();
}

3.7.2

#include<iostream>
int main() {
    using namespace std;
    cout.setf(ios_base::fixed, ios_base::floatfield);
    const double inch_to_meter = 0.0254;
    const double kg_to_lb = 2.2;
    int inch, foot, lb;
    //float height, weight;
    cout << "please input your height!\n";
    cout << "foot:_\b";
    cin >> foot;
    cout << "inch:_\b";
    cin >> inch;
    cout << "please input your weight " << "___ lb\b\b\b\b\b\b";
    cin >> lb;
    cin.get();
    cout << "your height is " << foot * 10 + inch << " inch\n";
    cout << "your height is " << (foot * 10 + inch)*inch_to_meter << "m\n";
    cout << "your weight is " << lb / 2.2 << "kg\n";
    cout << "your BMI is " << pow((lb / 2.2) / ((foot * 10 + inch)*inch_to_meter), 2);
    //cout << pow(2, 3);
    cin.get();
}

3.7.3

#include<iostream>
int main() {
    using namespace std;
    const int degree_to_minute = 60;
    const int minute_to_second = 60;
    int degree, minute, second;
    double latitude;
    cout << "Enter a latitude in degree,minutes,and seconds:\n";
    cout << "First,enter the degrees: ";
    cin >> degree;
    cout << "Next,enter the minutes of arc: ";
    cin >> minute;
    cout << "Finally,enter the seconds of arc: ";
    cin >> second;
    cin.get();
    latitude = degree + double(minute) / degree_to_minute + double(second) / degree_to_minute / minute_to_second;
    cout << degree << " degrees," << minute << " minutes," << second << " seconds = " << latitude << " degrees";
    cin.get();
}

3.7.4

#include<iostream>
int main() {
    using namespace std;
    const int days_to_hours = 24;
    const int hours_to_minutes = 60;
    const int mintutes_to_seconds = 60;
    int days, hours, minutes, seconds,init_times;
    cout << "Enter the number of seconds: ";
    cin >> init_times;
    cin.get();
    days = init_times / mintutes_to_seconds / hours_to_minutes / days_to_hours;
    hours = init_times / mintutes_to_seconds / hours_to_minutes % days_to_hours;
    minutes = init_times / mintutes_to_seconds % hours_to_minutes;
    seconds = init_times % mintutes_to_seconds;
    cout << init_times << " seconds = " << days << " days," << hours << " hours," << minutes << " minutes," << seconds << " seconds.";
    cin.get();
}

3.7.5

#include<iostream>
int main() {
    using namespace std;
    long long world_num;
    long long us_num;
    cout << "Enter the world's population: ";
    cin >> world_num;
    cout << "Enter the population of the US: ";
    cin >> us_num;
    cin.get();
    cout << "The population of the US is " << double(us_num) / double(world_num)*100 << "% of the world population";
    cin.get();
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
MCU开发之I2C通信发布时间:2022-07-14
下一篇:
C#中如何实现C++中的constreference发布时间:2022-07-14
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap