c++primer plus(第6版本)第二章重点总结 以及手写代码练习题答案

11 篇文章 0 订阅

1.endl  和 \n 的区别

两者都可以在标准输出流达到换行效果,然而不同点是,endl确保程序继续运行前刷新输出(将其立即显示在屏幕上),而\n没有这样的功能

2.关于源代码中的标记和空白

一行代码中不可分割的部分元素叫标记,通常由空格,制表符或者回车(统称为空白)将两个标记分开。有些字符(如括号和逗号)是不需要用空白分开标记的。

举例:

return0;   //invalid,must be return 0

return (0);   //valid,white space omitted;

return (0);   //valid,white space used;

intmain();   //invalid,white space omitted; 

int main()   //valid,white space omitted in ()

int main( ) //valid,white space used in () 

3.main()

可以将计算机操作系统看作调用程序,因此main函数的返回值并不是返回给程序的其他部分,而是返回给操作系统。

4.using namespce std;

说明使用处于std命名空间中的所有元素,而不是其他命名空间中的。且放在全局的位置可以通用

5.声明

void hehe(int);

void hehe(int a)

{

\\函数体

}

第一个是函数声明,在使用该函数前必须声明,第二个才是函数定义。一般声明在前,主函数在中,函数定义在后。大型工程中,可以将函数声明置于hpp文件中,然后用#include" "在cpp文件中包含进来

 

第二章的练习题目如下,共七道,是手写的。(标准答案网上也有,该程序可以给小白们看看)

#include<iostream>
#include<stdio.h>
//#include"mycout.hpp"
using namespace std;
//+++++++++++++++++++++++++++++++++++++++1++++++++++++++++++++++++++++++++++++++++++++++++++
/*void address_and_name(void);
int main()
{
address_and_name();
}

void address_and_name(void)
{
cout<<"your name is xxx\n"<<"your address is xxx"<<endl;
}*/

//++++++++++++++++++++++++++++++++++++++2+++++++++++++++++++++++++++++++++++++++++++++++++++
/*long distance (long);
int main(){
cout<<"enter your distance"<<endl;
long a;
cin >> a;
cout<<distance(a)<<endl;
return 0; 
//cin.get();
//return 0;
}

long distance(long b)
{
return b*220;
}*/

//++++++++++++++++++++++++++++++++++++++++++++++++3++++++++++++++++++++++++++++++++++++++++++++++

/*void mycout1(void);
void mycout2(void);

int main()
{
mycout1();
mycout1();
mycout2();
mycout2();
}

void mycout1(void)
{
cout<<" Three blind mice"<<endl;
}

void mycout2(void)
{
cout<<"See how they run\n";
}*/

//++++++++++++++++++++++++++++++++++++++++++++++4++++++++++++++++++++++++++++++++++++++++++++++++++
/*void age_to_month(int);
int main()
{
cout<<"enter your age"<<endl;
int a;
cin>>a;
age_to_month(a);
return 0;
}

void age_to_month(int n)
{
cout << "your ages equal to " << n*12 <<" month"<<endl;
}
*/

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++5++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*double sheshi_to_huashi(double);

int main()
{
cout<<"Please enter a Celsius value : "<<endl;
double a,b;
cin>>a;
b=sheshi_to_huashi(a);
cout<<a<<" "<<" degree Celsius is "<<b<<" "<<"  degrees Fahrenheit"<<endl;
}

double sheshi_to_huashi(double x)
{
return 1.8*x+32.0;
}
*/
//++++++++++++++++++++++++++++++++++++++++++++++++++6++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*double guangnian_to_tianwen(double);
int main()
{
cout<<"Enter the number of light years:"<<endl;
double a,b;
cin>>a;
b=guangnian_to_tianwen(a);
cout<<a<<"light years ="<<b<<"astronomical units"<<endl;
}
double guangnian_to_tianwen(double x)
{
return 63240*x;
}*/
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++7++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*void time(int,int);
int main()
{
double a,b;
cout<<"enter the number of hours:"<<endl;
cin>>a;
cout<<"enter the number of minutes"<<endl;
cin>>b;
time(a,b);
}

void time(int x,int y)
{
cout<<"Time"<<x<<":"<<y<<endl;
}*/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值