C++Primer第五版——习题答案详解(六)
习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html
第7章 类
练习7.1
class Sales_data {
public:
std::string isbn() const { return bookNo; }
Sales_data& combine(const Sales_data&);
private:
std::string bookNo;
unsigned units_sold;
double revenue;
};
Sales_data& Sales_data::combine(const Sales_data &rhs) {
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
}
练习7.4
class Person {
private:
std::string name;
std::string address;
};
练习7.5
class Person {
public:
std::string getName() const { return this->name; }
std::string getAddress() const { return this->address; }
private:
std::string name;
std::string address;
};
练习7.6
#include<iostream>
#include<string>
using namespace std;
class Sales_data {
public:
Sales_data(std::string bN, unsigned sold, double reven) :bookNo(bN), units_sold(sold), revenue(reven) {}
std::string isbn() const { return this->bookNo; }
Sales_data& combine(const Sales_data&);
double avg_price() const;
public:
std::string bookNo;
unsigned units_sold;
double revenue;
};
Sales_data& Sales_data::combine(const Sales_data &rhs) {
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
}
double Sales_data::avg_price() const {
if (units_sold) {
return revenue / units_sold;
}
else return 0;
}
istream &read(istream &is, Sales_data &item) {
double price = 0;
is >> item.bookNo >> item.units_sold >> price;
item.revenue = item.units_sold * price;
return is;
}
ostream &print(ostream &os, const Sales_data &item) {
os << item.isbn() << " " << item.units_sold << " " << item.revenue << " " << item.avg_price();
return os;
}
Sales_data add(const Sales_data &lhs, const Sales_data &rhs) {
Sales_data sum = lhs;
sum.combine(rhs);
return sum;
}
int main() {
return 0;
}
练习7.7
#include<iostream>
#include<string>
using namespace std;
class Sales_data {
public:
Sales_data(){}
Sales_data(std::string bN, unsigned sold, double reven) :bookNo(bN), units_sold(sold), revenue(reven) {}
std::string isbn() const { return this->bookNo; }
Sales_data& combine(const Sales_data&);
double avg_price() const;
public:
std::string bookNo;
unsigned units_sold;
double revenue;
};
Sales_data& Sales_data::combine(const Sales_data &rhs) {
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
}
double Sales_data::avg_price() const {
if (units_sold) {
return revenue / units_sold;
}
else return 0;
}
istream &read(istream &is, Sales_data &item) {
double price = 0;
is >> item.bookNo >> item.units_sold >> price;
item.revenue = item.units_sold * price;
return is;
}
ostream &print(ostream &os, const Sales_data &item) {
os << item.isbn() << " " << item.units_sold << " " << item.revenue << " " << item.avg_price();
return os;
}
Sales_data add(const Sales_data &lhs, const Sales_data &rhs) {
Sales_data sum = lhs;
sum.combine(rhs);
return sum;
}
int main() {
Sales_data total;
if (read(cin, total)) {
Sales_data trans;
while (read(cin, trans)) {
if (total.isbn() == trans.isbn()) {
total.combine(trans);
}
else {
print(cout, total);
cout << endl;
total = trans;
}
}
print(cout, total);
cout << endl;
return 0;
}
else {
cerr << "No data?" << endl;
return -1;
}
}
练习7.8
read需要改变参数,print不需要改变
练习7.9
#include<iostream>
#include<string>
class Sales_data {
public:
std::string isbn() const { return bookNo; }
Sales_data& combine(const Sales_data&);
private:
std::string bookNo;
unsigned units_sold;
double revenue;
};
Sales_data& Sales_data::combine(const Sales_data &rhs) {
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
}
class Person {
public:
std::string getName() const { return this->name; }
std::string getAddress() const { return this->address; }
std::ostream &print(std::ostream&, const Person&);
std::istream &read(std::istream&, Person&);
public:
std::string name;
std::string address;
};
std::ostream &print(std::ostream &os, const Person &p) {
os << p.getName() << " " << p.getAddress();
return os;
}
std::istream &read(std::istream &is, Person &p) {
is >> p.name >> p.address;
return is;
}
int main() {
return 0;
}
练习7.10
是否成功读入data1,data2
练习7.11
#include<iostream>
#include<string>
using namespace std;
class Sales_data {
public:
Sales_data() = default;
Sales_data(const std::string bN) :bookNo(bN), units_sold(0), revenue(0) {}
Sales_data(const std::string bN, unsigned sold) :bookNo(bN), units_sold(sold), revenue(0) {}
Sales_data(const std::string bN, unsigned sold, double reven) :bookNo(bN), units_sold(sold), revenue(reven) {}
std::string isbn() const { return bookNo; }
unsigned getUnits_sold() const { return units_sold; }
double getRevenue() const{ return revenue; }
Sales_data& combine(const Sales_data&);
private:
std::string bookNo;
unsigned units_sold;
double revenue;
};
Sales_data& Sales_data::combine(const Sales_data &rhs) {
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
}
int main() {
Sales_data A;
Sales_data B("0-1-33333-2");
Sales_data C("0-1-33333-3", 1);
Sales_data D("0-1-33334-3", 1,50);
cout << A.isbn() << ", " << A.getUnits_sold() << ", " << A.getRevenue() << endl;
cout << B.isbn() << ", " << B.getUnits_sold() << ", " << B.getRevenue() << endl;
cout << C.isbn() << ", " << C.getUnits_sold() << ", " << C.getRevenue() << endl;
cout << D.isbn() << ", " << D.getUnits_sold() << ", " << D.getRevenue() << endl;
system("pause");
return 0;
}
练习7.12
#include<iostream>
#include<string>
using namespace std;
class Sales_data;
std::istream &read(std::istream &, Sales_data &);
class Sales_data {
public:
Sales_data() = default;
Sales_data(const std::string bN) :bookNo(bN), units_sold(0), revenue(0) {}
Sales_data(const std::string bN, unsigned sold) :bookNo(bN), units_sold(sold), revenue(0) {}
Sales_data(const std::string bN, unsigned sold, double price) :bookNo(bN), units_sold(sold), revenue(price * sold) {}
std::string isbn() const { return bookNo; }
unsigned getUnits_sold() const { return units_sold; }
double getRevenue() const { return revenue; }
double avg_price() const;
Sales_data& combine(const Sales_data &);
Sales_data(std::istream &is) { read(is, *this); }
public:
std::string bookNo;
unsigned units_sold;
double revenue;
};
Sales_data&::Sales_data::combine(const Sales_data &rhs) {
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
}
double Sales_data::avg_price() const {
if (units_sold) {
return revenue / units_sold;
}
else {
return 0;
}
}
std::istream &read(std::istream &is, Sales_data &item) {
double price = 0;
is >> item.bookNo >> item.units_sold >> price;
item.revenue = price * item.units_sold;
return is;
}
int main() {
return 0;
}
练习7.13
#include<iostream>
#include<string>
using namespace std;
class Sales_data;
std::istream &read(std::istream &, Sales_data &);
std::ostream &print(std::ostream &os, const Sales_data &item);
Sales_data add(const Sales_data &lhs, const Sales_data &rhs);
class Sales_data {
public:
Sales_data() = default;
Sales_data(const std::string bN) :bookNo(bN), units_sold(0), revenue(0) {}
Sales_data(const std::string bN, unsigned sold) :bookNo(bN), units_sold(sold), revenue(0) {}
Sales_data(const std::string bN, unsigned sold, double price) :bookNo(bN), units_sold(sold), revenue(price * sold) {}
std::string isbn() const { return bookNo; }
unsigned getUnits_sold() const { return units_sold; }
double getRevenue() const { return revenue; }
double avg_price() const;
Sales_data& combine(const Sales_data &);
Sales_data(std::istream &is) { read(is, *this); }
public:
std::string bookNo;
unsigned units_sold;
double revenue;
};
Sales_data&::Sales_data::combine(const Sales_data &rhs) {
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
}
double Sales_data::avg_price() const {
if (units_sold) {
return revenue / units_sold;
}
else {
return 0;
}
}
std::istream &read(std::istream &is, Sales_data &item) {
double price = 0;
is >> item.bookNo >> item.units_sold >> price;
item.revenue = price * item.units_sold;
return is;
}
std::ostream &print(std::ostream &os, const Sales_data &item)
{
os << item.isbn() << " " << item.units_sold << " " << item.revenue << " " << item.avg_price();
return os;
}
Sales_data add(const Sales_data &lhs, const Sales_data &rhs)
{
Sales_data sum = lhs;
sum.combine(rhs);
return sum;
}
int main() {
Sales_data sales_data1;
print(std::cout, sales_data1) << endl;
Sales_data sales_data2("1-01");
print(std::cout, sales_data2) << std::endl;
Sales_data sales_data3("1-01", 1, 100);
print(std::cout, sales_data3) << std::endl;
Sales_data sales_data4(std::cin);
print(std::cout, sales_data4) << std::endl;
system("pause");
return 0;
}
练习7.14
Sales_data() : bookNo(""), units_sold(0) , revenue(0){ }
练习7.15
class Person {
public:
Person() = default;
Person(const std::string nm, const std::string ad) :name(nm), address(ad) {}
std::string getName() const { return this->name; }
std::string getAddress() const { return this->address; }
std::ostream &print(std::ostream&, const Person&);
std::ostream &read(std::istream&, Person&);
public:
std::string name;
std::string address;
};
练习7.16
访问位置有限定,次数没有限定。
public后的成员可以被整个程序内访问,而private只能被类的成员函数访问。
练习7.17
有,struct内的变量访问权限是public,而class的访问权限可以是private、public、protected
练习7.18
封装,即隐藏对象的属性和实现细节,仅对外公开接口,控制在程序中属性的读和修改的访问级别。
练习7.21
#include<iostream>
#include<string>
using namespace std;
class Sales_data {
public:
friend std::istream &read(std::istream &, Sales_data &);
friend std::ostream &print(std::ostream &os, const Sales_data &item);
friend Sales_data add(const Sales_data &lhs, const Sales_data &rhs);
Sales_data() = default;
Sales_data(const std::string bN) :bookNo(bN), units_sold(0), revenue(0) {}
Sales_data(const std::string bN, unsigned sold) :bookNo(bN), units_sold(sold), revenue(0) {}
Sales_data(const std::string bN, unsigned sold, double price) :bookNo(bN), units_sold(sold), revenue(price * sold) {}
std::string isbn() const { return bookNo; }
unsigned getUnits_sold() const { return units_sold; }
double getRevenue() const { return revenue; }
double avg_price() const;
Sales_data& combine(const Sales_data &);
Sales_data(std::istream &is) { read(is, *this); }
private:
std::string bookNo;
unsigned units_sold;
double revenue;
};
Sales_data&::Sales_data::combine(const Sales_data &rhs) {
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
}
double Sales_data::avg_price() const {
return units_sold > 0 ? revenue / units_sold : 0;
}
std::istream &read(std::istream &is, Sales_data &item) {
double price = 0;
is >> item.bookNo >> item.units_sold >> price;
item.revenue = price * item.units_sold;
return is;
}
std::ostream &print(std::ostream &os, const Sales_data &item)
{
os << item.isbn() << " " << item.units_sold << " " << item.revenue << " " << item.avg_price();
return os;
}
Sales_data add(const Sales_data &lhs, const Sales_data &rhs)
{
Sales_data sum = lhs;
sum.combine(rhs);
return sum;
}
int main() {
Sales_data sales_data1;
print(std::cout, sales_data1) << endl;
Sales_data sales_data2("1-01");
print(std::cout, sales_data2) << std::endl;
Sales_data sales_data3("1-01", 1, 100);
print(std::cout, sales_data3) << std::endl;
Sales_data sales_data4(std::cin);
print(std::cout, sales_data4) << std::endl;
system("pause");
return 0;
}
练习7.22
class Person {
public:
Person() = default;
Person(const std::string nm, const std::string ad) :name(nm), address(ad) {}
std::string getName() const { return this->name; }
std::string getAddress() const { return this->address; }
friend std::ostream &print(std::ostream&, const Person&);
friend std::istream &read(std::istream&, Person&);
private:
std::string name;
std::string address;
};
练习7.23-7.24
class Screen {
public:
typedef std::string::size_type pos;
Screen() = default;
Screen(pos ht, pos wd) :height(ht), width(wd) {}
Screen(pos ht, pos wd, char c) :height(ht), width(wd), contents(ht*wd, c) {}
char get() const { return contents[cursor]; }
char get(pos r, pos c) const { return contents[r * width + c]; }
private:
mutable size_t access_ctr;
pos height, width, cursor;
std::string contents;
};
练习7.25
可以,因为Screen类中只有string类和内置类型,他们都可以使用拷贝和赋值操作。
练习7.26
#include<iostream>
#include<string>
using namespace std;
class Sales_data {
public:
friend std::istream &read(std::istream &, Sales_data &);
friend std::ostream &print(std::ostream &os, const Sales_data &item);
friend Sales_data add(const Sales_data &lhs, const Sales_data &rhs);
Sales_data() = default;
Sales_data(const std::string bN) :bookNo(bN), units_sold(0), revenue(0) {}
Sales_data(const std::string bN, unsigned sold) :bookNo(bN), units_sold(sold), revenue(0) {}
Sales_data(const std::string bN, unsigned sold, double price) :bookNo(bN), units_sold(sold), revenue(price * sold) {}
std::string isbn() const { return bookNo; }
unsigned getUnits_sold() const { return units_sold; }
double getRevenue() const { return revenue; }
inline double avg_price() const;
Sales_data& combine(const Sales_data &);
Sales_data(std::istream &is) { read(is, *this); }
private:
std::string bookNo;
unsigned units_sold;
double revenue;
};
Sales_data&::Sales_data::combine(const Sales_data &rhs) {
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
}
inline double Sales_data::avg_price() const {
return units_sold > 0 ? revenue / units_sold : 0;
}
std::istream &read(std::istream &is, Sales_data &item) {
double price = 0;
is >> item.bookNo >> item.units_sold >> price;
item.revenue = price * item.units_sold;
return is;
}
std::ostream &print(std::ostream &os, const Sales_data &item)
{
os << item.isbn() << " " << item.units_sold << " " << item.revenue << " " << item.avg_price();
return os;
}
Sales_data add(const Sales_data &lhs, const Sales_data &rhs)
{
Sales_data sum = lhs;
sum.combine(rhs);
return sum;
}
int main() {
Sales_data sales_data1;
print(std::cout, sales_data1) << endl;
Sales_data sales_data2("1-01");
print(std::cout, sales_data2) << std::endl;
Sales_data sales_data3("1-01", 1, 100);
print(std::cout, sales_data3) << std::endl;
Sales_data sales_data4(std::cin);
print(std::cout, sales_data4) << std::endl;
system("pause");
return 0;
}
练习7.27
#include<iostream>
#include<string>
using namespace std;
class Screen {
public:
typedef std::string::size_type pos;
Screen() = default;
Screen(pos ht, pos wd) :height(ht), width(wd) {}
Screen(pos ht, pos wd, char c) :height(ht), width(wd), contents(ht*wd, c) {}
Screen &set(char);
Screen &set(pos, pos, char);
Screen &move(pos, pos);
char get() const { return contents[cursor]; }
char get(pos r, pos c) const { return contents[r * width + c]; }
Screen &display(std::ostream &os)
{
do_display(os);
return *this;
}
const Screen &display(std::ostream &os) const
{
do_display(os);
return *this;
}
void do_display(std::ostream &os) const { os << contents; }
private:
mutable size_t access_ctr;
pos height, width, cursor;
std::string contents;
};
inline Screen &Screen::set(char c) {
contents[cursor] = c;
return *this;
}
inline Screen &Screen::set(pos r, pos c, char ch) {
contents[r*width + c] = ch;
return *this;
}
inline Screen &Screen::move(pos r, pos c) {
cursor = r * width + c;
return *this;
}
int main() {
Screen myScreen(5, 5, 'X');
myScreen.display(cout);
cout << endl;
myScreen.move(4, 0).set('#').display(cout);
cout << endl;
myScreen.display(cout);
cout << endl;
system("pause");
return 0;
}
练习7.28-7.29
如果是Screen则不会修改字符。
练习7.31
class Y;
class X {
Y *y = nullptr;
};
class Y {
X x;
};
练习7.32
class Screen;
class Window_mgr {
public:
using ScreenIndex = std::vector<Screen>::size_type;
void clear(ScreenIndex);
private:
std::vector<Screen> screens;
};
class Screen {
friend void Window_mgr::clear(ScreenIndex);
public:
typedef std::string::size_type pos;
Screen() = default;
Screen(pos ht, pos wd) :height(ht), width(wd) {}
Screen(pos ht, pos wd, char c) :height(ht), width(wd), contents(ht*wd, c) {}
Screen &set(char);
Screen &set(pos, pos, char);
Screen &move(pos, pos);
char get() const { return contents[cursor]; }
char get(pos r, pos c) const { return contents[r * width + c]; }
Screen &display(std::ostream &os)
{
do_display(os);
return *this;
}
const Screen &display(std::ostream &os) const
{
do_display(os);
return *this;
}
void do_display(std::ostream &os) const { os << contents; }
private:
mutable size_t access_ctr;
pos height, width, cursor;
std::string contents;
};
练习7.34
报错,pos未声明
练习7.35
typedef string Type;
Type initVal(); // string
class Exercise {
public:
typedef double Type;
Type setVal(Type); // double
Type initVal(); // double
private:
int val;
};
Type Exercise::setVal(Type parm) { // first is `string`, second is `double`
val = parm + initVal();
return val;
}
练习7.36
成员的初始化顺序与他们在类定义中的出现顺序一致,所以先初始化rem再是base,所以结果不正确。
将类内定义顺序改成:
int base, rem;
练习7.37
Sales_data first_item(cin); // Sales_data(std::istream &is) ;
int main() {
Sales_data next; // Sales_data(std::string s = ""): bookNo = "", cnt = 0, revenue = 0.0
Sales_data last("9-999-99999-9"); // Sales_data(std::string s = ""): bookNo = "9-999-99999-9", cnt = 0, revenue = 0.0
}
练习7.38
Sales_data(std::istream &is = std::cin) { read(is, *this); }
练习7.41
#include <string>
#include <iostream>
using namespace std;
struct Sales_data;
std::istream &read(std::istream &is, Sales_data &item);
std::ostream &print(std::ostream &os, const Sales_data &item);
Sales_data add(const Sales_data &lhs, const Sales_data &rhs);
struct Sales_data
{
friend std::istream &read(std::istream &is, Sales_data &item);
friend std::ostream &print(std::ostream &os, const Sales_data &item);
friend Sales_data add(const Sales_data &lhs, const Sales_data &rhs);
public:
Sales_data(const std::string &s, unsigned n, double p) : bookNo(s), units_sold(n), revenue(p*n)
{
std::cout << "Sales_data(const std::string &s, unsigned n, double p)" << std::endl;
}
Sales_data() : Sales_data("", 0, 0)
{
std::cout << "Sales_data() : Sales_data(\"\", 0, 0)" << std::endl;
}
Sales_data(const std::string &s) : Sales_data(s, 0, 0)
{
std::cout << "Sales_data(const std::string &s) : Sales_data" << std::endl;
}
Sales_data(std::istream &is) : Sales_data()
{
read(is, *this);
std::cout << "Sales_data(std::istream &is) : Sales_data()" << std::endl;
}
std::string isbn() const { return bookNo; }
Sales_data& combine(const Sales_data&);
private:
inline double avg_price() const;
std::string bookNo;
unsigned units_sold = 0;
double revenue = 0.0;
};
Sales_data& Sales_data::combine(const Sales_data &rhs)
{
units_sold += rhs.units_sold;
revenue += rhs.revenue;
return *this;
}
inline double Sales_data::avg_price() const
{
if (units_sold)
return revenue / units_sold;
else
return 0;
}
std::istream &read(std::istream &is, Sales_data &item)
{
double price = 0;
is >> item.bookNo >> item.units_sold >> price;
item.revenue = price * item.units_sold;
return is;
}
std::ostream &print(std::ostream &os, const Sales_data &item)
{
os << item.isbn() << " " << item.units_sold << " " << item.revenue << " " << item.avg_price();
return os;
}
Sales_data add(const Sales_data &lhs, const Sales_data &rhs)
{
Sales_data sum = lhs;
sum.combine(rhs);
return sum;
}
int main() {
Sales_data a("0-1-999-9", 2, 10);
cout << endl;
Sales_data b;
cout << endl;
Sales_data c("0-1-999-9");
cout << endl;
Sales_data d(cin);
system("pause");
return 0;
}
练习7.43
class NoDefault {
public:
NoDefault(int i) {}
};
class C {
public:
C() :no(0) {}
private:
NoDefault no;
};
练习7.44
非法,NoDefault没有定义默认构造函数
练习7.45
合法,C有默认构造函数
练习7.48
都没问题,因为都是显式构造了Sales_data对象
练习7.50
explicit Person(std::istream &is) { read(is, *this); }
练习7.52
该初始化是用花括号括起来的成员初始值列表,需要定义聚合类。
struct Sales_data {
std::string isbn;
unsigned units_sold;
double revenue;
};
练习7.53
class Debug
{
public:
constexpr Debug(bool b = true) : hw(b), io(b), other(b) {}
constexpr Debug(bool h, bool i, bool o) : hw(h), io(i), other(o) {}
constexpr bool amy() { return hw || io || other; }
void set_io(bool b) { io = b; }
void set_hw(bool b) { hw = b; }
void set_other(bool b) { other = b; }
private:
bool hw;
bool io;
bool other;
};
练习7.56
类的静态成员与类本身直接相关,而不是与类的各个对象保持关联。
每个对象不需要存储公共数据,如果数据被改变,则每个对象都可以使用新值。
静态数据成员可以是不完全类型; 可以使用静态成员作为默认实参。
练习7.57
#include<iostream>
#include<string>
using namespace std;
//全局变量 利率
//double interestRate;
class Account {
public:
Account(std::string name, double money) :owner(name), amount(money) {}
double getAmount() const {
return this->amount;
}
void deposit(double money) {
this->amount += money;
}
double rate() { return interestRate; }
static void rate(double newRate){ //静态的成员函数不属于任何一个对象,所以this不能用,this指的是当前对象。
interestRate = newRate;
}
void applyint() { amount += amount * interestRate; }
private:
std::string owner;
double amount;
static double interestRate; //只有一个,不能在这初始化
static const int period = 30; //例外
};
double Account::interestRate = 0.015;
int main() {
//interestRate = 0.015;
Account::rate(0.026); //函数加static以后可以用这种方法修改static变量
Account a("张三", 1000);
Account b("李四", 2000);
cout << a.rate() << endl;
a.deposit(500);
b.deposit(600);
cout << a.getAmount() << endl;
cout << b.getAmount() << endl;
cout << a.rate() << endl;
a.rate(0.08);
cout << a.rate() << endl;
cout << b.rate() << endl;
Account::rate(0.02);
a.applyint();
b.applyint();
cout << a.getAmount() << endl;
cout << b.getAmount() << endl;
system("pause");
return 0;
}
练习7.58
// example.h
class Example {
public:
static double rate; //不能直接初始化
static const int vecSize = 20;
static vector<double> vec;
};
// example.C
#include "example.h"
double Example::rate = 6.5;
vector<double> Example::vec(Example::vecSize);
C++Primer第五版——习题答案详解(六)的更多相关文章
- C++Primer第五版——习题答案详解(一)
习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第1章 开始&&第2章 变量和基本类型 练习1.3 #include&l ...
- C++Primer第五版——习题答案详解(二)
习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第3章 字符串.向量和数组 练习3.2 一次读入一整行 #include<iost ...
- C++Primer第五版——习题答案详解(三)
习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第4章 表达式 练习4.10 while(cin>>i&&i ...
- C++Primer第五版——习题答案详解(四)
习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第5章 语句 练习5.9 #include<iostream> #inclu ...
- C++Primer第五版——习题答案详解(五)
习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第6章 函数 练习6.4 #include<iostream> using ...
- C++Primer第五版——习题答案详解(七)
习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第8章 IO库 练习8.1 istream &iofunc(istream &a ...
- C++Primer第五版——习题答案详解(八)
习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第9章 顺序容器 练习9.1 a.list,需要按字典序插入,可能插入位置在中间 b.d ...
- C++Primer第五版——习题答案详解(九)
习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第10章 泛型算法 练习10.1 #include<iostream> #i ...
- C++Primer第五版——习题答案详解(十)
习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第11章 关联容器 练习11.3 #include<iostream> #i ...
随机推荐
- PHP有关守护进程,以及流程控制和信号处理函数
守护进程(Daemon)是运行在后台的一种特殊进程.它独立于控制终端并且周期性地执行某种任务或等待处理某些发生的事件.守护进程是一种很有用的进程.PHP也可以实现守护进程的功能. 1.基本概念 进程 ...
- go web framework gin 启动流程分析
最主要的package : gin 最主要的struct: Engine Engine 是整个framework的实例,它包含了muxer, middleware, configuration set ...
- ui自动化:python+appium----环境搭建
前言: appium可以说是app最火的一个自动化框架,它的主要优势是支持android和ios,另外脚本支持java和python.以下为python+appium的安装教程... 环境准备... ...
- 剑指Offer 4. 重建二叉树 (二叉树)
题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7, ...
- 2--Postman脚本介绍
Postman是访问各种API的客户端.它的强大之处在于其允许在对某一个request访问的之前和之后分别运行自定义的一段Javascript脚本,可以将数条request连结成一个流程完成一体化测试 ...
- 环境搭建、RF库
一.Python27安装 1.双击安装python-2.7.13-64位.msi 2.检查python:cmd命令行→[python]→回车,出现如图所示,表示成功 可能出现:'python'不是内部 ...
- Python函数定义、文件操作(读写、修改)
date:2018421 day3 一.函数定义 def 函数名(首字母大写) 增加程序可读性 #直接写函数名即可调用函数 #参数 ①.形参 ②.实参 ③.缺省参数 如果有默认值,调用的时候没有传递 ...
- 第一篇,java学习之旅
在java的这座殿堂中,我才刚刚推开了大门,就像是在岔路口找到了一条,走向前进java大门的路. 下面是一些java算法的问题 第一题: package project.model; import j ...
- 重启HA集群NameNode无缘无故挂掉
重启HA集群后,两个NameNode无缘无故挂掉,查看日志时显示错误如下: 原因:journalnode的端口是8485,默认情况下是先NameNode启动后再启动journalnode,如果在Nam ...
- angular.copy(source, destination)
angular.copy(source, destination)只有1个参数,返回source的深拷贝有2个参数source的深拷贝复制给destination