Tuesday, 21 March 2017

Simple program created using Class (Object Oriented Programming)

This program will make us understand, how to use class and what is Object Oriented Programming. This program will take 6 strings Input and will display it on the screen as Output.

Source Code:
#include<iostream>
using namespace std;
class CourseNames
{
    private:
        string Names[6];
    public:
        void GetData()
        {
            cout<<"Enter Names of your Courses: "<<endl<<endl;
            for(int i=0; i<6; i++)
            {
                getline(cin, Names[i]);
            }
            cout<<endl;
        }

        void DisplayData()
        {
            cout<<"The course you Entered: "<<endl;
            for(int j=0; j<6; j++)
            {
                cout<<"\n*"<<Names[j]<<endl;
            }
        }
    
};

int main ()
{
  CourseNames S1;
  S1.GetData();
  S1.DisplayData();
}

No comments:

Post a Comment