C ++ Primer Plus Chapter Two After-Class Programming Exercises 2-7

2.。。。。。
#include

int main ()
{
using namespace std;
int llong;
cout << "Please enter a distance in long units:" << endl;
cin >> llong;
cout << llong << "Distance in long units, equal to" << llong * 220 << "Code" << endl;

return 0;

}

3.。。。。。

#include
using namespace std;
void two(void);
void one(void);
int main()
{
two();
one();
one();

return 0;

}

void two(void)
{
cout << “Three blind mice” << endl;
cout << “Three blind mice” << endl;
}

void one(void)
{
cout << “See how they run” << endl;
}

4.。。。。

#include
using namespace std;

int main ()
{
int year;
cout << "Please enter your age:" << endl;
cin >> year;
cout << "Your age is" << year << "contains" << year * 12 << "months." << endl;

return 0;

}

5.。。。。
#include
using namespace std;

double fahrenheit(double n);

int main()
{
double css,frht;
cout << “Please enter a Celsius value:”;
cin >> css;
frht = fahrenheit(css);
cout << css <<" degrees Celsius is "
<< frht << " degrees Fahrenheit." << endl;

return 0;

}

double fahrenheit(double n)
{
double frhit = n * 1.8 +32.0;
return frhit;
}

6.。。。。
#include
using namespace std;

int astronomical_units(double ly);
int main()
{
double lyear;
cout << “Enter the number of light years: “;
cin >> lyear;
cout << lyear <<” light years = "
<< astronomical_units(lyear)
<<” astronomical units." <<endl;

return 0;

}

int astronomical_units(double ly)
{
int AU = (int)ly * 63240;

return AU;

}

7.。。。。
#include
using namespace std;
void time(int hours, int minutes);
int main()
{
int hours, minutes;
cout <<"Enter the number of hours: ";
cin >> hours;
cout <<"Enter the number of minutes: ";
cin >> minutes;
time(hours, minutes);

return 0;

}

void time(int hours, int minutes)
{
cout <<“Time: "
<< hours
<<” : "
<< minutes
<< endl;
}

Published 85 original articles · Like1 · Visits1889

Guess you like

Origin blog.csdn.net/Tekkenwxp/article/details/103542889