0% found this document useful (0 votes)
44 views2 pages

Ex2 (Oops)

.

Uploaded by

suyashchavan301
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views2 pages

Ex2 (Oops)

.

Uploaded by

suyashchavan301
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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:-

You might also like