Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE DO NOT COPY PASTE FROM CHEGG/OTHERWISE I'LL REPORT YOU OR GIVE OU A DISLIKE [Q-6] Phase 1 Write a C++ program that multiplies a

PLEASE DO NOT COPY PASTE FROM CHEGG/OTHERWISE I'LL REPORT YOU OR GIVE OU A DISLIKEimage text in transcribed

[Q-6] Phase 1 Write a C++ program that multiplies a matrix by a vector. The program should read the number of rows and columns of the matrix from the command line Ex. s\$ /8 a.out -rows cint s>s-cols $ Phase 1 Write a C++ program that multiplies a matrix by a vector. The program should read the number of rows and columns of the matrix from the command line. $ /a.out-rows cint> -cols Ex Dynamically allocate space for the matrix and vector. The matrix and vector should both be declared to store integers. The vector should have the same size as the number of columns. Be sure to allocate "number of rows" integers for a vector to hold the product vector. Initialize each element of the matrix and vector to 1. This should be considered a test mode. Next, perform the matrix-vector multiplication operation. Finally, print the product vector on a single line with one space between elements. Confirm that the product is correct. The product vector should have as many elements as matrix rows. Each product vector element should equal the number of columns. Phase II Enable a compile-time flag to control how the matrix and vector are initialized the matrix for normal mode use. In test mode initialize the input matrix and vector as above. In normal mode Initialize the matrix and vector with random numbers in the range [-5, 5). Use the C++11 random number facilities, an example follows. DO NOT USE STANDARD C rand FUNCTION. Please keep the engine seed = 1; this will make grading much easier. #include dist(-5, 5); #ifdef TEST mat[][] - 1; #else mat[i] - dist(engine), Fendif Compile for TEST mode as follows $9++ stdC++11-DTEST mat-vec.cpp -o mat-vec.exe Compile for normal mode by omitting the "-DTEST" string

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions