随笔分类 - C++训练
摘要:14.42 使用标准库函数对象及适配器定义一条表达式,令其1 统计打于1024的值有多少个。2 找到第一个不等于pooh的字符串3 将所有的值乘以214.43 使用标准库函数对象判断一个给定的int值是否能被int容器中的所有元素整除#include#include#include#include#...
阅读全文
摘要:14.38 编写一个类令其检查某个给定的string对象的长度是否与一个阈值相等。使用该对象编写程序,统计并报告在输入的文件中长度为1的单词有多少个,长度为2的单词有多少个、.....、长度为10的单词又有多少个。#include#include#include#include#includeusi...
阅读全文
摘要:14.34定义一个函数对象类,令其执行if-then-else的操作;该类型的调用运算符接受三个参数,它首先检查第一个形参,如果成功返回第二个参数的值;如果不成功返回第三个形参的值。#includeusing namespace std;class if_then_else{public: i...
阅读全文
摘要:13.57 编写Foo类。Foo.h#ifndef FOO_H#define FOO_H#include#include#includeusing namespace std;class Foo{public: Foo sorted() &&; Foo sorted() const &;...
阅读全文
摘要:13.50 没有定义析构函数#include#include#include#include#include#includeusing namespace std;class String{public: String():elements(nullptr),first_free(nullpt...
阅读全文
摘要:13.44 编写标准库string类的简化版本,命名String。你的类应该至少有一个默认构造函数和一个接受C风格字符串指针参数的构造函数。使用allocator为你的String类分配所需内存。13.47 添加拷贝构造函数和拷贝赋值运算符,并添加打印语句,则每次函数执行时打印一条信息。13.48 ...
阅读全文
摘要:13.39 编写自己的StrVec,包括自己版本的reserve、capacity和resize。13.40 为StrVec添加一个构造函数,它接受一个initializer_list参数StrVec.h#ifndef STRVEC_H#define STRVEC_H#include#include...
阅读全文
摘要:13.33 13.36 13.37Message.h#ifndef MESSAGE_H#define MESSAGE_H#include#include#include#include"Folder.h"using namespace std;class Folder;class Message{f...
阅读全文
摘要:13.31为你的HasPtr类定义一个#include#include#include#includeusing namespace std;class HasPtr{friend void swap(HasPtr&,HasPtr&);public: HasPtr(const string &...
阅读全文
摘要:13.27 定义使用引用计数版本的HasPtr#include#include#includeusing namespace std;class HasPtr{public: HasPtr(const string &s=string()):ps(new string(s)),i(0),use...
阅读全文
摘要:13.22 假定我们希望HasPtr的行为像一个值。即,对于对象所指向的string成员,每个对象都有一份自己的拷贝。#include#include#includeusing namespace std;class HasPtr{public: HasPtr(const string &s=...
阅读全文
摘要:#include #include #include #include struct Numbered{ //! for ex13.14 Numbered() { static unsigned i = 0; ++i; mySn = i; ...
阅读全文
摘要:12.32 重写TextQuery和QueryResult类,用StrBlob代替vector保存输入文件。TextQuery.h#ifndef TEXTQUERY_H#define TEXTQUERY_H#include#include#include#include#include#includ...
阅读全文
摘要:我们实现一个简单的文本查询程序。我们的程序允许用户在一个给定文件中查询单词,查询结果是单词在文件中出现的次数及所在行的列表。如果一个单词在一行中出现多次,此行只列出一次。#include#include#include#include#include#include#include#includeu...
阅读全文
摘要:12.20 编写程序,逐行读入一个输入文件,将内容存入一个StrBlob中,用一个StrBlobPtr打印出StrBlob的每个元素。StrBlob.h#ifndef STRBLOB_H#define STRBLOB_H#include#include#include#includeusing na...
阅读全文
摘要:12.6 编写函数,返回一个动态分配的int的vector。将此vector传递给另一个函数,这个函数读取标准输入,将读入的值保存在vector元素中。再将vector传递给另一个函数,打印读入的值。记得在恰当的时刻delete vector。#include#include#includeusin...
阅读全文
摘要:11.20 使用insert代替下标操作。#include#include#include#includeusing namespace std;int main(){ map word_count; string word; while(cin>>word) { ...
阅读全文
摘要:11.12 编写程序,读入string和int的序列,将每个string和int存入一个pair中,pair保存在一个vector中。#include#include#include#includeusing namespace std;int main(){ vector> vec; ...
阅读全文
摘要:11.4 编写单词计数程序,忽略大小写和标点。例如,“example.”,“example,"和”Example“应该递增相同的计算器。#include#include#include#includeusing namespace std;int main(){ map word_count;...
阅读全文
摘要:10.42 使用list的算法实现排序和删除重复元素。#include#include#include#includeusing namespace std;void elimDup(list &words){ words.sort(); words.unique();}bool isS...
阅读全文

浙公网安备 33010602011771号