C++ Primer
文章平均质量分 58
AwL_1124
这个作者很懒,什么都没留下…
展开
-
C++ Primer:Exercises Section 1.1.1
Exercise 1.1:查看所用的编译器文档,了解它所用的文件命名规范。编译并运行本节的 main 程序。int main() { return 0; }由于此main函数没有执行任何操作,执行后无任何返回结果Exercise 1.2:修改程序使其返回 -1。返回值 -1 通常作为程序运行失败的指示器。然而,系统不同,如何(甚至是否)报告main原创 2011-11-24 11:28:21 · 795 阅读 · 0 评论 -
C++ Primer:Exercises Section 1.3
Exercise 1.7:编译有不正确嵌套注释的程序。#include int main(){ std::cout<<"Enter two numbers:"<<std::endl; int v1,v2; std::cin>>v1>>v2; std::cout<<"The value of "<<v1<<" * "<<v2<<" is "; std::cout<<v1*v2<<s原创 2011-11-24 11:57:51 · 427 阅读 · 0 评论 -
C++ Primer:Exercises Section 2.2
Exercise 2.7:解释下列字面值常量的不同之处。(a) 'a',L 'a',"a",L"a"(b) 10, 10u, 10L, 10uL, 012, 0xC (c) 3.14, 3.14f, 3.14L(a)‘a’:单个字符a,L'a':宽单个字符a,“a”字符a与空字符,L"a"宽字符a与空字符(b)10:整数,10U:无符号整数,10L:长整数型,10uL:原创 2011-11-24 15:22:09 · 659 阅读 · 0 评论 -
C++ Primer:Exercises Section 2.1.2
Exercise 2.1:int、long 和 short 类型之间有什么差别?int 16位,short 16位,long 32位Exercise 2.2:unsigned 和 signed 类型有什么差别?unsigned无符号型(大于等于0),signed带符号(任意数值)Exercise 2.3:如果在某机器上 short 类型占 16 位,那么可以赋给 sho原创 2011-11-24 15:06:21 · 492 阅读 · 0 评论 -
C++ Primer:Exercises Section 1.6
Exercise 1.25:使用源自本书配套网站的 Sales_item.h 头文件,编译并执行本节给出的书店程序。Exercise 1.26:在书店程序中,我们使用了加法操作符而不是复合赋值操作符将 trans 加到 total 中,为什么我们不使用复合赋值操作符?此程序已重载了,此操作符原创 2011-11-24 14:55:52 · 549 阅读 · 0 评论 -
C++ Primer:Exercises Section 1.5.2
Exercise 1.24:编写程序,读入几笔不同的交易。对于每笔新读入的交易,要确定它的 ISBN 是否和以前的交易的 ISBN 一样,并且记下每一个 ISBN 的交易的总数。通过给定多笔不同的交易来测试程序。这些交易必须代表多个不同的 ISBN,但是每个 ISBN 的记录应分在同一组。 Sales_item book1,book2,book3; Sales_item bookType原创 2011-11-24 14:18:40 · 633 阅读 · 0 评论 -
C++ Primer:Exercises Section 1.5.1
Sales_item.h#ifndef SALESITEM_H#define SALESITEM_H#include #include class Sales_item{public: Sales_item(const std::string &book):isbn(book),units_sold(0),revenue(0.0){} Sales_item(std::istr原创 2011-11-24 14:11:20 · 569 阅读 · 0 评论 -
C++ Primer:Exercises Section 1.4.4
Exercise 1.18:编写程序,提示用户输入两个数并将这两个数范围内的每个数写到标准输出。 int v1, v2; std::cin >> v1 >> v2; // read input if (v1 > v2) { for (v2;v1>=v2;v2++) { std::cout<<v2<<std::endl; } } else if(v2 > v1)原创 2011-11-24 13:44:37 · 610 阅读 · 0 评论 -
C++ Primer:Exercises Section 1.4.3
Exercise 1.14:如果输入值相等,本节展示的程序将产生什么问题?#include int main(){ std::cout << "Enter two numbers:" << std::endl; int v1, v2; std::cin >> v1 >> v2; // read input // use smaller number as lower bound f原创 2011-11-24 12:18:01 · 467 阅读 · 0 评论 -
C++ Primer:Exercises Section 1.4.2
Exercise 1.9:下列循环做什么?sum 的最终值是多少? int sum = 0; for (int i = -100; i <= 100; ++i) sum += i;i从-100到100之间整数求和,最终全部中和,结果 为0Exercise 1.10:用 for 循环编程,求从 50 到 100 的所有自然数的和。然后用 while原创 2011-11-24 12:09:20 · 402 阅读 · 0 评论 -
C++ Primer:Exercises Section 1.2.2
Exercise 1.3:编一个程序,在标准输出上打印“Hello, World”。#include int main(){ std::cout<<"Hello,World"<<std::endl; return 0;}Exercise 1.4:我们的程序利用内置的加法操作符“+”来产生两个数的和。编写程序,使用乘法操作符“*”产生两个数的积。#include int ma原创 2011-11-24 11:38:01 · 477 阅读 · 0 评论 -
C++ Primer:Exercises Section 2.3
Exercise 2.11:编写程序,要求用户输入两个数——底数(base)和指数(exponent),输出底数的指数次方的结果。 int base,expond,result = 1; std::cin>>base>>expond; for (expond;expond > 0;expond--) { result *= base; } std::coutExerc原创 2011-11-24 15:41:27 · 827 阅读 · 0 评论