CREATE CLASS & INITIALIZE THE CLASS MEMBER USING CONSTRUCTOR & DISPLAY

hello friends....

TAKE THE FIRST STEP TO KNOWLEDGE FRIENDS BECAUSE KNOWLEDGE IS FREE.

/* CREATE CLASS FRUIT WITH AT LEAST THREE DATA MEMBER. INITIALIZE THE CLASS MEMBER USING CONSTRUCTOR AND DISPLAY THE DETAILS OF LEAST 5 FRUITS. */

#include<iostream.h>
#include<conio.h>
class fruits
{
    int price;
    char name[20],color[20];
    public:
     fruits();
     void display();
};
fruits::fruits()
     {
   cout<<"enter fruit name :";
   cin>>name;
   cout<<"enter fruit color :";
   cin>>color;
   cout<<"enter fruit price :";
   cin>>price;
}
void fruits::display()
{
  cout<<name<<"\t\t"<<color<<"\t\t"<<price<<endl;
}

void main()
{
   clrscr();
   fruits f1,f2,f3,f4,f5;
   cout<<"\n";
   cout<<"fruit name\tfruit color\tfruit price\n";
   f1.display();
   f2.display();
   f3.display();
   f4.display();
   f5.display();
  getch();
}


  OUTPUT
============

enter fruit name :pear
enter fruit color :green
enter fruit price :40
enter fruit name :peach
enter fruit color :pink
enter fruit price :90
enter fruit name :apple
enter fruit color :red
enter fruit price :60
enter fruit name :banana
enter fruit color :yellow
enter fruit price :20
enter fruit name :orange
enter fruit color :orange
enter fruit price :10

fruit name       fruit color        fruit name 
pear                 green               40
peach               pink                 90
apple                red                   60
banana             yellow             20
orange             orange             10
* * * * * * * * * * * * * *
>> IF YOU LIKE THIS BLOG, PLEASE SHARE AND SUBSCRIBE. ALSO COMMENT  FOR THIS BLOG.
>> IF YOU HAVE ANY QUESTIONS PLEASE ASK IN COMMENT.
>> IF YOU WANT TO LEARN HTML WITH OUTPUT, SO VISIT THIS BLOG
      https://dnpwebdeveloper.blogspot.com/
>> IF YOU WANT TO LEARN C++ PROGRAM WITH OUTPUT, SO VISIT THIS BLOG
      https://cplusplusdnpdeveloper.blogspot.com/
>> IF YOU WANT TO LEARN C PROGRAM WITH OUTPUT, SO VISIT THIS BLOG
      https://dnpdeveloper.blogspot.com/
>> MY INSTAGRAM ID : dnp176

Comments

Popular posts from this blog

CREATE CLASS FRUIT FRUIT WITH AT LEAST THREE DATA MEMBER AND DISPLAY LEAST 5 FRUITS DETAILS

MATRIX' CLASS OF SIZE m X n, OVERLOAD THE '+' OPERATOR TO ADD TWO MATRIX OBJECTS

IMPLEMENT POWER FUNCTION USING FUNCTION OVERLOADING