c++ primer plus 第三章 课后题答案

#include<iostream>
using namespace std;

int main()
{
    const int unit=12;
    int shen_gao;
    cout <<"Please enter your leight in inches:____\b\b\b";
    cin >> shen_gao;
    cout << "It is contains: " << shen_gao / unit << " feet" << ", " << shen_gao % unit << " inches.";
    cin.get();
    cin.get();

    return 0;
}

#include<iostream>
using namespace std;

const int F_1 = 12;
const double F_2 = 0.0254;
const double F_3 = 2.2;

int main()
{
    int feet;
    int inch;
    double pound;
    double BMI;

    cout << "What‘s your heights?" << endl;
    cout << "Please enter your heights in feet: ";
    cin >> feet;
    cout << "Please enter your heights in inch: ";
    cin >> inch;
    cout << endl << "What‘s your pound?" << endl << "Please enter your pound: ";
    cin >> pound;
    BMI = (pound/F_3)/((inch+feet* F_1)*F_2);
    cout << endl << "Your BMI is " << BMI*BMI << ".";

    cin.get();
    cin.get();
    return 0;
}

#include<iostream>
using namespace std;

const int Du_fen = 60;
const int Fen_miao = 60;

int main()
{
    int degrees;
    int minutes;
    int seconds;

    cout << "Enter a latitude in degrees, minutes, seconds:\n" << "First, enter the degrees: ";
    cin >> degrees;
    cout << "Next, enter the minutes of arc: ";
    cin >> minutes;
    cout << "Finally, enter the seconds of arc: ";
    cin >> seconds;
    cout << degrees << " degrees, " << minutes << " minutes, " << seconds << " seconds = "
        << degrees + double(minutes) / Du_fen + double(seconds) / Fen_miao / Du_fen << " degrees";

    cin.get();
    cin.get();
    return 0;
}

#include<iostream>
using namespace std;

const int day_hour = 24;
const int hour_min = 60;
const int min_sec = 60;

int main()
{
    int day;
    int hour;
    int min;
    int sec;
    long second;
    cout << "Enter the number of seconds: ";
    cin >> second;

    day = second / min_sec / hour_min / day_hour;
    hour = second / min_sec / hour_min % day_hour;
    min = second / min_sec % hour_min;
    sec = second % min_sec;
    cout << second << " seconds = " << day << " days, " << hour << " hours, " << min << " minutes, " << sec << " seconds.";

    cin.get();
    cin.get();
    return 0;

}

#include<iostream>
using namespace std;

int main()
{
    long long peo_of_wor;
    long long peo_of_con;

    cout << "Enter the world‘s population: ";
    cin >> peo_of_wor;
    cout << "Enter the population of the US:";
    cin >> peo_of_con;
    cout << "The population of the US is " << (double(peo_of_con) / peo_of_wor * 100) << "% of the world population.";

    cin.get();
    cin.get();
    return 0;
}

#include<iostream>
using namespace std;

int main()
{
    double miles, gallons, kilometers, liter;
    int flage;

    cout << "You have two forms of fuel consumption: " << endl
         << "1- the mile of per gallons" << endl
         << "2- the liter of one hundred kilometer" << endl
         << "Plesase chioce(enter 1 or 2): ";
    cin >> flage;
    if (flage == 1)
    {
        cout << "Please enter the distance(mile): ";
        cin >> miles;
        cout << "Please enter the gasoline amount(gallon): ";
        cin >> gallons;
        cout << "Wasting a gallon gasoline run " << miles / gallons << " miles." << endl;
    }
    else {
        cout << "Please enter the distance(kilometer):";
        cin >> kilometers;
        cout << "Please enter the gasoline amount(liter):";
        cin >> liter;
        cout << "Wasting gasoline per hundred kilometers is " << liter / kilometers * 100 << " liters." << endl;
    }
    cin.get();
    cin.get();
    return 0;
}

#include<iostream>
using namespace std;
const float One_H_Kilometer_mile = 62.14;
const float Gallon_liter = 3.875;

