forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
84 changed files
with
1,077 additions
and
952 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
Language: Cpp | ||
# BasedOnStyle: LLVM | ||
AccessModifierOffset: 0 | ||
AlignAfterOpenBracket: true | ||
AlignEscapedNewlinesLeft: false | ||
AlignOperands: true | ||
AlignTrailingComments: true | ||
AlignConsecutiveAssignments: false | ||
AllowAllParametersOfDeclarationOnNextLine: false | ||
AllowShortBlocksOnASingleLine: false | ||
AllowShortCaseLabelsOnASingleLine: false | ||
AllowShortIfStatementsOnASingleLine: true | ||
AllowShortLoopsOnASingleLine: true | ||
AllowShortFunctionsOnASingleLine: false | ||
AlwaysBreakAfterDefinitionReturnType: false | ||
AlwaysBreakTemplateDeclarations: false | ||
AlwaysBreakBeforeMultilineStrings: false | ||
BreakBeforeBinaryOperators: None | ||
BreakBeforeTernaryOperators: true | ||
BreakConstructorInitializersBeforeComma: false | ||
BinPackParameters: true | ||
BinPackArguments: true | ||
ColumnLimit: 80 | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: false | ||
ConstructorInitializerIndentWidth: 4 | ||
DerivePointerAlignment: false | ||
ExperimentalAutoDetectBinPacking: false | ||
IndentCaseLabels: false | ||
IndentWrappedFunctionNames: false | ||
IndentFunctionDeclarationAfterType: false | ||
MaxEmptyLinesToKeep: 1 | ||
KeepEmptyLinesAtTheStartOfBlocks: true | ||
NamespaceIndentation: None | ||
ObjCBlockIndentWidth: 2 | ||
ObjCSpaceAfterProperty: false | ||
ObjCSpaceBeforeProtocolList: true | ||
PenaltyBreakBeforeFirstCallParameter: 19 | ||
PenaltyBreakComment: 300 | ||
PenaltyBreakString: 1000 | ||
PenaltyBreakFirstLessLess: 120 | ||
PenaltyExcessCharacter: 1000000 | ||
PenaltyReturnTypeOnItsOwnLine: 60 | ||
PointerAlignment: Right | ||
SpacesBeforeTrailingComments: 1 | ||
Cpp11BracedListStyle: true | ||
Standard: Cpp11 | ||
IndentWidth: 4 | ||
TabWidth: 4 | ||
UseTab: Never | ||
BreakBeforeBraces: Stroustrup | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
SpacesInAngles: false | ||
SpaceInEmptyParentheses: false | ||
SpacesInCStyleCastParentheses: false | ||
SpaceAfterCStyleCast: false | ||
SpacesInContainerLiterals: true | ||
SpaceBeforeAssignmentOperators: true | ||
ContinuationIndentWidth: 4 | ||
CommentPragmas: '^ IWYU pragma:' | ||
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] | ||
SpaceBeforeParens: ControlStatements | ||
DisableFormat: false | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,51 @@ | ||
#include <string> | ||
#include <iostream> | ||
|
||
struct Sales_data | ||
{ | ||
std::string bookNo; | ||
unsigned units_sold = 0; | ||
double revenue = 0.0; | ||
|
||
void CalcRevenue(double price); | ||
double CalcAveragePrice(); | ||
void SetData(Sales_data data); | ||
void AddData(Sales_data data); | ||
void Print(); | ||
struct Sales_data { | ||
std::string bookNo; | ||
unsigned units_sold = 0; | ||
double revenue = 0.0; | ||
|
||
void CalcRevenue(double price); | ||
double CalcAveragePrice(); | ||
void SetData(Sales_data data); | ||
void AddData(Sales_data data); | ||
void Print(); | ||
}; | ||
|
||
void Sales_data::CalcRevenue(double price) | ||
{ | ||
revenue = units_sold * price; | ||
revenue = units_sold * price; | ||
} | ||
|
||
void Sales_data::SetData(Sales_data data) | ||
{ | ||
bookNo = data.bookNo; | ||
units_sold = data.units_sold; | ||
revenue = data.revenue; | ||
bookNo = data.bookNo; | ||
units_sold = data.units_sold; | ||
revenue = data.revenue; | ||
} | ||
|
||
void Sales_data::AddData(Sales_data data) | ||
{ | ||
if (bookNo != data.bookNo) return; | ||
units_sold += data.units_sold; | ||
revenue += data.revenue; | ||
if (bookNo != data.bookNo) return; | ||
units_sold += data.units_sold; | ||
revenue += data.revenue; | ||
} | ||
|
||
double Sales_data::CalcAveragePrice() | ||
{ | ||
if (units_sold != 0) | ||
return revenue/units_sold; | ||
else | ||
return 0.0; | ||
if (units_sold != 0) | ||
return revenue / units_sold; | ||
else | ||
return 0.0; | ||
} | ||
|
||
void Sales_data::Print() | ||
{ | ||
std::cout << bookNo << " " << units_sold << " " << revenue << " "; | ||
double averagePrice = CalcAveragePrice(); | ||
if (averagePrice != 0.0) | ||
std::cout << averagePrice << std::endl; | ||
else | ||
std::cout << "(no sales)" << std::endl; | ||
std::cout << bookNo << " " << units_sold << " " << revenue << " "; | ||
double averagePrice = CalcAveragePrice(); | ||
if (averagePrice != 0.0) | ||
std::cout << averagePrice << std::endl; | ||
else | ||
std::cout << "(no sales)" << std::endl; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.