Exam Practice!
1. T
Syntax Problems
7. replace , with ;
Multiple Choice
10. (c)
Programming Problems
Unit Conversions.
/*——————————————————————–*/
/* Problem chapter4_17 */
int main()
{
// Declare and initialize variables.
double degrees, increment=PI/10, radians=0;
// Set formats
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(3);
// Print radians and degrees in a loop.
/* */
/* This program prints a conversion table from degrees to radians. */
int main()
{
// Declare and initialize variables.
double degrees=0, increment=0, radians=0;
cout.precision(3);
// Print title and table
cout << “Degrees to Radians with increment ” << increment << endl;
}
/*——————————————————————–*/
/*——————————————————————–*/
/* Problem chapter4_19 */
/* */
const double CM_PER_INCH = 2.54;
int main()
// Print table title and values.
cout << “Inches to Centimeters\n”;
while (inches <= 20.0)
{
/* It starts the mph column at 0, and increment by 5 mph. */
/* The last line contains the value 65 mph. */
#include <iostream>
using namespace std;
return 0;
}
/*——————————————————————–*/
/*——————————————————————–*/
int main()
{
// Define and initialize variables.
int fps=0, increment=5;
double mph=0;
}
/*——————————————————————–*/
Currency Conversions
/*——————————————————————–*/
/* Problem chapter4_22 */
/* */
#include <iostream>
using namespace std;
{
dollars = (double)pesos/PESO_PER_DOLLAR;
cout << pesos << ” P $” << dollars << ” \n”;
pesos += increment;
}
#include <iostream>
using namespace std;
const double PESO_PER_DOLLAR = 17.56;
const double Y_PER_DOLLAR = 108.7;
int main()
{
// Define and initialize variables.
int yen=1, increment=2, loopcount;
double peso;
}
// Exit program.
return 0;
}
/*——————————————————————–*/
const double RAND_PER_DOLLAR = 14.56;
int main()
{
// Define and initialize variables.
int loopcount;
double increment = (10000 – 100)/24.0;
yen += increment;
}
// Exit program.
return 0;
}
/*——————————————————————–*/
/*——————————————————————–*/
/* Problem chapter4_25 */
int main()
{
// Define and initialize variables.
int dollars=1, increment=1, loopcount;
double pesos, yen, rand;
}
// Exit program.
return 0;
}
/*——————————————————————–*/
Temperature Conversions.
int main()
{
// Define and initialize variables.
int farenheit=0, increment=5;
double celsius;
// Print title and table.
}
/* */
/* This program generates a table of conversions from Fahrenheit */
/* to Kelvin for values from 0 degrees F to 200 degrees F. */
/* It allows the user to enter the increment in degrees F. */
#include <iostream>
using namespace std;
int main()
}
// Print title and table.
cout << “Farenheit to Kelvin in ” << increment
<< “-degree increments \n”;
do {
kelvin = (5.0/9.0)*((double)farenheit + 459.67 );
cout << farenheit << ” F ” << kelvin << ” K \n”;
farenheit += increment;
#include <iostream>
using namespace std;
int main()
{
farenheit = (9.0/5.0) * celsius + 32;
rankin = farenheit + 459.67;
cout << celsius << ” C ” << rankin << ” R \n”;
celsius += increment;
}
#include <iostream>
using namespace std;
const double REFOREST_RATE = 0.02;
const double UNCUT_ACRES = 2500;
const double MAX_YEARS = 20;
int main()
year++;
}
// Exit program.
return 0;
}
/*——————————————————————–*/
using namespace std;
const double REFOREST_RATE = 0.02;
const double UNCUT_ACRES = 2500;
int main()
{
// Declare and initialize variables.
while (year <= max_years)
{
forested += REFOREST_RATE*forested;
cout << year << ” ” << forested << endl;
year++;
}
// Exit program.
using namespace std;
const double REFOREST_RATE = 0.02;
const double UNCUT_ACRES = 2500;
const double MAX_ACRES = 14000;
int main()
{
}
// Set format.
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
// Print headings.
return 0;
}
/*——————————————————————–*/
Loops
/*——————————————————————–*/
/* Problem chapter4_32 */
bool condition = (A && B || B && C);
//Print table header
cout << “TABLE 3.2\n A\tB\tC\t\tA && B || B && C” << endl;
cout << “_________________________________________________” << endl;
for(int i=1; i<=2; ++i) //base 2 – most significant
{
}
return 0;
}
/******************************************************************/
/* Program chapter4_33 */
/* */
int satID, minID;
double tTime, pRange, minPRange(DBL_MAX);
//Prompt user for input
cout << “Enter id and transit time for “
<< NUMBER_OF_SATELLITES << ” satellites:\n”
<< “Use whitespace to separate the values(ie: 25 0.00567)\n”
<< endl;
int count(0); //initialize counter
do
{
cout << “\nSatellite ” << minID
<< ” is closest to GPS receiver.” << endl;
return 0;
}
/*****************************************************************/
/******************************************************************/
/* Program chapter4_34 */
const int NUMBER_OF_SATELLITES(4);
int satID, minID;
double tTime, pRange, minPRange(DBL_MAX);
//Prompt user for input
cout << “Enter id and transit time for “
<< NUMBER_OF_SATELLITES << ” satellites:\n”
<< “Use whitespace to separate the values(ie: 25 0.00567)\n”
<< endl;