📄 main.cpp
字号:
#include "SparseTable.h"
#include "Show.h"
#include "windows.h"
#include "stdlib.h"
#include "time.h"
#include "KeyChar.h"
#include "conio.h"
#include "string.h"
#include "stdio.h"
void Create(CSparseTable & sparseTable,int & flagEnglish)
{
CKeyChar key;
int flag=flagEnglish;
int data[2];
int i,j,chese=27;
char str[20];
char * string[]={"创建稀疏矩阵:",
"Create a sparsity matrix:",
"请输入矩阵的行数:",
"Please input the number of the matrix lines: ",
"请输入矩阵的列数:",
"Please input the number of the matrix rows:",
"稀疏矩阵如下:",
"The following is the sparsity matrix:",
"创建成功!",
"Success",
"创建失败!",
"Fail",
"按 Esc 键切换到英文界面",
"Press the key Esc ,show a chinese interface."};
int specialkey[1]={27};
key.SetStyle(2,KEY_NUMBER);
key.SetStyle(specialkey,1);
i=0;
j=0;
cout<<string[12+flagEnglish]<<endl;
cout<<string[flagEnglish]<<endl;
while(1)
{
if(flag!=flagEnglish)
{
system("cls");
flag=flagEnglish;
cout<<string[12+flagEnglish]<<endl;
cout<<string[flagEnglish]<<endl;
for(j=0;j<i;j++)
cout<<string[2+j*2+flagEnglish]<<'\n'<<data[j]<<endl;
}
if(chese==27)
{
cout<<string[2+i*2+flagEnglish]<<endl;
key.GetKey(str);
if(strlen(str))
printf("%s",str);
}
while(!(chese=key.GetKey()));
if(chese==KEY_ENTER)
{
cout<<endl;
key.GetKey(data[i]);
key.SetStar();
chese=27;
i++;
}
else if(chese==27)
flagEnglish=(flagEnglish+1)%2;
if(i>=2)
break;
}
cout<<data[0]<<','<<data[1]<<endl;
if(sparseTable.Creat(0,data[0],data[1]))
{
cout<<string[8+flagEnglish]<<endl;
cout<<string[6+flagEnglish]<<endl;
sparseTable.ShowTable();
}
else
cout<<string[10+flagEnglish]<<endl;
}
void Show(CSparseTable & sparseTable,int & flagEnglish)
{
char * string[]={"显示稀疏矩阵的存储:",//0
"Show tho storage of the sparsity matrix:",
"稀疏矩阵如下:",//2
"the following is the sparsity matrix:",
"显示失败!",//4
"Fail",
"稀疏矩阵的存储:",//6
"The storage of the sparsity matrix:"};
cout<<string[flagEnglish]<<endl;
if(sparseTable.IsEmpty())
cout<<string[4+flagEnglish]<<endl;
else
{
cout<<string[2+flagEnglish]<<endl;
sparseTable.ShowTable();
cout<<string[6+flagEnglish]<<endl;
sparseTable.Display();
}
}
void Turn(CSparseTable & sparseTable,int & flagEnglish)
{
char * string[]={"稀疏矩阵转置:",//0
"Turn over the sparsity matrix :",
"稀疏矩阵如下:",//2
"the following is the sparsity matrix:",
"显示失败!",//4
"Fail",
"转置后的稀疏矩阵:",//6
"the turned sparsity matrix :"};
cout<<string[flagEnglish]<<endl;
if(sparseTable.IsEmpty())
cout<<string[4+flagEnglish]<<endl;
else
{
cout<<string[2+flagEnglish]<<endl;
sparseTable.ShowTable();
sparseTable.TurnOver();
cout<<string[6+flagEnglish]<<endl;
sparseTable.ShowTable();
}
}
void Delete(CSparseTable & sparseTable,int & flagEnglish)
{
CKeyChar key;
int flag=flagEnglish;
int chese=27;
char str[4];
char * string[]={"删除稀疏矩阵:",//0
"Delete the sparsity matrix:",
"删除成功!",//2
"Success",
"删除失败!",//4
"Fail",
"按 Esc 键切换到英文界面",//6
"Press the key Esc ,show a chinese interface.",
"你确定删除矩阵吗?(Y/y) :",//8
"Are you sure to delete the matric ? (Y/y) : "};
int specialkey[1]={27};
key.SetStyle(1,KEY_ANY);
key.SetStyle(specialkey,1);
cout<<string[6+flagEnglish]<<endl;
cout<<string[flagEnglish]<<endl;
cout<<string[8+flagEnglish]<<endl;
while(1)
{
if(flag!=flagEnglish)
{
system("cls");
flag=flagEnglish;
cout<<string[6+flagEnglish]<<endl;
cout<<string[flagEnglish]<<endl;
cout<<string[8+flagEnglish]<<endl;
}
while(!(chese=key.GetKey()));
if(chese==KEY_ENTER)
{
//cout<<ch<<endl;
cout<<endl;
key.GetKey(str);
if(str[0]=='Y'||str[0]=='y')
{
sparseTable.Destroy();
cout<<string[2+flagEnglish]<<endl;
break;
}
else
{
cout<<string[4+flagEnglish]<<endl;
break;
}
}
//if(chese=='Y'||chese=='y')
// ch=chese;
//ch=chese;
if(chese==27)
flagEnglish=(flagEnglish+1)%2;
}
}
void Input(CSparseTable & sparseTable,int & flagEnglish)
{
CKeyChar key;
int flag=flagEnglish;
int data[3];
int i,j,chese=27;
char str[20];
char * string[]={"输入矩阵的元素:",//0
"Input element of the sparsity matrix:",
"请输入矩阵的行号:",//2
"Please input the line'number :",
"请输入矩阵的列号:",//4
"Please input the row'number :",
"请输入数据:",//6
"Please input the data :",
"稀疏矩阵如下:",//8
"The following is the sparsity matrix :",
"成功!",//10
"Success",
"失败!",//12
"Fail",
"按 Esc 键切换到英文界面。\n按Q/q键返回到主菜单。",//14
"Press the key Esc ,show a chinese interface.\nPress Q/q key,return to the main menu.",
"按任意键,继续输入。",//16
"Press any key,continue to input."};
int specialkey[3]={27,'Q','q'};
key.SetStyle(2,KEY_NUMBER);
key.SetStyle(specialkey,3);
while(chese!='Q'&&chese!='q')
{
system("cls");
i=0;
j=0;
cout<<string[14+flagEnglish]<<endl;
cout<<string[flagEnglish]<<endl;
cout<<string[8+flagEnglish]<<endl;
sparseTable.ShowTable();
while(1)
{
if(sparseTable.IsEmpty())
{
cout<<string[12+flagEnglish]<<endl;
chese='Q';
break;
}
if(flag!=flagEnglish)
{
system("cls");
flag=flagEnglish;
cout<<string[14+flagEnglish]<<endl;
cout<<string[flagEnglish]<<endl;
cout<<string[8+flagEnglish]<<endl;
sparseTable.ShowTable();
for(j=0;j<i;j++)
cout<<string[2+j*2+flagEnglish]<<'\n'<<data[j]<<endl;
}
if(chese==27)
{
cout<<string[2+i*2+flagEnglish]<<endl;
key.GetKey(str);
if(strlen(str))
printf("%s",str);
}
while(!(chese=key.GetKey()));
if(chese=='q'||chese=='Q')
break;
if(chese==KEY_ENTER)
{
cout<<endl;
key.GetKey(data[i]);
key.SetStar();
chese=27;
i++;
}
else if(chese==27)
flagEnglish=(flagEnglish+1)%2;
if(i>=3)
{
break;
}
}
if(chese!='q'&&chese!='Q'&&!sparseTable.IsEmpty())
{
if(sparseTable.SetData(data[0],data[1],data[2]))
{
cout<<string[10+flagEnglish]<<endl;
cout<<string[8+flagEnglish]<<endl;
sparseTable.ShowTable();
}
else
cout<<string[12+flagEnglish]<<endl;
cout<<string[16+flagEnglish]<<endl;
getch();
}
}
}
void main()
{
char * pstring0[]={" 数据结构研究 功能演示平台 ",//0
"┏━━━━━━━━━━━━━━━━━━━━┓",//1
"┃ 程序信息 ┃",//2
"┠─────┬──────────────┨",//3
"┃设计目的:│ 用链表实现二维数组 ┃",//4
"┠─────┼──────────────┨",//5
"┃程序功能:│ 稀疏矩阵的存储 ┃",//6
"┠─────┼──────────────┨",//7
"┃指导教师:│ 马春江老师 ┃",//8
"┠─────┼──────────────┨",//9
"┃程序设计:│ 马哲江 ┃",//10
"┠─────┼──────────────┨",//11
"┃设计日期:│ 2005年 4月17日 ┃",//12
"┠─────┴──────────────┨",//13
"┃湖北汽车工业学院电系2005年数据结构双语班┃",//14
"┗━━━━━━━━━━━━━━━━━━━━┛",//15
"┠─────┴──────────────┨",//16
"┃ ┃",//17
"┃ 1: 创建稀疏矩阵 ┃",//18
"┃ 2: 删除稀疏矩阵 ┃",//19
"┃ 3: 稀疏矩阵转置 ┃",//20
"┃ 4: 显示稀疏矩阵的存储 ┃",//21
"┃ 5: 输入矩阵的元素 ┃",//22
"┃ 0: 退出。 ┃",//23
"┃ ┃",//24
"┠────────────────────┨"};//25
char * pstring1[]={" DATA STRUCTURE STUDY & FUNCTION DEMONSTRATE",//0
"┏━━━━━━━━━━━━━━━━━━━━┓",//1
"┃ PROGRAM INFORMATION ┃",//2
"┠─────┬──────────────┨",//3
"┃OBJECTIVE │PLANAR ARRAY WITH LINK LIST ┃",//4
"┠─────┼──────────────┨",//5
"┃FUNCTION │STORAGE OF A SPARSITY MATRIX┃",//6
"┠─────┼──────────────┨",//7
"┃INSTRUCTOR│ Gele ┃",//8
"┠─────┼──────────────┨",//9
"┃DESIGNER │ MA ZHEJIANG ┃",//10
"┠─────┼──────────────┨",//11
"┃ DATE │ 2005-4-17 ┃",//12
"┠─────┴──────────────┨",//13
"┃DATA STRUCTURE BILINGUAL-TEACHING CLASS ┃",//14
"┗━━━━━━━━━━━━━━━━━━━━┛",//15
"┠─────┴──────────────┨",//16
"┃ ┃",//17
"┃ 1: CREATE SPARSITY MATRIX ┃",//18
"┃ 2: DELETE SPARSITY MATRIX ┃",//19
"┃ 3: TURN OVER SPARSITY MATRIX ┃",//20
"┃ 4: SHOW STORAGE OF SPARSITY MATRIX ┃",//21
"┃ 5: INPUT ELEMENT OF SPARSITY MATRIX ┃",//22
"┃ 0: QUIT ┃",//23
"┃ ┃",//24
"┠────────────────────┨"};//25
char * string[]={"按 Esc 键切换到英文界面。",
"Press the key Esc ,show a chinese interface.",
"按任意键返回到菜单。",
"Press any key,return to the main menu."};
CShow show;
char * pstr[2][22];
int i,j;
srand(time(0));
int flagEnglist=rand()%2;
if(flagEnglist)
show.SetType(pstring1,16,CShow::SH_RAND,10);
else
show.SetType(pstring0,16,CShow::SH_RAND,10);
show.Show();
Sleep(1000);
for(i=j=0;i<26;i++,j++)
{
if(i==7)
i=16;
pstr[0][j]=pstring0[i];
pstr[1][j]=pstring1[i];
}
pstr[0][j]=pstring0[14];
pstr[1][j++]=pstring1[14];
pstr[0][j]=pstring0[15];
pstr[1][j++]=pstring1[15];
show.SetType(pstr[flagEnglist],j,CShow::SH_STATIC,10);
system("cls");
show.Show();
int specialkey[7]={'0','1','2','3','4','5',27};
CKeyChar key;
key.SetStyle(1,KEY_SPECIAL_INT);
key.SetStyle(specialkey,7);
int chese=0;
CSparseTable sparseTable;
while(1)
{
system("cls");
show.SetType(pstr[flagEnglist],j,CShow::SH_STATIC,10);
show.Show();
cout<<string[flagEnglist]<<endl;
while(!(chese=key.GetKey()));
if(chese=='0')
break;
switch(chese)
{
case '1':
system("cls");
Create(sparseTable,flagEnglist);
cout<<string[2+flagEnglist]<<endl;
getch();
break;
case '2':
system("cls");
Delete(sparseTable,flagEnglist);
cout<<string[2+flagEnglist]<<endl;
getch();
break;
case '3':
system("cls");
Turn(sparseTable,flagEnglist);
cout<<string[2+flagEnglist]<<endl;
getch();
break;
case '4':
system("cls");
Show(sparseTable,flagEnglist);
cout<<string[2+flagEnglist]<<endl;
getch();
break;
break;
case '5':
system("cls");
Input(sparseTable,flagEnglist);
cout<<string[2+flagEnglist]<<endl;
getch();
break;
case 27:
flagEnglist=(flagEnglist+1)%2;
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -