write a program using virtual function to find the
transposing of a square matrix?
Answer / Ashish Kumar Kashyap
In C++, you can use virtual functions in combination with inheritance to implement the transpose of a square matrix. Here's an example:n```cppnclass Matrix {npublic:n int **data;n int rows, cols;n // constructorn Matrix(int r, int c) : rows(r), cols(c) {n data = new int*[rows];n for (int i = 0; i < rows; ++i)n data[i] = new int[cols];n }n // destructorn ~Matrix() {n for (int i = 0; i < rows; ++i) delete[] data[i];n delete[] data;n }n // virtual function to transpose the matrixn virtual void transpose() = 0;n};n// derived class implementing the transpose functionnclass SquareMatrix : public Matrix {npublic:n SquareMatrix(int size) : Matrix(size, size) {}n void transpose() {n for (int i = 0; i < rows; ++i)n for (int j = i + 1; j < cols; ++j)n std::swap(data[i][j], data[j][i]);n }n};
| Is This Answer Correct ? | 0 Yes | 0 No |
Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.
what is virtual constroctor ? give an exam for it?-(parimal dhimmar)
Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.
1 Answers Facebook, Webyog, Wipro,
Faster Computers Suppose you have a computer that requires 1 minute to solve problem instances of size 1000. What instance sizes can be run in 1 minute if you buy a new computer that runs 1000 times faster than the old one, assuming the following time complexities T(n) for our algorithm? (a) T(n) = O(n). (b) T(n) = O(n3). (c) T(n) = O(10n).
using repetition structure. Write a c program that will accept five numbers. The program should count and output the total count of even numbers and total count of add numbers.
Here's the programm code: int magic(int a, int b) { return b == 0 ? a : magic(b, a % b); } int main() { int a, b; scanf("%d%d", &a, &b); printf("%d\n", magic(a, b)); return 0; } on input stream we have integers 4, 45 What's the output integer? How many times will be initiated "magic" function?
write a program that accepts a number and outputs its equivalent in words. take note that the maximum input is 3000
Write a program using one dimensional array that accept five values from the keyboard. Then it should also accept a number to search. This number is to be searched if it among the five input values. If it is found, display the message “Search number is found!” otherwise, display “Search is lost”. Example: Enter 5 numbers: 10 15 20 7 8 Enter number to search: 7 Search number is found!
2 Answers College School Exams Tests,
Display Pattern: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 …
Coin Problem You are given 9 gold coins that look identical. One is counterfeit and weighs a bit greater than the others, but the difference is very small that only a balance scale can tell it from the real one. You have a balance scale that costs 25 USD per weighing. Give an algorithm that finds the counterfeit coin with as little weighting as possible. Of primary importance is that your algorithm is correct; of secondary importance is that your algorithm truly uses the minimum number of weightings possible. HINT: THE BEST ALGORITHM USES ONLY 2 WEIGHINGS!!!
1 Answers Motorola, Qatar University,
What is the time complexity T(n) of the following program? a) int n, d, i, j; cin >> n; for (d=1; d<=n; d++) for (i=1; i<=d; i++) for (j=1; j<=n; j += n/10) cout << d << " " << i << " " << j << endl; b) void main() { int n, s, t; cin >> n; for (s = 1; s <= n/4; s++) {t = s; while (t >= 1) { cout << s << " " << t << endl; t--; } } } c) void main() { int n, r, s, t; cin >> n; for (r = 2; r <= n; r = r * 2) for (s = 1; s <= n/4; s++) { t = s; while (t >= 1) { cout << s << " " << t << endl; t--; } } }
3 Answers CTS, IBM, Infosys, Qatar University,
Show by induction that 2n > n2, for all n > 4.
2 Answers Karvy, Qatar University,