神秘博客

C++ Primer Plus [第六版]第14章复习题答案

2

#ifndef FRABJOUS_H_
#define FRABJOUS_H_

#include <iostream>
#include <string>

class Frabjous
{
private:
  std::string fab;
public:
  Frabjous(const char *s = "C++") :fab(s) {}
  virtual void tell() { std::cout << fab; }
};


class Gloam
{
private:
  int glip;
  Frabjous fb;
public:
  Gloam(int g = 0, const char *s = "C++") :glip(g), fb(s) {}
  Gloam(int g, const Frabjous &f) :glip(g), fb(f) {}
  void tell();
};

#endif
#include "frabjous.h"

void Gloam::tell()
{
  fb.tell();
  std::cout << " " << glip << std::endl;
}

3

#include <iostream>
#include <string>

class Frabjous
{
private:
  std::string fab;
public:
  Frabjous(const char *s = "C++") :fab(s) {}
  virtual void tell() { std::cout << fab; }
};

class Gloam :private Frabjous
{
private:
  int glip;
public:
  Gloam(int g = 0, const char *s = "C++") :glip(g), Frabjous(s) {}
  Gloam(int g, const Frabjous &f) :glip(g), Frabjous(f) {}
  void tell();
};

void Gloam::tell()
{
  Frabjous::tell();
  std::cout << " " << glip << std::endl;
}

int main()
{
  Gloam p1(24, "神秘");
  p1.tell();

  system("pause");
  return 0;
}

4

class Stack<Worker *>
{
private:
  enum { MAX = 10 };    
  Worker * items[MAX];
  int top;          
public:
  Stack();
  bool isempty();
  bool isfull();
  bool push(const Worker * & item);
  bool pop(Worker * & item);
};

 

版权说明:
点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注

觉得文章有用就请我吃包辣条吧

微信扫一扫打赏