Skip to content

Commit 7434a83

Browse files
committed
add: cpp-programming-questions
1 parent 81eb266 commit 7434a83

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

11_new_and_delete/00_questions.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212

1313
04. Define a class representing a student with attributes like name and roll number. Dynamically create an array of student objects based on user input for the number of students. Allow the user to input details for each student, display their information, and then use delete to free the memory.
1414

15+
05. Demonstrate the use of new operator with reference variable in cpp.

11_new_and_delete/02_matrix.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int main()
5050
for (int j = 0; j < cols; j++)
5151
cout << left << setw(4) << matrix[i][j];
5252

53-
putch(10); // // Add New line
53+
cout << endl; // // Add New line
5454
}
5555

5656
// // Transpose of Matrix
@@ -60,7 +60,7 @@ int main()
6060
for (int j = 0; j < rows; j++)
6161
cout << left << setw(4) << matrix[j][i];
6262

63-
putch(10); // // Add New line
63+
cout << endl; // // Add New line
6464
}
6565

6666
// // deallocate dynamically allocated memory
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// // Demonstrate the use of new operator with reference variable in cpp
2+
3+
// // Header files
4+
#include <iostream>
5+
6+
// // use namespace
7+
using namespace std;
8+
9+
// // define class A
10+
class Hello
11+
{
12+
13+
public:
14+
// // instance member function to print hello
15+
void printHello()
16+
{
17+
cout << "\nHello";
18+
}
19+
20+
operator Hello *()
21+
{
22+
return (*this);
23+
}
24+
};
25+
26+
// // Main Function Start
27+
int main()
28+
{
29+
// // create an reference obejct of class Hello
30+
Hello &h1 = *(new Hello);
31+
32+
h1.printHello();
33+
34+
cout << endl; // Add new line
35+
cin.ignore();
36+
return 0;
37+
}
38+
// // Main Function End
44.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)