C++ Primer Plus 第六版 第二章编程练习答案参考(仅仅用作学习交流,若有错误,请联系作者,谢谢)

版权声明:所有博客均由作者本人原创,若要转载,请注明出处。谢谢 https://blog.csdn.net/LU_Leo/article/details/80716792

第一题:

#include <iostream>
using namespace std;
int main(void)
{
	cout << "luxiao " << "shanghai university " << endl;
	return 0;
}

第二题:

#include <iostream>
using namespace std;
int change(int n);
int main()
{
	int distance;
	cout<<"Please enter a distance:";
	cin>>distance;
	cout<<distance<<" longs = "<<change(distance)<<" yards ."<<endl;
	return 0;
}
int change(int n)
{
	return n*220;
} 

第三题:

#include <iostream>
using namespace std;
void function1();
void function2();
int main()
{
	function1();
	function2();
	return 0;
}
void function1()
{
	cout<<"Three blind mice"<<endl;
	cout<<"Three blind mice"<<endl;
}
void function2()
{
	cout<<"See how they run"<<endl;
	cout<<"See how they run"<<endl;
}

第四题:

#include <iostream>
using namespace std;
int main()
{
	int age;
	cout << "Enter your age :";
	cin >> age;
	cout << age*12 <<" months"<<endl;
	return 0;
}

第五题:

#include <iostream>
using namespace std;
double change(double n);
int main()
{   
    double celsius;
	cout<<"Please enter a Celsius value:";
	cin>>celsius;
	cout<<celsius<<" degrees celsuis is "<<change(celsius)<<" Fehrenheit."<<endl;
	return 0;
}
double change(double n)
{
    return 1.8*n+32.0;
}

第六题:

#include <iostream>
using namespace std;
double change(double n);
int main()
{
	cout<<"Enter the number of light years:";
	double year;
	cin>>year;
	cout<<year<<" light years = "<<change(year)<<" astronomical units."<<endl;
	return 0;

}
double change(double n)
{
	return n*63240;
}

第七题:

#include <iostream>
using namespace std;
void time(int a, int b);
int main()
{
	cout<<"Enter the number of hours:";
	int hours;
	cin>>hours;
	cout<<"Enter the number of minutes:";
	int minutes;
	cin>>minutes;
	time(hours,minutes);
	return 0;
}
void time(int a, int b)
{
   cout<<"Time: "<<a<<":"<<b<<endl;
}



猜你喜欢

转载自blog.csdn.net/LU_Leo/article/details/80716792