调查统计员(源码6)

// ****************************************************************************
//  Investigator_Amount.h   version:  1.0     date: 12/09/2005
//  ---------------------------------------------------------------------------
//  Summary:
//  ---------------------------------------------------------------------------
//  Copyright (C) LYH_Studio @ 2005 - All Rights Reserved
// ****************************************************************************
//
// ****************************************************************************


#ifndef _LYH_STUDIO_INVESTIGATOR_Amount
#define _LYH_STUDIO_INVESTIGATOR_Amount

//include file
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

#include "Investigator_Base.h"


namespace Investigator
{
 
 //class define
 /*this class derive from basic class Investigator_Base,generate its useful member functions
 *this class also has some useful functions ,such as InvtAndDrawAmount(),InvtAndNotice(),InvtAnd_N_DM()
 *and function SetCharInvt(string) is used for set focus charators which user want to detected or investigated.This function must call befour investigate class functions
 */
 class Investigator_Amount :public Investigator_Base
 {
 public :
  Investigator_Amount();
  Investigator_Amount(const string &strData, const string &strCI);
  virtual ~Investigator_Amount();
  
  
  virtual bool InvtAndNotice(const stringEx &strItemShow) throw(char*);
  virtual bool InvtAndDrawMast(const stringEx &strItemShow) throw(char*);
  virtual bool InvtAnd_N_DM(const stringEx &strItemShow) throw(char*);
  
  virtual bool InvtAndNoticeAll() ;
  virtual bool InvtAndDrawMastAll() ;
  virtual bool InvtAnd_N_DMAll() ;
  
  
  //内部类定义
  /*--------->class @ Command @ discription<-----------*
  *@name: Command
  *@member functions:
  */
  static class Command {
 public:
  enum command {NOTICE = 1, PICTURE = 2};
  
  enum com_err {COM_ERR_RELATIVE_ELEMENT_NO_DEFINETION};
  static const char *m_comErr[1];
  
  /*------>Function @ GetParameter @ discription <---------
  *@name:int GetParameter(const stringEx &parameter) const throw(char*);
  *@parameter:const stringEx &parameter =====>>the paremeter of console line
  *@purpose:get the mix bitset correspond to the parameter which client has selected
  *@return value:int
  */
  static int GetParameter(const stringEx &parameter) throw(char*);
  };
 };
}

#endif

 

/

// ****************************************************************************
//  Investigator_Amount.cpp   version:  1.0     date: 12/09/2005
//  ---------------------------------------------------------------------------
//  Summary:
//  ---------------------------------------------------------------------------
//  Copyright (C) LYH_Studio @ 2005 - All Rights Reserved
// ****************************************************************************
//
// ****************************************************************************

//include filE
#include <iostream>
#include <cassert>
using std::cout;
using std::cin;
using std::endl;
#include <windows.h>

#include "MainInclude.h"              //加载主头文件
#include "Investigator_Amount.h"
using namespace Investigator;

const char *Investigator_Amount::Command::m_comErr[1] = {"统计选项没定义!"};

 

Investigator_Amount::Investigator_Amount() : Investigator_Base() {
}

Investigator_Amount::Investigator_Amount(const string &strData, const string &strCI) : Investigator_Base(strData,strCI) {
}

Investigator_Amount::~Investigator_Amount() {
}

bool Investigator_Amount::InvtAndNotice(const stringEx &strItemShow) throw(char*) {
 //排错
 if (!strItemShow.IsSubCharSet(m_strCI)) {
  throw Command::m_comErr[Command::COM_ERR_RELATIVE_ELEMENT_NO_DEFINETION];
 }
 
 
 int length = strItemShow.length();
 int *charNum = new int[length];
    unsigned short index;
 
 
 for (index = 0; index < length; index++)
 {
  charNum[index] = InvtChar(strItemShow[index]);
 }
 
 index = 0;
 while (index < length)
 {
  cout << "<选 " << strItemShow[index] << " 有> --->" << charNum[index] << " 人 " << endl;
  index ++;
 }
 
 delete[] charNum;
 
 return true;
}


bool Investigator_Amount::InvtAndDrawMast(const stringEx &strItemShow) throw(char*) {
 //排错
 if (!strItemShow.IsSubCharSet(m_strCI)) {
  throw Command::m_comErr[Command::COM_ERR_RELATIVE_ELEMENT_NO_DEFINETION];
 }
 
 
 int length = strItemShow.length();
 int *charNum = new int[length];
    short index;
 
 
 for (index = 0; index < length; index++)
 {
  charNum[index] = InvtChar(strItemShow[index]);
 }
 
 int total = m_strData.GetSubStringNum(DATA_DIVIDER);
 short flag = 0;
 for (index = 0; index < length; index++)
 {
  cout << strItemShow[index] << '|';
  
  const int  num = charNum[index] * (Investigator_Amount::WINDOWWIDTH -2) / total;
  int times;
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
  for (times =0; (times < (Investigator_Base::WINDOWWIDTH-2) / 5) && (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_BLUE|FOREGROUND_INTENSITY);
  for ( ; (times < 2*(Investigator_Base::WINDOWWIDTH-2) / 5) && (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_GREEN|FOREGROUND_INTENSITY);
  for ( ; (times < 3*(Investigator_Base::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
  for ( ; (times < 4*(Investigator_Base::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_RED|FOREGROUND_INTENSITY);
  for ( ; times < Investigator_Base::WINDOWWIDTH-3 && (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE);
  
  cout << endl;
 }

 
 delete[] charNum;
 
 return true;
 
}

bool Investigator_Amount::InvtAnd_N_DM(const stringEx &strItemShow) throw(char*) {
 //排错
 if (!strItemShow.IsSubCharSet(m_strCI)) {
  throw Command::m_comErr[Command::COM_ERR_RELATIVE_ELEMENT_NO_DEFINETION];
 }
 
 
 int length = strItemShow.length();
 assert(length >= 0);
 
 int *charNum = new int[length];
    short index;
 int total = 0;
 
 
 for (index = 0; index < strItemShow.length(); index++)
 {
  charNum[index] = InvtChar(strItemShow[index]);
  total += charNum[index];
 }
 
 
    for (int times = 0; times < WINDOWWIDTH; times++)
 {
  cout << '_';
 }
 
 total = m_strData.GetSubStringNum(DATA_DIVIDER);
 short flag = 0;
 for (index = 0; index < length; index++)
 {
  cout << strItemShow[index] << '|';
  
  const int  num = charNum[index] * (Investigator_Amount::WINDOWWIDTH -2) / total;
  int times;
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
  for (times =0; (times < (Investigator_Amount::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_BLUE|FOREGROUND_INTENSITY);
  for ( ; (times < 2*(Investigator_Amount::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_GREEN|FOREGROUND_INTENSITY);
  for ( ; (times < 3*(Investigator_Amount::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
  for ( ; (times < 4*(Investigator_Amount::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_RED|FOREGROUND_INTENSITY);
  for ( ; times < Investigator_Amount::WINDOWWIDTH-3 && (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE);
  
  cout << endl;
 }
 
    for (times = 0; times<WINDOWWIDTH; times++)
 {
  cout<<'_';
 }
 
 index = 0;
 while(index < length)
 {
  cout << "选 " << strItemShow[index] << " 有 " << charNum[index] << " 人 " << endl;
  index ++;
 }
 
 delete[] charNum;
 
 return true;
 
}

bool Investigator_Amount::InvtAndNoticeAll() {
 int length = m_strCI.length();
 int *charNum = new int[length];
    short index;
 
 
 for (index = 0; index < length; index++)
 {
  charNum[index] = InvtChar(m_strCI[index]);
 }
 

 index = 0;
 while (index < length)
 {
  cout << "<选 " << m_strCI[index] << " 有> --->" << charNum[index] << " 人 " << endl;
  index ++;
 }
 
 delete[] charNum;
 
 return true;
}

bool Investigator_Amount::InvtAndDrawMastAll() {
 int length = m_strCI.length();
 int *charNum = new int[length];
    short index;
 
 
 for (index = 0; index < length; index++)
 {
  charNum[index] = InvtChar(m_strCI[index]);
 }
 
 
 int total = m_strData.GetSubStringNum(DATA_DIVIDER);
 short flag = 0;
 for (index = 0; index < length; index++)
 {
  cout << m_strCI[index] << '|';
  
  const int  num = charNum[index] * (Investigator_Amount::WINDOWWIDTH -2) / total;
  int times;
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
  for (times =0; (times < (Investigator_Amount::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_BLUE|FOREGROUND_INTENSITY);
  for ( ; (times < 2*(Investigator_Amount::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_GREEN|FOREGROUND_INTENSITY);
  for ( ; (times < 3*(Investigator_Amount::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
  for ( ; (times < 4*(Investigator_Amount::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_RED|FOREGROUND_INTENSITY);
  for ( ; times < Investigator_Amount::WINDOWWIDTH-3 && (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE);
  
  cout << endl;
 }
 
 
 delete[] charNum;
 
 return true;
}

bool Investigator_Amount::InvtAnd_N_DMAll() {
 int length = m_strCI.length();
 assert(length >= 0);
 
 int *charNum = new int[length];
    short index;
 int total = 0;
 
 
 for (index = 0; index < length; index++)
 {
  charNum[index] = InvtChar(m_strCI[index]);
  total += charNum[index];
 }
 
 
    for (int times = 0; times < WINDOWWIDTH; times++)
 {
  cout << '_';
 }
 
 total = m_strData.GetSubStringNum(DATA_DIVIDER);
 short flag = 0;
 for (index = 0; index < length; index++)
 {
  cout << m_strCI[index] << '|';
  
  const int  num = charNum[index] * (Investigator_Amount::WINDOWWIDTH -2) / total;
  int times;
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
  for (times =0; (times < (Investigator_Amount::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_BLUE|FOREGROUND_INTENSITY);
  for ( ; (times < 2*(Investigator_Amount::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_GREEN|FOREGROUND_INTENSITY);
  for ( ; (times < 3*(Investigator_Amount::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
  for ( ; (times < 4*(Investigator_Amount::WINDOWWIDTH-2) / 5)&& (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_RED|FOREGROUND_INTENSITY);
  for ( ; times < Investigator_Amount::WINDOWWIDTH-3 && (times < num); times++) {
   cout << '*';
  }
  
  SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
   FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE);
  
  cout << endl;
 }
 
    for (times = 0; times<WINDOWWIDTH; times++)
 {
  cout<<'_';
 }
 
 index = 0;
 while(index < length)
 {
  cout << "选 " << m_strCI[index] << " 有 " << charNum[index] << " 人 " << endl;
  index ++;
 }
 
 delete[] charNum;
 
 return true;
}


//---------------------------------------------------------------------------------------->>

int Investigator_Amount::Command::GetParameter(const stringEx &parameter) throw(char*) {
 //确定没有额外的字符
 if (!parameter.IsSubCharSet(string("-pnal"))) {
  throw errMsg[ERR_MSG_PARAMETER_ERROR];
 }

 //因为参数前有连接符,所以定义一个真实参数数目与检测所得数目的误差值
 const short offset = 1;
 
 //获得参数数目
 int itemNum = parameter.GetSubStringNum(PARAMETER_DIVIDER);
 int selection = 0;   //保存选项的枚举类型
 
 stringEx tempStr;
 while (itemNum != offset) {
  tempStr = parameter.GetSubString(itemNum, PARAMETER_DIVIDER);
  
  if (tempStr == "n") {
   selection |= NOTICE;
   
   //item自减,用于标记已经读取一个命令,
   //直到变为1(还有一个子串参数)
   itemNum--;
  }
  else if (tempStr == "p") {
   selection |= PICTURE;
   
   itemNum--;
  }
  else {
   throw errMsg[ERR_MSG_PARAMETER_ERROR];
  }
 }
 
 return selection;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值