Skip to content

Commit a062b80

Browse files
committed
chapter 1
0 parents  commit a062b80

37 files changed

+617
-0
lines changed

Demo/.vs/Demo/v14/.suo

30 KB
Binary file not shown.

Demo/Debug/Demo.Build.CppClean.log

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
d:\c++ files\demo\debug\vc140.pdb
2+
d:\c++ files\demo\debug\vc140.idb
3+
d:\c++ files\demo\debug\demo.obj
4+
d:\c++ files\demo\debug\character.obj
5+
d:\c++ files\demo\debug\demo.pdb
6+
d:\c++ files\demo\debug\demo.tlog\cl.command.1.tlog
7+
d:\c++ files\demo\debug\demo.tlog\cl.read.1.tlog
8+
d:\c++ files\demo\debug\demo.tlog\cl.write.1.tlog
9+
d:\c++ files\demo\debug\demo.tlog\link-cvtres.read.1.tlog
10+
d:\c++ files\demo\debug\demo.tlog\link-cvtres.write.1.tlog
11+
d:\c++ files\demo\debug\demo.tlog\link-rc.read.1.tlog
12+
d:\c++ files\demo\debug\demo.tlog\link-rc.write.1.tlog
13+
d:\c++ files\demo\debug\demo.tlog\link.8152-cvtres.read.1.tlog
14+
d:\c++ files\demo\debug\demo.tlog\link.8152-cvtres.write.1.tlog
15+
d:\c++ files\demo\debug\demo.tlog\link.8152-rc.read.1.tlog
16+
d:\c++ files\demo\debug\demo.tlog\link.8152-rc.write.1.tlog
17+
d:\c++ files\demo\debug\demo.tlog\link.8152.read.1.tlog
18+
d:\c++ files\demo\debug\demo.tlog\link.8152.write.1.tlog
19+
d:\c++ files\demo\debug\demo.tlog\link.command.1.tlog
20+
d:\c++ files\demo\debug\demo.tlog\link.read.1.tlog
21+
d:\c++ files\demo\debug\demo.tlog\link.write.1.tlog

Demo/Debug/Demo.exe

98.5 KB
Binary file not shown.

Demo/Debug/Demo.ilk

494 KB
Binary file not shown.

Demo/Debug/Demo.log

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
生成启动时间为 2018/11/18 15:55:53。
2+
1>项目“D:\c++ files\Demo\Demo.vcxproj”在节点 2 上(Build 个目标)。
3+
1>ClCompile:
4+
E:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D _MBCS /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc140.pdb" /Gd /TP /analyze- /errorReport:prompt bookstore.cpp
5+
bookstore.cpp
6+
Link:
7+
E:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"D:\c++ files\Demo\Debug\Demo.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /Debug /PDB:"D:\c++ files\Demo\Debug\Demo.pdb" /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:\c++ files\Demo\Debug\Demo.lib" /MACHINE:X86 Debug\bookstore.obj
8+
Demo.vcxproj -> D:\c++ files\Demo\Debug\Demo.exe
9+
1>已完成生成项目“D:\c++ files\Demo\Demo.vcxproj”(Build 个目标)的操作。
10+
11+
已成功生成。
12+
13+
已用时间 00:00:01.50

Demo/Debug/Demo.pdb

988 KB
Binary file not shown.
3.29 KB
Binary file not shown.

Demo/Debug/Demo.tlog/CL.read.1.tlog

107 KB
Binary file not shown.

Demo/Debug/Demo.tlog/CL.write.1.tlog

1.98 KB
Binary file not shown.
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit
2+
Debug|Win32|D:\c++ files\Demo\|
950 Bytes
Binary file not shown.

Demo/Debug/Demo.tlog/link.read.1.tlog

3.1 KB
Binary file not shown.
286 Bytes
Binary file not shown.

Demo/Debug/appear_times.obj

39.3 KB
Binary file not shown.

Demo/Debug/bookstore.obj

246 KB
Binary file not shown.

Demo/Debug/character.obj

138 KB
Binary file not shown.

Demo/Debug/complex_add.obj

22.7 KB
Binary file not shown.

Demo/Debug/hello_world.obj

36.8 KB
Binary file not shown.

