02393 C++ Programming Exercises (Solution)

$ 20.99

Description

Assignment 5
Hand-in via https://dtu.codejudge.net/02393-e17/assignment/
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.

Reviews

There are no reviews yet.

Be the first to review “02393 C++ Programming Exercises (Solution)”

Your email address will not be published. Required fields are marked *