Program to Explain Working of Object and Class in C++ Programming.

/* Program to illustrate working of Objects and Class in C++*/
#include <iostream.h>
class temp
{
    private:
        int data1;
        float data2;
    public:
       void int_data(int d){
          data1=d;
          cout<<"Number: "<<data1;
         }
       float float_data(){
           cout<<"\nEnter data: ";
           cin>>data2;
           return data2;
         }
};
 int main(){
      temp obj1, obj2;
      obj1.int_data(12);
      cout<<"You entered "<<obj2.float_data();
      return 0;
 }
Expected Output:
Number: 12
Enter data: 12.43
You entered: 12.43

Post a Comment

Previous Post Next Post