Demo/Debug/io_test.obj

39 KB
Binary file not shown.

Demo/Debug/simple_add.obj

21.5 KB
Binary file not shown.

Demo/Debug/vc140.idb

467 KB
Binary file not shown.

Demo/Debug/vc140.pdb

428 KB
Binary file not shown.

Demo/Demo.sdf

10.1 MB
Binary file not shown.

Demo/Demo.sln

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.23107.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo", "Demo.vcxproj", "{6FBAF84B-EC26-42FD-9AE2-6DE49EEE6D29}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{6FBAF84B-EC26-42FD-9AE2-6DE49EEE6D29}.Debug|x64.ActiveCfg = Debug|x64
17+
{6FBAF84B-EC26-42FD-9AE2-6DE49EEE6D29}.Debug|x64.Build.0 = Debug|x64
18+
{6FBAF84B-EC26-42FD-9AE2-6DE49EEE6D29}.Debug|x86.ActiveCfg = Debug|Win32
19+
{6FBAF84B-EC26-42FD-9AE2-6DE49EEE6D29}.Debug|x86.Build.0 = Debug|Win32
20+
{6FBAF84B-EC26-42FD-9AE2-6DE49EEE6D29}.Release|x64.ActiveCfg = Release|x64
21+
{6FBAF84B-EC26-42FD-9AE2-6DE49EEE6D29}.Release|x64.Build.0 = Release|x64
22+
{6FBAF84B-EC26-42FD-9AE2-6DE49EEE6D29}.Release|x86.ActiveCfg = Release|Win32
23+
{6FBAF84B-EC26-42FD-9AE2-6DE49EEE6D29}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

Demo/Demo.vcxproj

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<ItemGroup>
22+
<ClInclude Include="Sales_item.h" />
23+
</ItemGroup>
24+
<ItemGroup>
25+
<ClCompile Include="bookstore.cpp" />
26+
</ItemGroup>
27+
<PropertyGroup Label="Globals">
28+
<ProjectGuid>{6FBAF84B-EC26-42FD-9AE2-6DE49EEE6D29}</ProjectGuid>
29+
<RootNamespace>Demo</RootNamespace>
30+
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
31+
</PropertyGroup>
32+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
33+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
34+
<ConfigurationType>Application</ConfigurationType>
35+
<UseDebugLibraries>true</UseDebugLibraries>
36+
<PlatformToolset>v140</PlatformToolset>
37+
<CharacterSet>MultiByte</CharacterSet>
38+
</PropertyGroup>
39+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
40+
<ConfigurationType>Application</ConfigurationType>
41+
<UseDebugLibraries>false</UseDebugLibraries>
42+
<PlatformToolset>v140</PlatformToolset>
43+
<WholeProgramOptimization>true</WholeProgramOptimization>
44+
<CharacterSet>MultiByte</CharacterSet>
45+
</PropertyGroup>
46+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
47+
<ConfigurationType>Application</ConfigurationType>
48+
<UseDebugLibraries>true</UseDebugLibraries>
49+
<PlatformToolset>v140</PlatformToolset>
50+
<CharacterSet>MultiByte</CharacterSet>
51+
</PropertyGroup>
52+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
53+
<ConfigurationType>Application</ConfigurationType>
54+
<UseDebugLibraries>false</UseDebugLibraries>
55+
<PlatformToolset>v140</PlatformToolset>
56+
<WholeProgramOptimization>true</WholeProgramOptimization>
57+
<CharacterSet>MultiByte</CharacterSet>
58+
</PropertyGroup>
59+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
60+
<ImportGroup Label="ExtensionSettings">
61+
</ImportGroup>
62+
<ImportGroup Label="Shared">
63+
</ImportGroup>
64+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
65+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
66+
</ImportGroup>
67+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
68+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
69+
</ImportGroup>
70+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
71+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
72+
</ImportGroup>
73+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
74+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
75+
</ImportGroup>
76+
<PropertyGroup Label="UserMacros" />
77+
<PropertyGroup />
78+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
79+
<ClCompile>
80+
<WarningLevel>Level3</WarningLevel>
81+
<Optimization>Disabled</Optimization>
82+
<SDLCheck>true</SDLCheck>
83+
</ClCompile>
84+
<Link>
85+
<GenerateDebugInformation>true</GenerateDebugInformation>
86+
</Link>
87+
</ItemDefinitionGroup>
88+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
89+
<ClCompile>
90+
<WarningLevel>Level3</WarningLevel>
91+
<Optimization>Disabled</Optimization>
92+
<SDLCheck>true</SDLCheck>
93+
</ClCompile>
94+
<Link>
95+
<GenerateDebugInformation>true</GenerateDebugInformation>
96+
</Link>
97+
</ItemDefinitionGroup>
98+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
99+
<ClCompile>
100+
<WarningLevel>Level3</WarningLevel>
101+
<Optimization>MaxSpeed</Optimization>
102+
<FunctionLevelLinking>true</FunctionLevelLinking>
103+
<IntrinsicFunctions>true</IntrinsicFunctions>
104+
<SDLCheck>true</SDLCheck>
105+
</ClCompile>
106+
<Link>
107+
<GenerateDebugInformation>true</GenerateDebugInformation>
108+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
109+
<OptimizeReferences>true</OptimizeReferences>
110+
</Link>
111+
</ItemDefinitionGroup>
112+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
113+
<ClCompile>
114+
<WarningLevel>Level3</WarningLevel>
115+
<Optimization>MaxSpeed</Optimization>
116+
<FunctionLevelLinking>true</FunctionLevelLinking>
117+
<IntrinsicFunctions>true</IntrinsicFunctions>
118+
<SDLCheck>true</SDLCheck>
119+
</ClCompile>
120+
<Link>
121+
<GenerateDebugInformation>true</GenerateDebugInformation>
122+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
123+
<OptimizeReferences>true</OptimizeReferences>
124+
</Link>
125+
</ItemDefinitionGroup>
126+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
127+
<ImportGroup Label="ExtensionTargets">
128+
</ImportGroup>
129+
</Project>

