C++ examples for Class:Class Creation
Create a method in class to accept parameter
#include <iostream> #include <string> class MyClass {/*from w ww.ja v a2 s . com*/ public: void displayMessage(std::string courseName) { std::cout << "Welcome to the grade book for\n" << courseName << "!" << std::endl; } }; int main(int argc, const char *argv[]) { std::string nameOfCourse; MyClass myMyClass; // prompt for and input course name std::cout << "Please enter the course name: "; std::getline(std::cin, nameOfCourse); // read a course name with blanks std::cout << std::endl; myMyClass.displayMessage(nameOfCourse); return 0; }