Starting from:

$30

02393 C++ Programming Exercises  Assignment 5 -Solved

Processing datasets 
The goal of the following exercises is similar. You have 
to read some mixed datasets of int values from cin and process them. Luckily, 
each data value is preceded by the identififier of the dataset it belongs to, and 
there are only two datasets, identifified by a and b. You have to read values until 
the input provides no more (no explicit stop input is provided). The datasets 
can be of difffferent sizes. 
Exercise 1: Read the datasets and write them into cout in the following order: 
fifirst by dataset (fifirst a, then b) and then by value. Example: 
input: a 3 b 2 b 1 a 1 a 4 b 2 
output: 1 3 4 1 2 2 
Exercise 2: Read the datasets and write them into cout in the following order: 
fifirst the 1st read value of dataset a (if any), then the 1st read value from 
dataset b (if any), then the 2nd read value from the dataset a (if any), 
then the 2nd read value from dataset b (if any), etc. Example: 
input: a 3 b 2 b 1 a 1 a 4 b 2 
output: 3 2 1 1 4 2 
Exercise 3: Read the datasets. Interpret each dataset as a vector (in the 
order provided by the input) and compute their scalar product. If one 
of the vectors is shorter than the other, the missing dimensions are to be 
considered as having value 0. Example: 
input: a 3 b 2 b 1 a 1 a 4 b 2 
output: 15 
which is obtained from (3, 1, 4) × (2, 1, 2) = 3 · 2 + 1 · 1 + 4 · 2 
Hints Use one vector container to store each dataset. Load the datasets into 
the vectors fifirst, and process them later. Use the documentation of vector: 
http://en.cppreference.com/w/cpp/container/vector 
http://www.cplusplus.com/reference/vector/vector/ 
Challenge 
Consider the more general case of an unknown arbitrary number 
of data sets.

More products