C++ Premier Plus 6th edition - Prog
七哥地盘
这个作者很懒,什么都没留下…
展开
-
C++ Premier Plus 6th edition - Programming excercise - Chapter18 - 2
cpmv.h#ifndef CPMV_H_#define CPMV_H_#include<iostream>class Cpmv{public: struct Info// info is only a self-defined type, has no contents in Cpmv { std::string qcode; ...原创 2019-03-13 19:11:04 · 150 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter16 - 9
main.cpp#include<iostream>#include<vector> // vector#include<list> // list#include<algorithm> // copy() of STL#include<iterator> // insert_iterator#include<ctime...原创 2019-02-12 11:23:26 · 105 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter16 - 8
main.cpp#include<iostream>#include<vector> // in case one has friends having same name(first and last)#include<set> // set can sort and remove duplicates#include<string>#i...原创 2019-02-11 20:27:56 · 137 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter16 -7
main.cpp// lottery card game#include<iostream>#include<vector>#include<cstdlib> // srand(),rand()#include<ctime> // time()#include<algorithm> // random_shuffle()#i...原创 2019-02-10 19:06:43 · 157 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter16 - 6
main.cpp// bank.cpp -- using the Queue interface// compile with queue.cpp#include <iostream>#include <cstdlib> // for rand() and srand()#include <ctime> // for time()#include...原创 2019-02-08 22:40:56 · 93 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter16 - 5
main.cpp#include<iostream>#include<algorithm>#include<string>template <typename T>int reduce(T ar[], int n);template <typename T>void show(T ar[], int n);using...原创 2019-02-06 11:20:59 · 108 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter16 - 4
main.cpp#include&amp;lt;iostream&amp;gt;#include&amp;lt;algorithm&amp;gt; // sort() from STL//#include&amp;lt;iterator&amp;gt;int reduce(long ar[], int n);void show(long ar[], int n);using std::cout;u原创 2019-02-05 13:15:36 · 401 阅读 · 2 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter16 - 3
今天过年了,撸点小代码助兴main.cpp// hangman.cpp -- some string methods#include &lt;iostream&gt;#include &lt;string&gt;#include &lt;cstdlib&gt; // srand(), rand()#include &lt;ctime&gt; // time()#inc原创 2019-02-04 11:34:05 · 252 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter16 - 2
main.cpp#include<iostream>#include<string>#include<cctype>#include<algorithm>#include<iterator>using std::string;using std::cin;using std::cout;using std::endl;...原创 2019-02-03 12:18:45 · 115 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter16 - 1
#include&lt;iostream&gt;#include&lt;string&gt;using std::string;using std::cin;using std::cout;using std::endl;void FillString(string&amp; str);bool equal(string&amp; str);int main(){ s...原创 2019-02-02 13:53:01 · 117 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter17 - 6
未将对象作为整体写入和读出,此种方式待再写一版。本次是将对象中的信息拆分写入文件,再以读取每个字符的方式读取出所有文件内容。emp.h#ifndef EMP_H_#define EMP_H_// emp.h -- header file for abstr_emp class and children#include <iostream>#include <str...原创 2019-02-27 17:50:47 · 177 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter16 - 10
main.cpp这次是尽量往复杂了写,想检验自己对于函数的多重调用、STL容器操作方法、以及函数指针、稍复杂的容器类型表达等方面的掌握情况,从而帮助自己更熟练使用。所以很多代码和注释会显得啰嗦和没有必要,但对于当前的自己,这样的练习还是必要的。稍后写一个简版的。夜已深,先睡觉了。// has simple codes,here only want to practice more tech...原创 2019-02-13 01:15:03 · 147 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter18 - 1
#include<iostream>#include<initializer_list>#include<algorithm>using namespace std;// create a template function, which will add all elements together// initializer_list is co...原创 2019-03-12 20:14:33 · 118 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter18 - 4
// functor.cpp -- using class object as functor. object has name, and temporary object without name#include <iostream>#include <list>#include <iterator>#include <algorithm>...原创 2019-03-15 15:23:32 · 116 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter18 - 3
// APPROACH 1: use rvalue as parameter#include<iostream>#include<cmath>long double sum_values() { return 0; };// 0 parameter,deal with border situationtemplate<typename T, typenam...原创 2019-03-15 08:39:18 · 305 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter17 - 5
#include<iostream>#include<fstream>#include<string>#include<set>#include<iterator>int main(){ using namespace std; const char* filename[3] = { "mat.dat",".原创 2019-02-26 15:33:46 · 104 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter17 - 4
// copy from 2 files to 1 file// Approach 3: fin connect to 2 files, fout connect to 1 file#include&lt;iostream&gt;#include&lt;fstream&gt;#include&lt;string&gt;int main(){ using namespace s...原创 2019-02-26 12:42:36 · 153 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter17 - 3
#include&amp;lt;iostream&amp;gt;#include&amp;lt;fstream&amp;gt;int main(int argc,char*argv[3])// 2 files{ using namespace std; if (argc == 1 || argc == 2) // quit if no arguments,or only 1 file { ...原创 2019-02-25 17:48:44 · 143 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter17 - 7
#include<iostream>#include<fstream>// fout#include<vector>#include<string>#include<algorithm>// for_each()using namespace std;// write to file. use ifstream to inp...原创 2019-03-01 11:43:34 · 220 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter17 - 2
这个没有经过测试。#include<iostream>#include<fstream>#include<string>int main(int argc, char* argv[4])// suppose need to fill 3 files,argv[0] is command name{ using namespace std;...原创 2019-02-25 14:04:03 · 267 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter17 - 1
想到3种实现方法// APPROACH 1:peek()#include<iostream>#include<sstream>int main(){ using namespace std; istringstream s1("Hello world!$"); string str = s1.str(); cout << "Here is a...原创 2019-02-25 12:52:06 · 118 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter15 - 4
sales.h// sales.h -- exceptions and inheritance#ifndef SALES_H_#define SALES_H_#include &lt;stdexcept&gt;#include &lt;string&gt;class Sales{public: enum { MONTHS = 12 }; // could be a sta...原创 2019-01-18 23:04:38 · 284 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter15 - 3
error.h#ifndef ERROR_H_#define ERROR_H_#include<stdexcept>#include <iostream>using std::cout;using std::endl;class son_logic: public std::logic_error{private: double v1; ...原创 2019-01-18 19:03:26 · 104 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter12 - 4
stack.h// stack.h -- class definition for the stack ADT#ifndef STACK_H_#define STACK_H_typedef unsigned long Item;class Stack{private: enum { MAX = 10 }; // constant specific to class I...原创 2018-11-26 16:27:00 · 102 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter12 -2
string2.h// string1.h -- fixed and augmented string class definition#ifndef STRING1_H_#define STRING1_H_#include &amp;lt;iostream&amp;gt;#include&amp;lt;cctype&amp;gt;using std::ostream;using std::istream;原创 2018-11-25 12:51:39 · 116 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter12 - 1
Cow.h#ifndef COW_H_#define COW_H_class Cow{ char name[20]; char * hobby; double weight;public: Cow(); Cow(const char * nm, const char * ho, double wt); Cow(const Cow&...原创 2018-11-23 13:35:33 · 173 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter12 - 3
stock20.h// stock20.h -- augmented version#ifndef STOCK20_H_#define STOCK20_H_#include <string>#include<iostream>class Stock{private: char* str; int shares; double sha...原创 2018-11-25 21:36:17 · 129 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter11 - 7
complex0.h#ifndef COMPLEX0_H_#define COMPLEX0_H_class Complex0{private: double real; double imag;public: Complex0() { real = imag = 0.0; };// default constructor ...原创 2018-11-13 15:30:09 · 173 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter11 - 6
为方便起见:需要用友元重载<<;未考虑用户非法输入的情况;既然是bool值,用法肯定是用于条件判断,可以是if或for/while中expression部分。Stonewt.h// stonewt.h -- definition for the Stonewt class#ifndef STONEWT_H_#define STONEWT_H_class Stone...原创 2018-11-13 13:01:37 · 186 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter11 - 5
这道题里,用switch和while配合时,着实花了不少时间,还是使用不熟练所致。排除非法输入(非int)和非1、2、3的用法,尽量做到精简。实现1个需求的方法有无数种,代码也有无数种,但尽量用注释记录自己当时的思路,回头看的时候可以找到不完善的地方进一步修改和调整。stonewt.h// stonewt.h -- definition for the Stonewt class#ifn...原创 2018-11-13 11:44:37 · 626 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter11 - 4
All alteredmytime3.h// mytime3.h -- Time class with friends#ifndef MYTIME3_H_#define MYTIME3_H_#include &lt;iostream&gt;class Time{private: int hours; int minutes;public: Time();...原创 2018-11-10 16:50:18 · 210 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter11 - 3
Omit vech.h and vech.cpprandwalk.cpp (altered)// randwalk.cpp -- using the Vector class// compile with the vect.cpp file#include &amp;amp;amp;lt;iostream&amp;amp;amp;gt;#include &amp;amp;amp;lt;cstdlib&amp;amp;amp;原创 2018-11-10 14:13:06 · 109 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter12 -5&6
总等待时间 VS 总顾客人数:来的顾客人多,每个人都会产生等待时间,总等待时间自然也会多,不会随着ATM数量的增加而减少(ATM空闲情况除外)总服务人数 VS 总顾客人数:ATM增多,能同时服务的顾客人数自然更多,所以这是一个效率概念,是会有明显提升的需要创建2个队列用于存储新来的顾客,但总等待时间,总服务人数,总拒绝人数都不需要单独计算。但两台ATM的当前处理时间需要单独创建,因为需要分别...原创 2018-11-27 14:10:31 · 120 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter13 - 1&2
classic.hNote:In base class, even if not explicitly defined copy constructor and overloaded op=, derived class still is able to revolk defaut ones. (condition: no dynamic memory used in base class)...原创 2018-12-05 16:07:43 · 243 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter15 - 2
error.h#ifndef ERROR_H_#define ERROR_H_#include<stdexcept>#include <iostream>class bad_hmean:public std::logic_error{private: double v1; double v2;public: bad_hmean(do...原创 2019-01-18 18:16:40 · 150 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter15 - 1
几点说明:使用friend class Remote; 就起到了Remote的前向声明的作用,不用在Tv声明前单加class Remote;仅有friend class Remote; 编译器仅知道Remote是一个类名,但类内的成员(数据成员或函数)如果出现,编译器仍然不知道如何处理结合第2条,Tv中出现的访问Remote私有成员的Tv的成员函数,必须在Remote类定义完成后再单独添加...原创 2019-01-18 16:28:42 · 150 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter14 - 4
有些在本例中不会用到的功能,如class Card中的函数,也尽可能详细的写上了,既然是为了练习,索性就一起练了吧。尽管会显得臃肿。犯了好几个错误,能发现的都改过来了。这个回头还是需要重新写一下,一是做到精简,二是看同样的错误还会不会再犯。person.h#ifndef PERSON_H_#define PERSON_H_#include<iostream>#includ...原创 2019-01-02 20:47:25 · 150 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter14 - 3
其实可以在类模板QueueTP中创建1个show(),通过循环连续返回queue中每个节点中存储的Worker*,但怎么将这个指针与相应的类成员函数(如Singer的show() )联系起来用,我还没有想到好办法。想到在QueueTP用函数指针,比如show(*pf),然后pf可以使用相应派生类的成员函数show(),但没有实现。后面再回过头来想想吧。最终只能仍然是用Worker指针数组去完成...原创 2019-01-01 21:17:04 · 101 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter14 - 2
wine.h#ifndef WINE_H_#define WINE_H_#include<string>#include<valarray>// delclarations and implementaions of Pairtemplate <class T1, class T2>class Pair{private: T1 a; ...原创 2018-12-30 18:14:08 · 161 阅读 · 0 评论 -
C++ Premier Plus 6th edition - Programming excercise - Chapter14 - 1
wine.h#ifndef WINE_H_#define WINE_H_#include<string>#include<valarray>// delclarations and implementaions of Pairtemplate <class T1, class T2>class Pair{private: T1 a; ...原创 2018-12-30 15:59:31 · 420 阅读 · 0 评论