[SOLVED] 02393 Assignment 5-Processing datasets

35.00 $

Category: Tags: , , , ,
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Assignment-5-Containers_1-dzmvkd.zip (2092.1 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

 

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 identifier of the dataset it belongs to, and there are only two datasets, identified 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 different sizes.

Exercise 1: Read the datasets and write them into cout in the following order: first by dataset (first 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: first 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 first, 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.

  • Assignment-5-Containers_1-dzmvkd.zip