• 这两者,关于抽象函数的区别,自己还没有完全区分开来


    #include<iostream>
    
    using namespace std;
    //实现多继承场景
    class Interface
    {
    public:
    	virtual int  add(int a,int b)=0;
    	virtual void  print()=0;
    private:
    	int i1;
    protected:
    };
    class Interface2
    {
    public:
    	virtual int  multi(int a,int b)=0;
    	virtual void  print()=0;
    private:
    	int i2;
    protected:
    };
    
    class Child:public Interface,public Interface2
    {
    public:
    	void print()
    	{
    		cout<<"Child 的 打印
    ";
    	}
    	int  add(int a,int b)
    	{
    		return a+b;
    	}
    	int multi(int a,int b)
    	{
    		return a*b;
    	}
    
    	
    private:
    	int c;
    protected:
    };
    int main()
    {
    	Child c;
    	c.print();
    
    	
    	cout<<"  add";
    	cout<<c.add(2,3);
    	cout<<endl;
    
    	cout<<"      multi ";
    	cout<<c.multi(3,4);
    	cout<<endl;
    
    	Interface *i1=&c;
    	Interface2 *i2 =&c;
    	cout<<i1->add(2,4);
    		cout<<endl;
    	cout<<i2->multi(7,8);
    		cout<<endl;
    		i1->print();
    		i2->print();
    	system("pause");
    	return 0;
    }
    

      

    #include<iostream>
    
    using namespace std;
    //编写一个C++程序, 计算程序员( programmer )工资
    //	1 要求能计算出初级程序员( junior_programmer ) 中级程序员 ( mid_programmer )高级程序员( adv_programmer)的工资
    //	2 要求利用抽象类统一界面,方便程序的扩展, 比如:新增, 计算 架构师 (architect ) 的工资
    //
    
    class saraly
    {
    public:
    	virtual void salary()=0;
    
    };
    class junior_programmer:public saraly
    {
    public:
    	junior_programmer(char *name,char *kind,int sal)
    	{
    		this->kind=kind;
    		this->name=name;
    		this->sal=sal;
    	}
    	virtual void salary()
    	{
    		cout<<"the salary of the junior_programmer is "<<sal<<endl;
    	}
    protected:
    private:
    	char *name ;
    	char *kind;
    	int sal;
    };
    class mid_programmer:public saraly
    {
    public:
    	mid_programmer(char *name,char *kind,int sal)
    	{
    		this->kind=kind;
    		this->name=name;
    		this->sal=sal;
    	}
    	virtual void salary()
    	{
    		cout<<"the salary of the mid_programmer is "<<sal<<endl;
    	}
    protected:
    private:
    	char *name ;
    	char *kind;
    	int sal;
    };
    
    class adv_programmer:public saraly
    {
    public:
    	adv_programmer(char *name,char *kind,int sal)
    	{
    		this->kind=kind;
    		this->name=name;
    		this->sal=sal;
    	}
    	virtual void salary()
    	{
    		cout<<"the salary of the adv_programmer is "<<sal<<endl;
    	}
    protected:
    private:
    	char *name ;
    	char *kind;
    	int sal;
    };
    
    void Getsalary(saraly *base)
    {
    	base->salary();
    }
    int main()
    {
    	
    	junior_programmer jp("Alice ","junior ",400);
    
    	mid_programmer mp("Alenx","mid",8000);
    	adv_programmer ap("Juster", "adv",1500);
    	Getsalary(&jp);
    	Getsalary(&mp);
    	Getsalary(&ap);
    	system("pause");
    	return 0;
    }
    

      

  • 相关阅读:
    使用Razor视图引擎来生成邮件内容
    Asp .Net Core 2.0 登录授权以及多用户登录
    简单几步,提升.Net Core的开发效率
    百万数据测试 Entity Framework 到底有多慢
    纸壳CMS(ZKEACMS)体验升级,快速创建页面,直接在页面中修改内容
    ZKEACMS 配置使用 HTTPS
    使用 jQuery.Pin 垂直滚动时固定导航
    底层的增删查改
    关于hangfire的使用
    巧用 CSS 实现酷炫的充电动画
  • 原文地址:https://www.cnblogs.com/xiaochige/p/6622470.html
Copyright © 2020-2023  润新知