int main()
{
    float european_style;
    float america_style;
    cout << "Please enter European style fuel consumption: ";
    cin >> european_style;
    america_style = One_H_Kilometer_mile * Gallon_liter / european_style;
    cout << european_style << "/100 km = " << america_style << " mpg";
    cin.get();
    cin.get();
    return 0;
}

原文地址:https://www.cnblogs.com/CJT-blog/p/10230346.html

时间: 2024-11-08 09:02:14

c++ primer plus 第三章 课后题答案的相关文章

c++ primer plus 第四章 课后题答案

#include<iostream> #include<string> using namespace std; int main() { string first_name; string last_name; char grade; int age; cout << "What is your first name? "; getline(cin,first_name); cout << endl << "Wha

C++ Primer 第五版 部分课后题答案

当时刚学C++的时候买了这本书,一开始前面看的一知半解,索性就先缓缓,等学完学校的C++课程(中途自己也写了不少c++的代码),一段时间之后又拿起这本书去看,感觉还是挺有滋味的,这本书对我印象中的C++做了很大的扩展,个人认为这本书不太适合刚学C++就去看,而是写了一定的代码,对C++有一个大体的了解之后再去看会很有味道.在看书的过程中自己也写了上面的课后练习题,现在整理一下,也跟大家分享一下,下面是9~12 15~16章的课后题编程题的答案 (第八章之前的都没保存/(ㄒoㄒ)/~~): 当时保

服务计算与服务生态系统 第三章测验题答案

1. 服务系统中的三要素包括:服务提供者.服务消费者和服务注册(Service Registry).其中,服务注册通过支持服务的发布和查找,实现服务提供者和服务消费者之间的松耦合,从而实现服务系统灵活.可动态配置的特点. × 2. 由是否拥有中心协调者作为判断,服务组合(Composition)的方法可以分为编排(Orchestration)和编导(Choreograph).从能力上来说,它们各有不同,在实际使用时需要根据业务场景进行选择. × 3. 对应服务生态系统,SOA-RA(SOA参考架

python核心编程第4章课后题答案(第二版75页)

4-1Python objects All Python objects have three attributes:type,ID,and value. All are readonly with a possible expection of the value(which can be changed only if the object is mutable). 4-5str()and repr() repr() is a built-in function while str() wa

python核心编程第2章课后题答案(第二版36页)

2-5 Loops and Numbers a) i = 0    while i <11:     print i    i += 1 b) for i in range(0,11): print i 2-6 Conditionals n =int( raw_input('enter a number:')) if n < 0: print 'negative' elif n > 0: print 'positive' else: print 'zero' 2-7 Loops and

数据库原理 西安电子科技大学(第三版) 付婷婷 第三章 课后习题答案

CREATE TABLE student_t( sno Char(7) PRIMARY KEY,--学号 sname Varchar(20) NOT NULL,--姓名 ssex CHAR(2) NOT NULL, --性别 sage Smallint, --年龄 CLON CHAR(5) --学生所在班级的编号 ); CREATE TABLE course_t( cno CHAR(1) PRIMARY KEY, --课程编号 cname Varchar(20) NOT NULL, --课程名称

C++ primer (第五版)课后题答案(八)

8.10 #include <sstream> #include <fstream> #include <iostream> #include <string> #include <vector> using namespace std; void main() { vector <string> ch; string word, line; ifstream input("test.txt"); if (!inp

python核心编程第5章课后题答案

5-8Geometry import math def sqcube(): s = float(raw_input('enter length of one side: ')) print 'the area is:', s ** 2., '(units squared)' print 'the volume is:', s ** 3., '(cubic units)'def cirsph(): r = float(raw_input('enter length of radius: ')) p

C++ Primer 笔记 第三章

C++ Primer 第三章 标准库类型 3.1using声明 例: using namespace atd; using std::cin; 3.2string类型 初始化方式 string s1 默认构造函数,s1为空串 string s2(s1) 将s2初始化为s1的一个副本 string s3(“value”) 将s3初始化为一个字符串的副本 string s4(n, 'c') 将s4初始化为字符'c'的n个副本 getline读取整行文本 getline接受两个参数:一个是输入流对象和