Created
March 7, 2017 07:40
-
-
Save pezy/94bf6cc1125e4d05752eb45d8dd68733 to your computer and use it in GitHub Desktop.
review for CppPrimer#104
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
#include <iostream> | |
#include <string> | |
class Sales_data { | |
public: | |
friend std::istream& read(std::istream&, Sales_data&); | |
Sales_data(std::istream &is = std::cin) { read(is, *this); } | |
std::string bookNo; | |
int units_sold; | |
double revenue; | |
}; | |
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() | |
{ | |
Sales_data sales; | |
std::cout << sales.bookNo << "_" << sales.units_sold << "_" << sales.revenue << 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
#include <iostream> | |
struct X { | |
X(int i, int j): base(i), rem(base % j) {} | |
int base, rem; | |
}; | |
int main() | |
{ | |
X x(10, 5); | |
std::cout << x.base << "_" << x.rem << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment