C++语言题目2

IT小小龙 posted @ 2014年4月04日 22:32 in C++ with tags 继承 抽象类 , 631 阅读
//某软件需要把运行过程中的一些日志信息(发生时间,类型,内容)进行记录,
//采用面向对象思想,实现了一个日志类Log, Log类中有saveLog方法存储日志
//信息,现在假设该软件支持日志信息的多种存储方式,例如可以将日志信息
//存储进文本文件,也可以放入某数据库中,Log类的设计尽量满足面向对象的
//开-闭原则(支持对新的存储方式的扩展,但Log类的代码不修改),请设计并实现。
#include"iostream"
#include"string"
using namespace std;

class Log{
public:
  virtual void saveLog() = 0;
};

class LogSaveToFile:public Log
{
private:
  string content;
public:
  LogSaveToFile(string logcontent)
  {
    content = logcontent;
  }
  void saveLog()
  {
    cout<<"这是日志内容:"<<content<<endl;
    cout<<"已经把日志写到文本文件。"<<endl;
  }
};

class LogSaveToSQLServer:public Log
{
private:
  string content;
public:
  LogSaveToSQLServer(string logcontent)
  {
    content = logcontent;
  }
  void saveLog()
  {
    cout<<"这是日志内容:"<<content<<endl;
    cout<<"已经把日志写到SQL Server。"<<endl;
  }
};

int main()
{
  cout<<"1、把日志写到文本文件:"<<endl;
  LogSaveToFile lstf("abc");
  lstf.saveLog();
  cout<<"2、把日志写到SQL Server:"<<endl;
  LogSaveToSQLServer ltss("abc");
  ltss.saveLog();
  return 1;
}
Avatar_small
HDFC Forex Card Logi 说:
2022年8月07日 23:24

HDFC is a National Cum international Bank which holds many services for its customers, and Forex Card is one such option that HDFC bank does provide in all the various streams and based on the customer eligibility and requirements the Forex Card is issued which does help them when they are on their way to a foreign country. HDFC Forex Card Login Having a Forex Card during your visit abroad from India does help you in many ways, as they also come with insurance which protects your loaded money always. Customers can use the options to check their balance and get it loaded timely so that you will not be short of money during your business or family trip to any country outside India.

Avatar_small
NCERT Term 2 Sample 说:
2022年9月26日 14:16

NCERT Term 2 Sample Paper Class 9 Analysis of skills is done through conducting Examination for 9th class students as Term-2 Exams for every subject.Every Education Board conduct Examinations for students after completion of Teaching the limited range of syllabus i.e., 50% and 100% of syllabus to analyse the skills of students in the particular subject. NCERT Term 2 Sample Paper Class 9 Analysis of skills is done through conducting Examination for 9th class students as Term-2 Exams for every subject.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter