August 2012
Intermediate to advanced
976 pages
30h 17m
English
Our program that adds two Sales_items should check whether the objects have the same ISBN. We’ll do so as follows:
#include <iostream>#include "Sales_item.h"int main(){ Sales_item item1, item2; std::cin >> item1 >> item2; // first check that item1 and item2 represent the same book if (item1.isbn() == item2.isbn()) { std::cout << item1 + item2 << std::endl; return 0; // indicate success } else { std::cerr << "Data must refer to same ISBN" << std::endl; return -1; // indicate failure }}
The difference between this program and the previous version is the if and its associated else branch. Even without understanding the if condition, we know ...
Read now
Unlock full access