C++ Class Member Function Question

Introduction

Write a program that defines a class called MyClass with one member function called printmessage().

Define the printmessage() member function inside the class and make it output the "Hello World" string.

Create an instance of that class and use the object to call the class member function.

You can use the following code structure.

#include <iostream> 

int main() 
{ 
    //your code here
} 



#include <iostream> 

class MyClass 
{ 
public: 
    void printmessage() 
    { 
        std::cout << "Hello World."; 
    } 
}; 

int main() 
{ 
    MyClass o; 
    o.printmessage(); 
} 



PreviousNext

Related