// page : 5 #includeint main() { std::cout << "Enter two numbers:" << std::endl; int v1 = 0, v2 = 0; std::cin >> v1 >> v2; std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1 + v2 << std::endl; system("pause"); return 0; }
// page : 10 #includeint main() { int sum = 0, val = 1; //只要Val的值小于等于10,while循环就会持续进行 while (val <= 10) { sum += val; ++val; } std::cout << "Sum of 1 to 10 inclusive is " << sum << std::endl; system("pause"); return 0; }
// page : 11 #includeint main() { int sum = 0; //从1加到10 for (int val = 1; val <= 10; ++val) sum += val; std::cout << "Sum of 1 to 10 is " << sum << std::endl; system("pause"); return 0; }
// page : 13 #includeint main() { int sum = 0, value = 0; //读取数据直到遇到文件尾,计算所有读入的值的和 while (std::cin >> value)//win系统的文件结束符尾ctrl+d sum += value; std::cout << "Sum is: " << sum << std::endl; system("pause"); return 0; }
// page : 18 #include#include "Sales_item.h" int main() { Sales_item book; std::cin >> book; std::cout << book << std::endl; system("pause"); return 0; }
// page : 19 #include#include "Sales_item.h" int main() { Sales_item item1,item2; std::cin >> item1 >> item2; std::cout << item1 + item2 << std::endl; system("pause"); return 0; }
// page : 20 #include#include "Sales_item.h" int main() { Sales_item item1,item2; std::cin >> item1 >> item2; if (item1.isbn() == item2.isbn()) { std::cout << item1 + item2 << std::endl; system("pause"); return 0; } else { std::cerr << "Data must refer to same ISBN" << std::endl; system("pause"); return -1; } }
// page : 21 #include#include "Sales_item.h" int main() { Sales_item total; if (std::cin >> total) { Sales_item trans; while (std::cin >> trans) { if (total.isbn() == trans.isbn()) total += trans; else { std::cout << total << std::endl; total = trans; } } std::cout << total << std::endl; } else { std::cerr << "No data?!" << std::endl; system("pause"); return -1; } system("pause"); return 0; }



