- 1、本文档被系统程序自动判定探测到侵权嫌疑,本站暂时做下架处理。
- 2、如果您确认为侵权,可联系本站左侧在线QQ客服请求删除。我们会保证在24小时内做出处理,应急电话:400-050-0827。
- 3、此文档由网友上传,因疑似侵权的原因,本站不提供该文档下载,只提供部分内容试读。如果您是出版社/作者,看到后可认领文档,您也可以联系本站进行批量认领。
查看更多
Chapter 1
Exercise 1.1
Review the documentationforyourcompilerand determinewhat file naming
convention it uses.Compile and runthe main programfrom page 2.
Windows
Linux
Exercise 1.2
Exercise 1.2:Changethe programto return-1.A returnvalue of -1is often
treated as an indicatorthat the programfailed. Recompile and rerunyour
programto see how yoursystemtreats a failure indicatorfrom main.
Windows
Linux
255?why? please lookat this
Exercise 1.3
Write a programto print Hello,World onthe standard output.
#include iostream
int main()
{
std::cout Hello, World std::endl;
return 0;
}
Exercise 1.4
Our program used the additionoperator,+,to addtwo numbers.Write a
programthat uses the multiplicationoperator,*,to print the product instead.
#include iostream
int main()
{
std::cout Enter two numbers: std::endl;
int v1 = 0, v2 = 0;
std::cin v1 v2;
std::cout The product of v1 and v2
is v1 * v2 std::endl;
return 0;
}
Exercise 1.5
Wewrote the output inone large statement. Rewritethe programto use a
separate statement to print eachoperand.
#include iostream
int main()
{
std::cout Enter two numbers: std::endl;
int v1 = 0, v2 = 0;
std::cin v1 v2;
std::cout The product of ;
std::cout v1;
std::cout and ;
std::cout v2;
std::cout is ;
std::cout v1 * v2;
std::cout std::endl;
return 0;
}
Exercise 1.6
Explainwhetherthefollowing programfragment is legal.
Its illegal.
[Error] expected primary-expression before token
Fixed it: remove the spare semicolons.
std::cout The sum of v1
and v2
is v1 + v2 std::endl;
Exercise 1.7
Compile a programthat has incorrectly nested comments.
Example:
/*
* comment pairs /* */ cannot nest.
* cannot nest is considered source code,
* as is the rest of the program
*/
int main()
{
return 0;
}
Compiled result(g++):
Exercise 1.8
Indicatewhich, if a
文档评论(0)