Demo/Demo.vcxproj.filters

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="源文件">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="头文件">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="资源文件">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="Sales_item.h">
19+
<Filter>源文件</Filter>
20+
</ClInclude>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClCompile Include="bookstore.cpp">
24+
<Filter>源文件</Filter>
25+
</ClCompile>
26+
</ItemGroup>
27+
</Project>

Demo/Demo.vcxproj.user

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
4+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
5+
</PropertyGroup>
6+
</Project>

Demo/Sales_item.h

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* This file contains code from "C++ Primer, Fifth Edition", by Stanley B.
3+
* Lippman, Josee Lajoie, and Barbara E. Moo, and is covered under the
4+
* copyright and warranty notices given in that book:
5+
*
6+
* "Copyright (c) 2013 by Objectwrite, Inc., Josee Lajoie, and Barbara E. Moo."
7+
*
8+
*
9+
* "The authors and publisher have taken care in the preparation of this book,
10+
* but make no expressed or implied warranty of any kind and assume no
11+
* responsibility for errors or omissions. No liability is assumed for
12+
* incidental or consequential damages in connection with or arising out of the
13+
* use of the information or programs contained herein."
14+
*
15+
* Permission is granted for this code to be used for educational purposes in
16+
* association with the book, given proper citation if and when posted or
17+
* reproduced.Any commercial use of this code requires the explicit written
18+
* permission of the publisher, Addison-Wesley Professional, a division of
19+
* Pearson Education, Inc. Send your request for permission, stating clearly
20+
* what code you would like to use, and in what specific way, to the following
21+
* address:
22+
*
23+
* Pearson Education, Inc.
24+
* Rights and Permissions Department
25+
* One Lake Street
26+
* Upper Saddle River, NJ 07458
27+
* Fax: (201) 236-3290
28+
*/
29+
30+
/* This file defines the Sales_item class used in chapter 1.
31+
* The code used in this file will be explained in
32+
* Chapter 7 (Classes) and Chapter 14 (Overloaded Operators)
33+
* Readers shouldn't try to understand the code in this file
34+
* until they have read those chapters.
35+
*/
36+
37+
#ifndef SALESITEM_H
38+
// we're here only if SALESITEM_H has not yet been defined
39+
#define SALESITEM_H
40+
41+
#include "Version_test.h"
42+
43+
// Definition of Sales_item class and related functions goes here
44+
#include <iostream>
45+
#include <string>
46+
47+
class Sales_item {
48+
// these declarations are explained section 7.2.1, p. 270
49+
// and in chapter 14, pages 557, 558, 561
50+
friend std::istream& operator>>(std::istream&, Sales_item&);
51+
friend std::ostream& operator<<(std::ostream&, const Sales_item&);
52+
friend bool operator<(const Sales_item&, const Sales_item&);
53+
friend bool
54+
operator==(const Sales_item&, const Sales_item&);
55+
public:
56+
// constructors are explained in section 7.1.4, pages 262 - 265
57+
// default constructor needed to initialize members of built-in type
58+
#if defined(IN_CLASS_INITS) && defined(DEFAULT_FCNS)
59+
Sales_item() = default;
60+
#else
61+
Sales_item(): units_sold(0), revenue(0.0) { }
62+
#endif
63+
Sales_item(const std::string &book):
64+
bookNo(book), units_sold(0), revenue(0.0) { }
65+
Sales_item(std::istream &is) { is >> *this; }
66+
public:
67+
// operations on Sales_item objects
68+
// member binary operator: left-hand operand bound to implicit this pointer
69+
Sales_item& operator+=(const Sales_item&);
70+
71+
// operations on Sales_item objects
72+
std::string isbn() const { return bookNo; }
73+
double avg_price() const;
74+
// private members as before
75+
private:
76+
std::string bookNo; // implicitly initialized to the empty string
77+
#ifdef IN_CLASS_INITS
78+
unsigned units_sold = 0; // explicitly initialized
79+
double revenue = 0.0;
80+
#else
81+
unsigned units_sold;
82+
double revenue;
83+
#endif
84+
};
85+
86+
// used in chapter 10
87+
inline
88+
bool compareIsbn(const Sales_item &lhs, const Sales_item &rhs)
89+
{ return lhs.isbn() == rhs.isbn(); }
90+
91+
// nonmember binary operator: must declare a parameter for each operand
92+
Sales_item operator+(const Sales_item&, const Sales_item&);
93+
94+
inline bool
95+
operator==(const Sales_item &lhs, const Sales_item &rhs)
96+
{
97+
// must be made a friend of Sales_item
98+
return lhs.units_sold == rhs.units_sold &&
99+
lhs.revenue == rhs.revenue &&
100+
lhs.isbn() == rhs.isbn();
101+
}
102+
103+
inline bool
104+
operator!=(const Sales_item &lhs, const Sales_item &rhs)
105+
{
106+
return !(lhs == rhs); // != defined in terms of operator==
107+
}
108+
109+
// assumes that both objects refer to the same ISBN
110+
Sales_item& Sales_item::operator+=(const Sales_item& rhs)
111+
{
112+
units_sold += rhs.units_sold;
113+
revenue += rhs.revenue;
114+
return *this;
115+
}
116+
117+
// assumes that both objects refer to the same ISBN
118+
Sales_item
119+
operator+(const Sales_item& lhs, const Sales_item& rhs)
120+
{
121+
Sales_item ret(lhs); // copy (|lhs|) into a local object that we'll return
122+
ret += rhs; // add in the contents of (|rhs|)
123+
return ret; // return (|ret|) by value
124+
}
125+
126+
std::istream&
127+
operator>>(std::istream& in, Sales_item& s)
128+
{
129+
double price;
130+
in >> s.bookNo >> s.units_sold >> price;
131+
// check that the inputs succeeded
132+
if (in)
133+
s.revenue = s.units_sold * price;
134+
else
135+
s = Sales_item(); // input failed: reset object to default state
136+
return in;
137+
}
138+
139+
std::ostream&
140+
operator<<(std::ostream& out, const Sales_item& s)
141+
{
142+
out << s.isbn() << " " << s.units_sold << " "
143+
<< s.revenue << " " << s.avg_price();
144+
return out;
145+
}
146+
147+
double Sales_item::avg_price() const
148+
{
149+
if (units_sold)
150+
return revenue/units_sold;
151+
else
152+
return 0;
153+
}
154+
#endif

0 commit comments

Comments
 (0)