5.12

#include <iostream>

#include <string>

using namespace std;

class Document {

public:

    Document() {

    }

    Document(char* nm);

    char* name;

    void PrintNameOf();

};

Document::Document(char* nm) {

    name = new char[strlen(nm) + 1];

    strcpy(name, nm);

};

void Document::PrintName0f() {

    cout << name << endl;

}

class Book :public Document {

public:

    Book(char* nm, long pagecount);

    void PrintNameOf();

private:

    long pageCount;

};

Book::Book(char* nm, long pagecount) :

    Document(nm) {

    pageCount = pagecount;

}

void Book::PrintNameOf() {

    cout << "Name Of Book:";

    Document::PrintNameOf();

}

int main() {

    Document a("Document1");

    Book b("Book1", 100);

    b.PrintNameOf();

    return 0;

}

posted @ 2023-05-12 20:32  张佳木  阅读(21)  评论(0)    收藏  举报