Oct 16, 2026 08:12 PM
#include <iostream>
#include "Sales_item.h"
int main; (
//We read and ensure that we have data to process
Sales_item total;
if (std::cin >> total) {
Sales_item trans;
while (std::cin > trans) {
if (trans.isbn () == total.isbn ())
return 0; )
etc.
This is the most complicated program we've seen so far, but it only uses facilities that we are already familiar with.
As usual we begin with our headers, <iostream> from the library and our own sales_item.h. Inside main, we define an object named total, which will sum the data for a given transaction. Next we define an object named trans, which will hold the transactions as we read them. The while condition will read the remaining records. As in our earlier programs, the while reads a value from the standard input. That value is a sales_item object.
Assuming we have successfully read a record, we execute the block following the outermost if statement. That block starts by defining an object named trans, which will read our remaining records.
The if checks whether the isbn's are equal. If they are we use the compound assignment operator to add trans to total and update the running total.
#include "Sales_item.h"
int main; (
//We read and ensure that we have data to process
Sales_item total;
if (std::cin >> total) {
Sales_item trans;
while (std::cin > trans) {
if (trans.isbn () == total.isbn ())
return 0; )
etc.
This is the most complicated program we've seen so far, but it only uses facilities that we are already familiar with.
As usual we begin with our headers, <iostream> from the library and our own sales_item.h. Inside main, we define an object named total, which will sum the data for a given transaction. Next we define an object named trans, which will hold the transactions as we read them. The while condition will read the remaining records. As in our earlier programs, the while reads a value from the standard input. That value is a sales_item object.
Assuming we have successfully read a record, we execute the block following the outermost if statement. That block starts by defining an object named trans, which will read our remaining records.
The if checks whether the isbn's are equal. If they are we use the compound assignment operator to add trans to total and update the running total.
