没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Solutions for Programming Exercises in C++ Primer Plus, 5th Edition
Chapter 2
// pe2-2.cpp
#include <iostream>
int main(void)
{
using namespace std;
cout << "Enter a distance in furlongs: ";
double furlongs;
cin >> furlongs;
double feet;
feet = 220 * furlongs;
cout << furlongs << " furlongs = "
<< feet << " feet";
return 0;
}
// pe2-3.cpp
#include <iostream>
using namespace std;
void mice();
void run();
int main()
{
mice();
mice();
run();
run();
return 0;
}
void mice()
{
cout << "Three blind mice";
}
void run()
{
cout << "See how they run\n";
}
// pe2-4.cpp
#include <iostream>
double C_to_F(double);
int main()
{
using namespace std;
cout << "Enter a temperature in Celsius: ";
double C;
cin >> C;
double F;
F = C_to_F(C);
cout << C << " degrees Celsius = "
<< F << " degrees Fahrenheit\n";
return 0;
}
double C_to_F(double temp)
{
return 1.8 * temp + 32.0;
}
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;
latitude = degrees + (minutes + seconds / SECS_PER_MIN)/MINS_PER_DEG;
cout << degrees << " degrees, " << minutes << " minutes, "
<< seconds << " seconds = " << latitude << " degrees\n";
return 0;
}
// pe3-5.cpp
#include <iostream>
int main(void)
{
using namespace std;
cout << "How many miles have you driven your car? ";
float miles;
cin >> miles;
cout << "How many gallons of gasoline did the car use? ";
float gallons;
cin >> gallons;
cout << "Your car got " << miles / gallons;
cout << " miles per gallon.\n";
return 0;
}
// pe3-6.cpp
#include <iostream>
const double KM100_TO_MILES = 62.14;
const double LITERS_PER_GALLON = 3.875;
int main ( void )
{
using namespace std;
double euro_rating;
double us_rating;
cout << "Enter fuel consumption in liters per 100 km: ";
cin >> euro_rating;
// divide by LITER_PER_GALLON to get gallons per 100-km
// divide by KM100_TO_MILES to get gallons per mile
// invert result to get miles per gallon
us_rating = (LITERS_PER_GALLON * KM100_TO_MILES) / euro_rating;
cout << euro_rating << " liters per 100 km is ";
cout << us_rating << " miles per gallon.\n";
return 0;
}
Chapter 4
// pe4-2.cpp -- storing strings in string objects
#include <iostream>
#include <string>
int main()
{
using namespace std;
string name;
string dessert;
cout << "Enter your name:\n";
getline(cin, name); // reads through newline
cout << "Enter your favorite dessert:\n";
getline(cin, dessert);
cout << "I have some delicious " << dessert;
cout << " for you, " << name << ".\n";
return 0;
}
// pe4-3.cpp -- storing strings in char arrays
#include <iostream>
#include <cstring>
const int SIZE = 20;
int main()
{
using namespace std;
char firstName[SIZE];
char lastName[SIZE];
char fullName[2*SIZE + 1];
cout << "Enter your first name: ";
cin >> firstName;
cout << "Enter your last name: ";
cin >> lastName;
strncpy(fullName,lastName,SIZE);
strcat(fullName, ", ");
strncat(fullName, firstName, SIZE);
fullName[SIZE - 1] = '\0';
cout << "Here's the information in a single string: "
<< fullName << endl;
return 0;
}
// pe4-5.cpp
// a candybar structure
剩余63页未读,继续阅读
资源评论
- Zack_8882014-03-08答案不全,复杂的题目答案没有啊
minjianmin
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功