OOP HomeWork

This commit is contained in:
e2hang
2025-08-11 00:01:30 +08:00
commit e8a5ca2363
119 changed files with 3187 additions and 0 deletions

33
oop_hw3/hw3/main.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include <iostream>
using namespace std;
template <class T>
void f(int m, int n) {
T** p;
p = new T* [m];
for (int i = 0;i < m;i++) {
p[i] = new T[n];
}
int cnt = 1;
for (int i = 0;i < m;i++) {
for (int j = 0;j < n;j++) {
p[i][j] = cnt;
cout << cnt << " ";
cnt++;
}
cout << endl;
}
if (p) {
for (int i = 0;i < m;i++) {
delete[] p[i];
}
delete[] p;
}
}
int main() {
int a, b;
cin >> a >> b;
f<int>(a, b);
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 KiB