C++ Primer Reading

Preface

My answer of the Program tests in this book.

Chapter one

//Num 1:
std::cout << "My name is Feishi , and my address is 127.0.0.1." << std::endl;
//Nmu 2:
long dis;
std::cout << "Please input a number:";
std::cin >> dis;
std::cout << "m:" << dis * 220 << std::endl;
//Num 3:
auto a = []() {std::cout << "Three blind mice" << std::endl; };
auto b = []() {std::cout << "See how they run" << std::endl; };
a(); a();
b(); b();
//Num 4:
//Num 5:
auto sth = []() {
    std::cout << "Please enter a Cslsius value:";
    int n; std::cin >> n;
    std::cout << n << " degress Celsius is " << n * 1.8 + 32.0 << " degress Fahrenheit." << std::endl;
};
sth();
//Num 6:
auto tra = []() {
    std::cout << "Enter the number of light years:";
    double dis; std::cin >> dis;
    std::cout << dis << " light years = " << dis * 63240 << " astronomical units." << std::endl;
};
tra();
//Num 7:
auto dis1 = [](int h, int m) {
    std::cout << "Time: " << h << ':' << m << std::endl;
};
int tema, temb;
std::cout << "Enter the number of hours:"; std::cin >> tema;
std::cout << "Enter the number of minutes:"; std::cin >> temb;
dis1(tema, temb);

Chapter two

//Num 1:
const double Divisor = 12;
std::cout << "Please enter your length_"; int length = 0;
std::cin >> length;
std::cout << "Your length:" << length << " to feet:" << length * Divisor << std::endl;

//Num 2:
double inch, feet, weig;
std::cout << "Please enter  inch and feet:" << std::endl;
std::cout << "inch:"; std::cin >> inch;
std::cout << "feet:"; std::cin >> feet;
std::cout << "weight:"; std::cin >> weig;
std::cout << "THE BMI:" << pow(weig / 2.2 / ((inch * Divisor + feet) * 0.00254), 2);

//Num 3:
double degree, min, sec;
std::cout << "Enter a latitude in degrees, minutes, and seconds:" << std::endl;
std::cout << "First, enter the degrees:"; std::cin >> degree;
std::cout << "Next, enter the minutes of arc:"; std::cin >> min;
std::cout << "Finally, enter the seconds of arc:"; std::cin >> sec;
std::cout << degree << " degrees, " << min << " minutes, " << sec << " seconds = " << degree + min / 60 + sec / 360 << " degrees" << std::endl;

//Num 4:
long d;
std::cout << "Enter the number of seconds:"; std::cin >> d;
std::cout << d << " seconds = " << d / (60 * 60 * 24); d %= (60 * 60 * 24);
std::cout << " days, " << d / (60 * 60); d %= (60 * 60);
std::cout << " hours, " << d / 60; d %= 60;
std::cout << " minutes, " << d << " seconds" << std::endl;

//Num 5:
long long w, a;
std::cout << "Enter the world's population: "; std::cin >> w;
std::cout << "Enter the population of the US: "; std::cin >> a;
std::cout << "The population of the US is " << long double(a) / w << "% of the world population" << std::endl;

//Num 6:
//I dont't want ,both.

//Num 7:
double n;
std::cout << "Enter a number:"; std::cin >> n;
n /= 3.875; n=62.14/n;
std::cout << n << std::endl;

猜你喜欢

转载自blog.csdn.net/qq_36389986/article/details/113166481