Tuesday, December 9, 2014

Array pro and Data pro and Function pro using in c++



Illustrate array of objects in classes in C++ Programming

 #include
 #include
/*************************************************************************///------------------------------  distance  -----------------------------///*************************************************************************/
class distance
    {
      private:
        int feet;
        float inches;
      public:
        void getdistance();
        void showdistance();
    };
/*************************************************************************///---------------------------  getdistance( )  -------------------------///*************************************************************************/
void distance::getdistance()
    {
       cout<<"\t Enter feet = ";
       cin>>feet;
       cout<<"\t Enter inches = ";
       cin>>inches;
    }
/*************************************************************************///---------------------------  showdistance( )  -----------------------///*************************************************************************/
void distance::showdistance()
    {
       cout<<"\n\t Total distance is "<"\' "<'"'<
    }
int main()
    {
       clrscr();
       distance obj[25];
       char ans;
       int n=0;
       do
      {
         cout<<"\n Enter the distance number = "<
         obj[n++].getdistance();
         cout<<"\n  Enter another (y/n)?";
         cin>>ans;
      }
       while(ans!='n');
       for(int i=0;i
      {
         cout<<"\n Distance number "<" is :";
         obj[i].showdistance();
      }
       getch();
       return 0;
    }

Class and objects using private and public data members in C++

#include
#include
class data
{
    int day;
    int month;
    int year;
    public:
    void date(int dd,int mm,int yy)
    {
        day=dd;
        month=mm;
        year=yy;
        cout<<"\t"<
        cout<<"\t"<
        cout<<"\t"<
    }
};
int main()
{
    clrscr();
    data f1,f2;
    f1.date(7,12,2002);
    f2.date(8,12,2002);
    f1.date(12,12,2002);
}

Pointer to Function 


#include
#include
int main()
{
   double y(), cos(), table();
   table (y,0.0,2.0,0.5);
   table (cos,0.0,3.1415,0.5);
}
double (double (*f)(),min,max,step;)
  {
      double a, value;
      for (a=min;a,=max; a+=step)
      {
          value = (*f)(a);
          printf("%5.2f %10.4f\n",a,value);} 
       }
    double y (double x) 
    {
return (2*x*x-x+1);
}

No comments:

Post a Comment