C/C++知识点之C++ primer plus Chapter 2
小标 2018-08-27 来源 : 阅读 1769 评论 0

摘要:本文主要向大家介绍了C/C++知识点之C++ primer plus Chapter 2,通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。

本文主要向大家介绍了C/C++知识点之C++ primer plus Chapter 2,通过具体的内容向大家展示,希望对大家学习C/C++知识点有所帮助。

Chapter Review
They are called functions.
It causes the contents of the iostream file to be substituted for this directive before final compilation.
It makes definitions made in the std namespace available to a program.
cout << "Hello, world" << endl; or cout << "Hello, world\n";
int cheeses;
cheeses = 32;
cin >> cheeses;
cout << "We have " << cheeses << " varieties of cheese\n";
The function froop() expects to be called with one argument, which will be type double, and that the function will return a type int value. For instance, it could be used as follows:
int gval = froop(3.14159);
The function rattle() has no return value and expects an int argument. For instance, it could be used as follows:
rattle(37);
The function prune() returns an int and expects to be used without an argument. For instance, it could be used as follows:
int residue = prune();
You don't have to use return in a function when the function has the return type void. However, you can use it if you don't give a return value:
return;
The likely cause it that the function loses a statement using namespace std; to declare a directive of output.
place using namespace std; above the main() function;
place using std::cout; in the main() function;
type as following: using std::cout << "Please enter your PIN: " << std::endl;
Programming Exercises
1

#include 

int main()
{
    using namespace std;
    
    cout << "Name: NaRiSu;\n"
         << "Address: BeiJing;" << endl;
         
    return 0;
}
2

#include 

int main()
{
    using namespace std;
    
    int furlong;
    cin >> furlong;
    cout << furlong << " furlong(s) = "
         << 220 * furlong << " yard(s)" << endl;
    
    return 0;
}
3

#include 
void f1();
void f2();

using namespace std;

int main()
{   
    f1();
    f1();
    f2();
    f2();
    
    return 0;
}

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

void f2()
{
    cout << "See how they run\n"; // 也可以用f1()函数中的endl形式。
    
    return; // void f2()表明无返回值,故可以这样写;也可以如f1()不写return语句。
}
4

#include 

int main()
{
    using namespace std;
    
    cout << "Enter your age: ";
    int age;
    cin >> age;
    cout << "Your age in months is " << 12 * age << "." << endl;
    
    return 0;
}
5

#include 
double fahrenheit(double);

int main()
{
    using namespace std;
    
    cout << "Please enter a Celsius value: ";
    int celsius;
    cin >> celsius;
    cout << celsius << " degrees Celsius is "
         << fahrenheit(celsius) << " degrees Fahrenheit." << endl;
    
    return 0;
}

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

#include 
double astronomical(double);

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

double astronomical(double n)
{
    return 63240 * n;
}
7

#include 
void f(int, int);

int main()
{
    using namespace std;
    
    cout << "Enter the number of hours: ";
    int hour;
    cin >> hour;
    cout << "Enter the number of minutes: ";
    int minute;
    cin >> minute;
    f(hour, minute);
    
    return 0;
}

void f(int h, int m)
{
    using namespace std;
    
    cout << "Time: " << h << " : " << m << endl;
}    

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标编程语言C/C+频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 1 不喜欢 | 0
看完这篇文章有何感觉?已经有1人表态,100%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved