鱼C论坛

 找回密码
 立即注册

C++学习,第三十三课

已有 529 次阅读2014-8-26 08:54 |个人分类:作业

#include<iostream>
#include<string>

class Company
{
public:
    Company(std::string theName);
    virtual void print();

protected:
    std::string name;
};

class TecCompany :public Company
{
public:
    TecCompany(std::string name, std::string theproduct);
    virtual void print();
private:
    std::string product;
};

Company::Company(std::string theName)
{
    name=theName;
}

TecCompany::TecCompany(std::string theName, std::string product) :Company(theName)
{
    this->product = product;
}

void Company::print()
{
    std::cout << "我是" << name << "公司\n\n";
}

void TecCompany::print()
{
    std::cout << "我是" << name << "公司,我的产品是:" << product<<"\n\n";
}

int main()
{
    Company *company = new Company("Microsoft");
    company->print();
    delete company;
    company = NULL;

    company = new TecCompany("Apple","iPad");
    company->print();
    delete company;
    company = NULL;

    system("pause");
    return 0;
}

路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-27 18:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部