Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do all of them! Here is the code we learned in class!! (1) Dynamic Memory Allocation and Structures #include struct Vector{ double *x; //

image text in transcribed Please do all of them! Here is the code we learned in class!! (1) "Dynamic Memory Allocation and Structures"
#include  struct Vector{ double *x; // Vector elements pointer int n_dimension; }; struct Matrix{ double *X; //Matrix elements pointer int n_rows, n_columns; //Rows and column dimensions }; void DefineVector (Vector &a, int size){ a.n_dimension = size; a.x = (double*)calloc(size, sizeof(double)); } void DisplayVector(Vector a){ for (int i = 0; i > a.x[i]; } } int main() { Vector a; //Declares a vector a of Vector Structure datatype Matrix A; //Declares a Matrix A of Matrix Structure dataype int a_size, A_rows, A_columns; std::cout > a_size; DefineVector(a, a_size); //DMA for Vector a DisplayVector(a); //Dsplays Vector a elements SpecifyVectorElements(a); DisplayVector(a); }

(2) Matrix Multiplication

#include  struct Vector { double *x; // Vector elements pointer int n_dimension; }; struct Matrix { double *X; // Matrix elements pointer int n_rows, n_columns; // Rows and column dimensions }; void DefineVector(Vector &a, int size) { a.n_dimension = size; a.x = (double *)calloc(size, sizeof(double)); } void DefineMatrix(Matrix &A, int rows, int columns) { A.n_rows = rows; A.n_columns = columns; A.X = (double *)calloc(rows * columns, sizeof(double)); } void DisplayVector(Vector a) { for (int i = 0; i > a.x[i]; } } void SpecifyMatrixElements(Matrix &A) { std::cout > A.X[i + k* A.n_rows]; } } } void VectorMatrixProduct(Vector a, Matrix A, Vector &b){ if (A.n_columns == a.n_dimension){ DefineVector(b, A.n_rows); for(int i = 0; i> A_rows; std::cout > A_columns; DefineMatrix(A, A_rows, A_columns); SpecifyMatrixElements(A); DisplayMatrix(A); std::cout > B_rows; std::cout > B_columns; DefineMatrix(B, B_rows, B_columns); SpecifyMatrixElements(B); DisplayMatrix(B); MatrixMatrixProduct(A, B, C); std::cout > a_size; DefineVector(a, a_size); // DMA for Vector a //DisplayVector(a); // Displays Vector a elements SpecifyVectorElements(a); DisplayVector(a); std::cout > A_rows; std::cout > A_columns; DefineMatrix(A, A_rows, A_columns); SpecifyMatrixElements(A); DisplayMatrix(A); VectorMatrixProduct(a, A, b); std::cout  

Functions and Modules: 1. Write a function C2F to convert Temperature in degree Celsius to degree Fahrenheit which takes input arguments double CTemp and returns CFahr. Call this function in main function to convert any given temperature from Celsius to Fahrenheit. (2.5 points) 2. Write a module with argument CTemp and CFahr which converts any given temperature from Celsius to Fahrenheit. Call this module in main function and verify its results. (2.5 points) 3. From the nested loops concept, Dynamic memory Allocation and Structures, we learned in the class, (10 points) a. Write a module to Transpose a Matrix A of size 4X3 (rows X columns) into Matrix B. Note, give appropriate values to the rows and columns of Matrix B. b. In the main function, DefineMatrix A and B. Display Matrix A and then invoke the newly written Transpose function to accomplish B=AT. Then display Matrix B in the following format. 4. Write another module Reverse, (5 points) a. To create a new Matrix C (33) from a Matrix D ( 3 X 3) where elements of Matrix C are modified as follows: An example of Matrix D: Resultant Matrix C must look like: b. Display the Matrices C and D in the format shown above Execute the above programs, submit the code as text file and repl.it link. Also include a screenshot of the outcome in the output console window

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

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions