C++ Class Data and Function Members Question

Introduction

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

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

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

You can use the following code structure.

#include <iostream> 

int main() 
{ 
    //your code here
} 


#include <iostream> 

class MyClass 
{ 
public: 
    void printmessage(); 
}; 

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

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



PreviousNext

Related