This needs to be in C++
Problem3.cpp
Problem3.h:
/* * Problem3.h file */ #ifndef LAB3_PROBLEM3 #define LAB3_PROBLEM3 #define MAX 100 void rotatematrix(int m, int n, int mat[][MAX]); #endif /* problem3.h file ends */ /* * Problem3.cpp */ #include "problem3.h" void rotatematrix(int m, int n, int mat[][MAX]) { int M = m, N = n; int row = 0, col = 0; int prev, curr; while (row < m && col < n) { if (row + 1 == m || col + 1 == n) break; prev = mat[row + 1][col]; for (int i = col; i < n; i++) { curr = mat[row][i]; mat[row][i] = prev; prev = curr; } row++; for (int i = row; i < m; i++) { curr = mat[i][n-1]; mat[i][n-1] = prev; prev = curr; } n--; if (row < m) { for (int i = n-1; i >= col; i--) { curr = mat[m-1][i]; mat[m-1][i] = prev; prev = curr; } } m--; if (col < n) { for (int i = m-1; i >= row; i--) { curr = mat[i][col]; mat[i][col] = prev; prev = curr; } } col++; } // Print rotated matrix for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) cout << mat[i][j] << "\t"; cout << endl; } } /* Probelm3.cpp file ends */ /* * Main.cpp file */ #include <iostream> using namespace std; #include "problem3.h" int main() { int mat[][MAX] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16} }; rotatematrix(4, 4, mat); return 0; } /* Main.cpp file ends */
Note: Please drop comment, for issues or queries.
This needs to be in C++ Problem3.cpp Problem3.h: Given a matrix, clockwise-rotate elements in it. Please...
Given a matrix, clockwise-rotate elements in it. Please add code to problem3.cpp and the makefile. I have also given the main_problem3.cpp and problem3.h to test. problem3.cpp::: #include "problem3.h" // A function to rotate a matrix mat[][MAX] void rotatematrix(int m, int n, int mat[][MAX]) { // your code here } Makefile::: all : problem3.o g++ -o mainp3 # your code here problem3.o : problem3.h problem3.cpp # your code here clean: rm -f *.o mainp3 main_problem3.cpp::: #include <iostream>...
C++ how can I fix these errors this is my code main.cpp #include "SpecialArray.h" #include <iostream> #include <fstream> #include <string> using namespace std; int measureElementsPerLine(ifstream& inFile) { // Add your code here. string line; getline(inFile, line); int sp = 0; for (int i = 0; i < line.size(); i++) { if (line[i] == ' ') sp++; } sp++; return sp; } int measureLines(ifstream& inFile) { // Add your code here. string line; int n = 0; while (!inFile.eof()) { getline(inFile,...
CC++ Compiler: CPP (gcc-5.x) 0 Simple Calculator Given two integers and a string, create a simple calculator which performs the following operations: • Addition if the string is "+" • Difference if the string is "-" Multiplication if the string is "*" • Return quotient (obtained by dividing the first number by the second) if the string is "/" • Return greater value if the string is "max" • Return lesser value if the string is "min" solution.cpp 2 Create...
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:
Write a program whose input is two integers and whose output is the two integers swapped. Write in C language 7.3 LAB: Swapping variables Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 38 then the output is: 83 Your program must define and call a function. SwapValues returns the two values in swapped order. void SwapValues(int* userVali, int* userVal2) ACRIVITY 7.3.1: LAB: Swapping variables 0/10 ] main.c...
Define a test method testfindMax that exercises Calculation.findMax() in Calculation class Define a tearDown() method Given the following code below: 6. 7. 1. public class Calculation { 2. //method that returns cube of the given number 3. public int findMax(int ac[]}{ 4. int max=0; 5. for(int į=1;i<acr.length;i++){ if(max<arc[i]). max=acc[i]; } 8. return max: 10. } 11. //method that returns cube of the given number 12. public static int cube(int n){ 13. return n*n*n; 14. 15. } } 9. }
(b) Find the sircular convolution on xi(n) and x2(n). Show the steps. xi(n)- 4 9 16 x2(n)- (12 -6 4 -3) (n-0, 1,2,3) xiun) x2(-n reverse/rotate clockwise 14 916 9 16 14916 (reverse order) rotate right) 14916___ 14 916 4916 (b) Find the sircular convolution on xi(n) and x2(n). Show the steps. xi(n)- 4 9 16 x2(n)- (12 -6 4 -3) (n-0, 1,2,3) xiun) x2(-n reverse/rotate clockwise 14 916 9 16 14916 (reverse order) rotate right) 14916___ 14 916 4916
CONVERT CODE TO JAVA // A C++ program to Print all elements in sorted order from row and // column wise sorted matrix #include<iostream> #include<climits> using namespace std; #define INF INT_MAX #define N 4 // A utility function to youngify a Young Tableau. This is different // from standard youngify. It assumes that the value at mat[0][0] is // infinite. void youngify(int mat[][N], int i, int j) { // Find the values at down and right sides of...
In C please Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original maino: int main(void) { double milesPerHour, double minutes Traveled; double hours Traveled; double miles Traveled; scanf("%f", &milesPerHour); scanf("%lf", &minutes Traveled); hours Traveled = minutes Traveled / 60.0; miles Traveled = hours Traveled * milesPerHour; printf("Miles: %1f\n", miles Traveled); return 0; 1 #include <stdio.h> 3/* Your solution goes here */ 1 test passed 4 All tests passed...
Please help me modify the Stash3.cpp and Stash3.h files below to utilize default arguments in the constructor. Please test the constructor by creating two different versions of a Stash object. Please see the source code below: //Stash3.cpp //: C07:Stash3.cpp {O} // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt // Function overloading #include "Stash3.h" #include "../require.h" #include <iostream> #include <cassert> using namespace std; const int increment = 100;...