Question

C++ Vectors readImage: Creates a two dimensional vector (a matrix) of 1's and 0's based off...

C++ Vectors

readImage: Creates a two dimensional vector (a matrix) of 1's and 0's based off of the input files which you send it. (Returns a multidimensional vector). Take two inputs - number of columns and number of rows.The image stored in a two-dimensional vector of ints.

printImage: Takes the matrix which was created in readImage and prints it out.

vector <vector<int>> readImage(int,int);

void printImage (vector<vector<int>>);

input: (explained in ()'s )

1 -(input 1)
10 1  - (10 colums and 1 row)
1 0 0 1 1 1 1 0 1 1   -(this needs to be outputed)

output:

1001111011
0 0
Add a comment Improve this question Transcribed image text
Answer #1

vector<vector<int> > readImage(int r, int c){
   vector<vector<int> > v;
   for(int i=0;i<r;i++){
       vector<int> temp;
       for(int j=0;j<c;j++){
           int x;
           cin >> x;
           temp.push_back(x);
       }
       v.push_back(temp);
   }
   return v;
}

void printImage(vector<vector<int> > v){
   for(int i=0;i<v.size();i++){
       for(int j=0;j<v[i].size();j++){
           cout << v[i][j] << " ";
       }
       cout << endl;
   }
}

Add a comment
Know the answer?
Add Answer to:
C++ Vectors readImage: Creates a two dimensional vector (a matrix) of 1's and 0's based off...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment: Write a C function that accepts the pointer to a matrix of integer numbers (i.e....

    Assignment: Write a C function that accepts the pointer to a matrix of integer numbers (i.e. a two-dimensional array), number of rows and number of columns as input and prints the matrix after rotating it 90 degrees clockwise. Example: void rotate-matrix (int* matrix, int row, int column) Inputs: row 4, column-6 and the pointer to the matrix below: 2 3 6 5 8 0 Output:

  • C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional...

    C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional arrays. Your program should include three functions: one for getting input data, one for calculating the sum of matrices, and one for printing the result. a) Function inputMatrix: This Function prompts the user to enter the data and stores data inside two-dimensional array. b) Function addMatrices: This function calculatesthe sum result of two matrices. c) Function printMatrix: This function prints the matrix to screen....

  • 1) Define a 2 dimensional arrays of doubles (3 rows by 3 columns) and 2) Read...

    1) Define a 2 dimensional arrays of doubles (3 rows by 3 columns) and 2) Read values from the user. 3) Print the numbers entered by the user in row major order 4) Print the numbers entered by the user in column major order import java.util.*; public class XXX_Chapter83 { public static void main(String[] args) { //creates array and stores values with input from user printArrayRowMajor (board); printArrayColumnMajor (board); } public static void printArrayRowMajor (int [] [] board) { //prints...

  • ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given....

    ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given. Perform various matrix processing activities according to the algorithms below. Store the results into the output vector (one-dimensional array) with appropriate size. For Grade 7) Count the number of odd values (n mod 2 <> 0) for each row. For Grade 9) Calculate the sum of positive values for each column. To obtain inputs and return the results, define appropriate type C/C++ functions. Please...

  • IT a) If one row in an echelon form for an augmented matrix is [o 0 5 o 0 b) A vector bis a linear combination of the columns of a matrix A if and only if the c) The solution set of Ai-b is the set o...

    IT a) If one row in an echelon form for an augmented matrix is [o 0 5 o 0 b) A vector bis a linear combination of the columns of a matrix A if and only if the c) The solution set of Ai-b is the set of all vectors of the formu +vh d) The columns of a matrix A are linearly independent if the equation A 0has If A and Bare invertible nxn matrices then A- B-'is the...

  • C++ Create a program that finds the dot product of two vectors. I'm currently trying to...

    C++ Create a program that finds the dot product of two vectors. I'm currently trying to display the dot product by calling the dotProduct member function however I am confused as to how to do this. What would be the proper way to display the dot product? I don't believe my dotProduct member function is set up correctly to access the proper data. Feel free to modify the dotProduct member function to allow for it to work with the other...

  • Language is C++ Basic principles and theory of structured programming in C++ by implementing the class:...

    Language is C++ Basic principles and theory of structured programming in C++ by implementing the class: Matrix Use these principles and theory to help build and manipulate instances of the class (objects), call member functions Matrix class implementation from the main function file and, in addition, the Matrix class must have its interface(Matrix.h) in a separate file from its implementation (Matrix.cpp). The code in the following files: matrix.h matrix.cpp matrixDriver.h Please use these file names exactly. Summary Create three files...

  • Theory: A vector with nonnegative entries is called a probability vector if the sum of its entries is 1. A square matrix...

    Theory: A vector with nonnegative entries is called a probability vector if the sum of its entries is 1. A square matrix is called right stochastic matrix if its rows are probability vectors; a square matrix is called a left stochastic matrix if its columns are probability vectors; and a square matrix is called a doubly stochastic matrix if both the rows and the columns are probability vectors. **Write a MATLAB function function [S1,S2,P]=stochastic(A) which accepts a square matrix A...

  • IN C#.Develop a program that prints out the location of the largest value in a two-dimensional...

    IN C#.Develop a program that prints out the location of the largest value in a two-dimensional array. The largest values may appear more than once in the array, so you must only print out the first instance. The program defines method locateLargest() that takes a two-dimensional array of integers and returns the location (row index and column index) of the first largest value as a single-dimensional array. The program main method prompts the user to enter a 3-by-4 matrix, prints...

  • Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array...

    Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT