C++ Primer Plus(第六版)
文章平均质量分 73
greatlisten
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
C++Primer Plus(第六版) 第七章 第六题
之前我写过C++Primer Plus 的第六章第二题,现在阅读到第七章第六题发现之前的原创 2017-04-15 23:38:20 · 307 阅读 · 0 评论 -
C++Primer Plus(第六版) 第十六章 第一题
本题主要还是STL的使用,如果知道rbegin和rend的使用就非常的快速。 代码如下: #include #include bool isPal(const std::string & s); int main() { std::string input; std::cout << "Enter a string (empty string to quit):\n"; std:原创 2017-10-06 13:33:13 · 285 阅读 · 0 评论 -
C++Primer Plus(第六版) 第十三章 第四题
port.h // port.h // #pragma once #ifndef PORT_H_ #define PORT_H_ #include using namespace std; class Port { private: char * brand; char style[20]; // i.e., tawny, ruby, vintage int bottles; publi原创 2017-08-14 16:56:22 · 302 阅读 · 0 评论 -
C++Primer Plus(第六版) 第十三章 第二题
第二题是在第一题的基础上让两个类使用动态分配内存,就是用char * 来代替char数组,故必需要重写重载几个函数,如:参数为自身类的构造函数,operator=运算符。 另外注意将基类的析构函数设为虚函数。代码如下: classic.h // base class // #pragma once #ifndef CLASSIC_H_ #define CLASSIC_H_ class Cd原创 2017-08-14 16:00:36 · 262 阅读 · 0 评论 -
C++Primer Plus(第六版) 第十三章 第一题
classic.h // base class // #pragma once #ifndef CLASSIC_H_ #define CLASSIC_H_ class Cd { // represents a CD disk private: char performers[50]; char label[20]; int selections; // number of selectio原创 2017-08-13 16:55:38 · 248 阅读 · 0 评论 -
C++Primer Plus(第六版) 第十四章 第五题
本道题主要是写定义,就只放定义的cpp代码,另外两个题目上都有 emp.cpp #include "emp.h" abstr_emp::abstr_emp() { } abstr_emp::abstr_emp(const std::string & fn, const std::string & ln, const std::string & j) { fname = fn; lnam原创 2017-08-20 15:59:16 · 371 阅读 · 0 评论 -
C++Primer Plus(第六版) 第十四章 第一题
这题比较简单,Pair类是个模板类,也需要实例化 winec.h // winec.h #ifndef WINEC_H_ #define WINEC_H_ #include #include #include template class Pair { private: T1 year; T2 bottles; public: Pair(const T1 & yr, const T原创 2017-08-19 15:29:40 · 302 阅读 · 0 评论 -
C++Primer Plus(第六版) 第十一章 第七题
本题基本上是运算符的重载,友元函数等等,基本在之前都有写过,难一点的也就是重载cin的>>运算符 代码如下 声明(complex0.h): // complex0.h // #pragma once #ifndef COMPLEX0_H_ #define COMPLEX0_H_ #include class complex { public: complex(); complex(do原创 2017-07-21 16:29:14 · 417 阅读 · 0 评论 -
C++Primer Plus(第六版) 第十二章 第二题
本题主要是重载+运算符,使用友元函数,直接返回String。代码如下: string2.h: // string2.h // #pragma once #ifndef STRING2_H_ #define STRING2_H_ #include using std::ostream; using std::istream; class String { private: char * s原创 2017-07-30 14:17:09 · 464 阅读 · 0 评论 -
C++Primer Plus(第六版) 第十二章 第一题
本题主要是对本章基本内容的掌握,对于动态分配内存(new、new[])的情况下析构函数要对应用delete、delete[],同时由于析构函数只有一个,故注意所有的构造函数(包括重载的=运算符等)都采用相同的动态内存分配方式。 代码如下: #include #include "cow.h" Cow::Cow() { hobby = new char[1]; hobby[0] = '\0原创 2017-07-30 10:02:33 · 341 阅读 · 0 评论 -
C++Primer Plus(第六版) 第十章 第八题
本代码是从其他人的pdf答案中粘贴过来的,我不知道出处在哪,如有侵犯权益或知道出处的,请联系我。 本题难点在visit函数,它其实是函数的指针 整个的声明: #ifndef LIST_H_ #define LIST_H_ const int TSIZE = 50; struct film { char title[TSIZE]; int rating; }; typedef struct转载 2017-07-12 17:52:46 · 316 阅读 · 0 评论 -
C++Primer Plus(第六版) 第八章 第四题
如题 #include using namespace std; #include // for strlen(), strcpy() struct stringy { char *str; // points to a string int ct; // length of string (not counting '\0') }; // prototypes for set(), sh原创 2017-07-01 13:57:06 · 356 阅读 · 0 评论 -
C++Primer Plus(第六版) 第八章 第二题
如题#include #include struct CandyBar { char name[40]; double weight; int heat; }; void setCandyBar(CandyBar &candybar, const char *name = "Millennium Munch", const double weight = 2.85, const int原创 2017-07-01 12:59:49 · 495 阅读 · 0 评论 -
C++ Primer Plus(第六版) 第八章 第一题
我在网上看了下,很多都是错误的答案,更有甚者,直接说那题目太无厘头了改题目。下面是原题: 编写通常接受一个参数(字符串的地址),并打印该字符串的函数。然而,如果提供了第二个参数(int类型),且该参数不为0,则该函数打印字符串的次数为该函数被调用的次数(注意,字符串的打印次数不等于第二个参数的值,而等于函数被调用的次数)。是的,这是一个非常可笑的函数,但它让您能够使用本章介绍的一些技术,在一个简原创 2017-07-01 11:57:10 · 736 阅读 · 2 评论 -
C++Primer Plus(第六版) 第六章 第二题
最近在想好好学学C++,手头有本纸质的Primer,但想着之前的Plus还没看完,然后继续看,对于第六章第二题一开始不是很会,上网看了下都不是很符合要求,基本都有小差错,所以自己也发个博客#include #include #include using namespace std; bool judge(string line) { int len; len = line.size();原创 2017-04-12 09:36:15 · 340 阅读 · 0 评论 -
C++Primer Plus(第六版) 第十六章 第八题
这主要是STL的使用,之前书看的比较认真的话基本没什么问题 #include #include #include #include #include #include int main() { std::string temp; std::set Mats; std::cout << "Enter Mat's guest list (empty line to quit):\原创 2017-10-06 14:00:22 · 295 阅读 · 0 评论
分享