题目说明:
题目解读:
其实就是非常简单的类用法:继承、抽象类
示例代码:
// Day13_AbstractClasses.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <Windows.h>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
class BOOK
{
protected:
string title;
string author;
public:
BOOK( string t, string a )
{
title = t;
author = a;
};
virtual void display() = 0;
};
class MyBook : public BOOK
{
public:
MyBook( string title, string author, int price ): BOOK( title, author )
{
this->title = title;
this->author = author;
this->price = price;
};
public:
void display()
{
cout << "Title:" << title << endl;
cout << "Author:" << author << endl;
cout << "Price:" << price << endl;
}
private:
int price;
};
//by zhaocl
int main()
{
string title, author;
int price;
getline( cin, title );
getline( cin, author );
cin >> price;
MyBook novel( title, author, price );
novel.display();
system( "pause" );
return 0;
}