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

第一题:

#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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值