C++.polymorphism.Simulation of JAVA's DB Interface

==========main.h==========

#pragma once
#include<iostream>
#include <typeinfo>
using namespace std;
class DataBase{
public:
	virtual void Open()=0;
	virtual void Close()=0;
	virtual void Create()=0;
	virtual void Read()=0;
	virtual void Update()=0;
	virtual void Delete()=0;
};
void main();
void f(DataBase &);


=========Access.h========

#pragma once
#include "main.h"
class Access:public DataBase{
public:
	void Open();
	void Close();
	void Create();
	void Read();
	void Update();
	void Delete();
};

==========Disk.h=========

#pragma once
#include "main.h"
class Disk:public DataBase{
public:
	void Open();
	void Close();
	void Create();
	void Read();
	void Update();
	void Delete();
};

=========SQL.h==========

#pragma once
#include "main.h"
class SQL:public DataBase{
public:
	void Open();
	void Close();
	void Create();
	void Read();
	void Update();
	void Delete();
};

========MySQL.h=========

#pragma once
#include "main.h"
class MySQL:public DataBase{
public:
	void Open();
	void Close();
	void Create();
	void Read();
	void Update();
	void Delete();
};

============= Access.cpp===========

#include"Access.h"
void Access::Open(){
	cout<<"Access has been called successfully!"<<endl;
}
void Access::Close(){
	cout<<"Access has been called successfully!"<<endl;
}
void Access::Create(){
	cout<<"Access has been called successfully!"<<endl;
}
void Access::Read(){
	cout<<"Access has been called successfully!"<<endl;
}
void Access::Update(){
	cout<<"Access has been called successfully!"<<endl;
}
void Access::Delete(){
	cout<<"Access has been called successfully!"<<endl;
}


=============Disk.cpp============

#include"Disk.h"
void Disk::Open(){
	cout<<"Disk has been called successfully!"<<endl;
}
void Disk::Close(){
	cout<<"Disk has been called successfully!"<<endl;
}
void Disk::Create(){
	cout<<"Disk has been called successfully!"<<endl;
}
void Disk::Read(){
	cout<<"Disk has been called successfully!"<<endl;
}
void Disk::Update(){
	cout<<"Disk has been called successfully!"<<endl;
}
void Disk::Delete(){
	cout<<"Disk has been called successfully!"<<endl;
}

========MySQL.cpp=========

#include"MySQL.h"
void MySQL::Open(){
	cout<<"MySQL has been called successfully!"<<endl;
}
void MySQL::Close(){
	cout<<"MySQL has been called successfully!"<<endl;
}
void MySQL::Create(){
	cout<<"MySQL has been called successfully!"<<endl;
}
void MySQL::Read(){
	cout<<"MySQL has been called successfully!"<<endl;
}
void MySQL::Update(){
	cout<<"MySQL has been called successfully!"<<endl;
}
void MySQL::Delete(){
	cout<<"MySQL has been called successfully!"<<endl;
}


========SQL.cpp=========

#include"SQL.h"
void SQL::Open(){
	cout<<"SQL has been called successfully!"<<endl;
}
void SQL::Close(){
	cout<<"SQL has been called successfully!"<<endl;
}
void SQL::Create(){
	cout<<"SQL has been called successfully!"<<endl;
}
void SQL::Read(){
	cout<<"SQL has been called successfully!"<<endl;
}
void SQL::Update(){
	cout<<"SQL has been called successfully!"<<endl;
}
void SQL::Delete(){
	cout<<"SQL has been called successfully!"<<endl;
}


========main.cpp=========

#include "Access.h"
#include "Disk.h"
#include "SQL.h"
#include "MySQL.h"
void main(){
	char n;
	Access A; Disk D; MySQL M; SQL S;
	cout<<"Please choose a kind of DB (Access(A) Disk(D) SQL(S) MySQL(M)):";
	cin>>n;
	switch (n)
	{
		case 'A':
		case 'a':
			f(A);
			break;
		case 'D':
		case 'd':
			f(D);
			break;
		case 'S':
		case 's':
			f(S);
			break;
		case 'M':
		case 'm':
			f(M);
			break;
		default:
			cout<<"Error input!"<<endl;
	}
}
void f(DataBase &F){
	cout<<"The type of current object is:"<<typeid(F).name()<<endl;
	F.Open();
	F.Close();
	F.Create();
	F.Read();
	F.Update();
	F.Delete();
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值