by Dinesh Thakur Category: Classes in C++

 

#include <iostream.h>

#include <conio.h>
const int size=10;
#include <string.h>
class country
{
        protected:
                           char cname[size];
                           float pprc;
                           float Iprc;
                           float ratio;
        public:
                          country(){ }
                          virtual void getdata()
                    {
                              cout<<"Enter Country Name ";
                              cin>>cname;
                              cout<<"Enter the % of Polio ";
                              cin>>pprc;
                              cout<<"Enter the % of Literacy ";
                              cin>>Iprc;
                     }
                          virtual void display()
                    {
                        cout<<"\n";
                        cout<<"Country Name "<<cname<<endl;
                        cout<<"Country Polio% "<<pprc<<endl;
                        cout<<"Country Lit. % "<<Iprc<<endl;
                        cout<<"The Measure of Interdependency "<<float (pprc/Iprc)<<endl;
                    }
};
           class state: public country
    {
  protected :
                       char sname[size];
                       float spprc;
                       float slprc;
                       float ratio;
 public:
                       state() {}
                       void getdata()
                          {
                                      country::getdata();
                                      cout<<" \n";
                                      cout<<"Enter State Name ";
                                      cin>>sname;
                                      cout<<"Enter %Age of Polio of State ";
                                      cin>>spprc;
                                      cout<<"Enter %Age of Lite. of State ";
                                      cin>>slprc;
                          }
                                      void display()
                               {
                                            country::display();
                                            cout<<"State Name "<<sname<<endl;
                                            cout<<"%Age of Polio of State "<<spprc<<endl;
                                            cout<<"%Age of Lite. of State "<<slprc<<endl;
                                            cout<<"The Measure of Interdependency "<<float (spprc/slprc)<<endl;
                                }
      };
                     void main( )
             {
                         clrscr();
                         country *o1;
                         state o2;
                         cout<<"\n";
                         o1= &o2;
                         o1->getdata();
                         o2.display();
                         getch();
             }

Virtual Function



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles