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 ...
随机推荐
- MongoDB 教程(八):查询文档、条件操作符
MongoDB 查询文档 MongoDB 查询文档使用 find() 方法. find() 方法以非结构化的方式来显示所有文档. MongoDB 查询数据的语法格式如下: db.collection. ...
- 如何破解MyEclipse 10.x
本文以MyEclipse Professional 10.6 为例来介绍如何破解MyEclipse 10.x. 本文使用的破解补丁对MyEclipse Standard/ Professional/ ...
- python项目运行环境安装小结
安装最新即可,实际的版本号可能不一样 安装过程较复杂,建议用一台单独的vm安装,能做成docker image最好 基础软件 nginx-1.10.0: sudo apt-get install ng ...
- php解析Excel表格并且导入MySQL数据库
最近根据客户需求,需要增加一个导入Excel表格的功能,Excel中存放的是知识库中医知识的分类体系目录.是在thinkphp框架下编写的代码,用的是phpexcel第三方包.测试环境用的是xampp ...
- JAVA 程序的基本语法
首先看我们的第一个java程序: public class HelloWorld { public static void main(String[] args) { System.out.print ...
- windows环境搭建Vue开发环境
一.安装node.js(https://nodejs.org/en/) 下载完毕后,可以安装node,建议不要安装在系统盘(如C:). 二.设置nodejs prefix(全局)和cache(缓存)路 ...
- [Java] [Lock] [Synchronized VS ReentrantLock]
Overview java编写多线程程序时,为了保证线程安全,需要对数据进行同步,经常用到的两种同步方式就是synchronized和重入锁ReentrantLock. 相似点 都是加锁方式 都是阻塞 ...
- ChinaCock界面控件介绍-TCCBarcodeCreator
条码生成器,可以生成各种条码,包括二维码.这是一个不可视控件.用起来依旧简单. 属性说明: BarCodeColor:生成条码的颜色 BarcodeFormat:生成条码的类型,支持的条码类型: Bo ...
- WCF分布式服务2-服务配置部署
上图整理了服务配置过程中所用到的基本的元素,大致的步骤: 1. 主要是首先要在调用服务的程序集中添加服务的一个引用. 2. 然后添加一个service并指定服务的名称.终结点. 在添加一个servi ...
- pip3 install mysqlclient 报错 “/bin/sh: 1: mysql_config: not found”的解决方法
执行 sudo apt-get install libmysqlclient-dev, 然后执行 pip3 install mysqlclient 成功.