C++ Primer Plus 复习题及编程练习记录

2.6   复习题

1,函数        

2,用iostream文件的内容替换该行

3,使std名称空间中的名称都可用        /使得程序可以使用std名称空间中的定义

4,cout<<"Hello,world"<<endl;

5,int cheeses;

6,cheeses=32;

7,cin>>cheeses;

9,返回值类型 形参类型,形参个数,函数名称

10,返回值类型为void时

11,未在函数中添加using namespace std;语句        /在函数中添加using ... /在函数外添加using.../使用std::cout<<打印语句

2.7 编程练习

#include<iostream>
using namespace std;
int main()
{        
    cout<<"张先仙"<<endl;
    cout<<"广东省肇庆市";

    return 0;
}
#include<iostream>
using namespace std;
int main()
{        
	long x;
    cout<<"请输入一个以long为单位的距离:\n";
	cin>>x;
	cout<<x<<" long为: "; 
	cout<<x*220<<"码";

    return 0;
}
#include<iostream>
using namespace std;

void fun1()
{
	cout<<"Three blind mice\n";
}

void fun2()
{
	cout<<"See how they run"<<endl;
}


int main()
{        
    fun1();
    fun1();
    fun2();
    fun2();
    
    return 0;
}
#include<iostream>
using namespace std;

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

double fun(int val) {
	return 1.8*val+32.0;
}

int main()
{        
	int val;
	cout<<"Please enter a Celsius value:";
	cin>>val;
	cout<<endl;
	cout<<val<<" degrees Celsius is "<<fun(val)<<" degrees Fahreheit\n";
	
    return 0;
}
,
#include<iostream>
using namespace std;

void fun(int a,int b) {
	cout<<"Time: "<<a<<":"<<b;
}

int main()
{        
	int hours,minutes;
	cout<<"Enter the number of hours:";
	cin>>hours;
	cout<<"Enter the number of minutes:";
	cin>>minutes;
	cout<<endl;
	fun(hours,minutes);
    return 0;
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值