C++PRIMER PLUS 第五版第三章习题参考答案

Chapter 3

// pe3-1.cpp

#include <iostream>

const int Inch_Per_Foot = 12;

int main(void)
{
using namespace std;
// Note: some environments don't support the backspace character cout << "Please enter your height in inches: ___/b/b/b "; int ht_inch;
cin >> ht_inch;
int ht_feet = ht_inch / Inch_Per_Foot;
int rm_inch = ht_inch % Inch_Per_Foot;
cout << "Your height is " << ht_feet << " feet, ";
cout << rm_inch << " inch(es).\n";
return 0;
}

// pe3-3.cpp
#include <iostream>
const double MINS_PER_DEG = 60.0;
const double SECS_PER_MIN = 60.0;
int main()
{
using namespace std;

int degrees;
int minutes;
int seconds;
double latitude;

cout << "Enter a latitude in degrees, minutes, and seconds:\n"; cout << "First, enter the degrees: ";
cin >> degrees;
cout << "Next, enter the minutes of arc: ";
cin >> minutes;
cout << "Finally, enter the seconds of arc: ";
cin >> seconds;

相关文档
最新文档