Pages

Friday, 3 June 2022

Chapter 24 // Drill 5 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 24 // Drill 5

Read ten floating-point values from input and put them into a Matrix<double>. Matrix has no push_back() so be careful to handle an attempt to enter a wrong number of doubles. Print out the Matrix.


The accompanying MatixIO.h file provides very simple I/O for 1D and 2D matrices. So
Matrix<double> a(4);
cin >> a;
cout << a;

Will read 4 whitespace-seperate doubles delimited by curly braces. For example with a 1D matrix:
{ 1.2 3.4 5.6 7.8 }

These functions will handle reading in the correct amount of numbers and throw errors if the structure isn't exact.

I also added my own method for fun.

No comments:

Post a Comment