⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.cpp

📁 软件的名称:AA制用餐管理系统 软件的功能:管理消费中产生的费用
💻 CPP
字号:
#include <cstdio>
#include <cstring>
#include <math.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
#include <ctype.h>
#include "function.h"
/*
function:设置输入窗口颜色
param:color颜色代号
return:无返回值
*/
void function::SetTextCorlor(unsigned short int color)
{
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hOut,color);
}
/*
function:获得光标当前位置
param:x,y决定光标坐标
return:无返回值
*/
void function::GetXY(int *x,int *y)
{
	HANDLE hOut;	// 获取标准输出设备句柄
	CONSOLE_SCREEN_BUFFER_INFO bInfo;
	COORD pos;
	hOut = GetStdHandle(STD_OUTPUT_HANDLE);
   	GetConsoleScreenBufferInfo( hOut, &bInfo );	
	pos = bInfo.dwCursorPosition;
	*x = pos.X;
	*y = pos.Y;
}
/*
function:将光标定位到控制台上的某个位置
param:xcursor,ycursor决定光标要定位到的坐标
return:无返回值
*/
void function::SetXY(int xcursor, int ycursor)
{
	COORD pos = {xcursor,ycursor};
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);	// 获取标准输出设备句柄
	SetConsoleCursorPosition(hOut, pos);
}

/*
function:读取系统当前时间并显示
param:无参数
return:无返回值
*/
void function::GetTime()   
  {   
        time_t   tval;   
        struct   tm   *now;   
        /*   Get   current   date   and   time   */   
        tval = time(NULL);   
        now = localtime(&tval);   
        printf("CurrentTime: %4d-%d-%02d \n",
			now->tm_year+1900,now->tm_mon+1,now->tm_mday);   
  }

/*
function:画一个输入框
param:color设置输入框颜色;xcursor,ycursor决定画输入框的位置
return:无返回值
*/
void function::DrawInputFrame(unsigned short color,int xcursor,int ycursor,int len)
{
	int i;
	SetXY(xcursor,ycursor);
	SetTextCorlor(color);
	for(i=0;i<len;i++)
	{
	    printf(" ");
	}
}

/*
function:清屏区域函数
param:(fromX,fromY)区域开始坐标,(toX,toY)区域终点坐标
return:无返回值
*/
void function::ClearScreen(int fromX,int fromY,int toX,int toY)
{
	int i,j;
    int row,line;//row代表行,line代表列
	row=toY-fromY+1;
	line=toX-fromX+1;
	for(i=0;i<row;i++)
	{		
		for(j=0;j<line;j++)
		{
			SetXY(fromX+j,fromY+i);	
			printf(" ");
		}
	}
}
 
//载入条
void function::Loading()
{
	int i;
	DrawInputFrame(255,10,10,50);
	for(i=1;i<=50;i++)
	{
		Sleep(80);
		SetXY(35,9);
		SetTextCorlor(10);
		printf("%d%%",2*i);
		DrawInputFrame(202,10,10,i);
	}
    SetTextCorlor(15);	
}
/*
function:设置文本颜色
param:color颜色代号
return:无返回值
*/
void function::SetCorlor(short int color)
{
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hOut,color);
}

/*
function:框控制定长输入
param:str[]存放输入的字符串,len输入字符串的最大长度
return:无返回值
*/

int function::input(char str[], int len)
{
	int i=0;
	int ch;
	while(1)
	{
		ch=getch();
		if(ch==0xe0)
		{
			ch=getch();//方向键不接收	
			//continue;
		}
		else if(ch==27)
		{
			return 1;//按ESC退出
		}
		else if(ch==8)
		{
			if(i>0)
			{
				printf("\b");//光标前移,然后用空格代替光标当前位置的字符
				printf(" ");
				printf("\b");
				i--;
				str[i]='\0';
			}
		}
		else if(ch==13)
		{
			str[i]='\0';
			return 0;
		}
		else if(i<len)
		{
			if(isprint(ch))//isprint(ch)判断ch是否是可打印字符,不包括Tab键
			{
				str[i++]=ch;
				putchar(ch);
			}
		}
	}
	return 0;
}


//输入的数字超过10
int function::InputValidate(char str[],int begin,int to)
{
	int len;
	int i=0;
	int value=0;//0为正确
	len=strlen(str);
	if(len<=0)
		return value=1;//为空
	else
	{
		while(i<len)
		{
			if(!(str[i]>=48 && str[i]<=57))
				return value=2;//不是数字,即非法字符
			i++;
		}
	}
	if(len>0)
	{
		if(atoi(str)<begin || atoi(str)>to)
		  return value=3;//超出范围
	}
	return value;
}

















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -