数制转换类继承

// Note:Your choice is C++ IDE

//题目:定义一个基类Number,该类对象存储一个整数值,并提供成员函数print_it来输出该整数;
//再定义Number类的二个派生类,分别以八进制和二进制输出该值。例:12(10)=14(8)=1100(2)


#include

using namespace std;

class Number{
 public:
 int a;
 virtual void print_it(){
 cout<<"The beginning number is:  "< }
};
class Octal:public Number{
     public:
     void print_it(){
     cout<<"Output the beginning number by Octal is:  "<     }   
}; 
class Binary:public Number{
 public:
 void print_it(){
  int data[20],i=0,b=a;
  cout<<"Output the beginning number by Bunary is:  ";
  do
  {  
   data[i]=b%2;
   b/=2;
   i++;
  }while(b!=0);
  for(i--;i>=0;i--)
  cout< } 
};
int main()
{   cout<<"Please input Data:  ";
 Number N;
 Octal num;
 Binary Num;
 cin>>num.a;
 N.a=num.a;
 Num.a=num.a;
 N.print_it();
 num.print_it();
 Num.print_it();
    return 0;
}

你可能感兴趣的:(常用工具类)