C++ Primer Plus 6e Stephen Prata
(Solutions Manual All Chapter)
- / 4
Solutions for Programming Exercises in C++ Primer Plus, 6 th Edition SP 1 of 176 September 30, 2011 Some programming environments run programs in a window that closes automatically when the program terminates. The solutions below include code as comments to keep the window open until a key is struck. In most cases this extra code consists of one or two cin.get() statements, but some program require more elaborate code.Chapter 2 // pe2-1.cpp
#include
int main() { using namespace std; cout << "Glandville Gibbons \n"; cout << "8234 Springle Road \n"; cout << "Bright Rock, CA 94888 \n"; //cin.get(); return 0; }
// pe2-2.cpp
#include
int main() { using namespace std;
cout << "Enter a distance in furlongs: ";
double furlongs; cin >> furlongs; double feet; feet = 220 * furlongs; cout << furlongs << " furlongs = " << feet << " feet\n"; //cin.get(); //cin.get(); return 0; }
// pe2-3.cpp
#include
void mice(); void run(); int main() { mice(); mice(); run(); run();
- / 4
Solutions for Programming Exercises in C++ Primer Plus, 6 th Edition SP 2 of 176 September 30, 2011 //cin.get(); return 0; }
void mice() { cout << "Three blind mice \n"; }
void run() { cout << "See how they run \n"; }
// pe2-4.cpp -- displays age in months #include
cout << "Enter your age: ";
int years; cin >> years; cout << "Your age in months is " << 12 * years << "." << endl; //cin.get(); //cin.get(); return 0; }
// pe2-5.cpp
#include
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"; //cin.get(); //cin.get();
return 0; }
double C_to_F(double temp) { return 1.8 * temp + 32.0;
} 3 / 4
Solutions for Programming Exercises in C++ Primer Plus, 6 th Edition SP 3 of 176 September 30, 2011
// pe2-6.cpp #include
double ly_to_au(double); int main() { using namespace std; double light_years; double astr_units;
cout << "Enter the number of light years: ";
cin >> light_years; astr_units = ly_to_au(light_years); cout << light_years << " light years = "; cout << astr_units << " astronomical units. \n"; //cin.get(); //cin.get(); return 0; }
double ly_to_au(double ly) { return 63240.0 * ly; }
// pe2-7.cpp -- displays hours and minutes #include
cout << "Enter the number of hours: ";
int hours; cin >> hours;
cout << "Enter the num ber of minutes: ";
int minutes; cin >> minutes; showtime(hours, minutes); //cin.get(); //cin.get(); return 0; }
void showtime(int hrs, int mins) { using namespace std; cout << "Time: " << hrs <<":" << mins << endl; }
Chapter 3
// pe3-1.cpp
- / 4