1].
Write a C++ Program which show the use of function outside the class using scope resolution operator.
#include <iostream>
using namespace std;
// Define the class
class MyClass {
public:
void display() {
cout << "Inside the class method" << endl;
}
// Function outside the class using scope resolution operator
void MyClass::show() {
cout << "Outside the class using scope resolution operator" << endl;
}
};
int main() {
MyClass obj;
// Call the class method
obj.display();
// Call the function outside the class
obj.show();
return 0;
}
OUTPUT:-
2]. Write a program to display the massage “Welcome to the world of C++” using manipulators.
#include <iostream.h>
#include <iomanip.h>
int main()
{
cout << setw(30) << "Welcome to the world of C++" << endl;
return 0;
}
OUTPUT:-
3]. Write a program to create the memory using new operator and free the created memory using delete
operator.
#include <iostream.h>
int main()
{
int *ptr;
// Allocate memory for an integer
ptr = new int;
// Assign a value to the allocated memory
*ptr = 10;
// Access and print the value
cout << "Value: " << *ptr << endl;
// Free the allocated memory
delete ptr;
return 0;
}
OUTPUT:-