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

📄 io.h

📁 经典矩阵运算问题求解
💻 H
字号:
void ReadCommand(char &cmd)
{
	do{cmd=getchar();
}while(cmd!='+'&&cmd!='-'&&cmd!='*'&&cmd!='q'&&cmd!='Q'&&cmd!='p');
}


void Initialization()
{clrscr();
 cout<<"*****************************************************************************"<<endl;
 cout<<" Addition-(+) Subtraction-(-) Multiplication-(*) Result-(p)  Quit-(q)"<<endl;
 cout<<"*****************************************************************************"<<endl;
 gotoxy(1,22);
 cout<<"*****************************************************************************"<<endl;
 cout<<"                  Enter a operation code:+,-,*,p or q"<<endl;
 cout<<"*****************************************************************************"<<endl;
 gotoxy(11,4);
}


void print1(TSMatrix &M,char X)
{
	cout<<"please input the row&col of "<<X<<endl;
	cin>>M.mu>>M.nu;
	if(M.mu>=1&&M.mu<=MAX&&M.nu>=1&&M.nu<=MAX)
		flag1=1;
}

void print2(TSMatrix &M,TSMatrix &N)
{ int num1=M.nu*M.mu;
  int num2=N.mu*N.nu;
    clrscr();
    Initialization();
    gotoxy(1,4);
    cout<<"Arrays have been set up successfully and they can be computed!"
	<<endl<<"please input the number of NOT ZERO in M"<<endl;
	cin>>M.tu;
	if(M.tu>=0&&M.tu<num1+1)
	{ if(M.tu)
	  {cout<<"please input the data of NOT ZERO in M,data(i,j,e)"<<endl;
	   for(int w=1;w<=M.tu;w++)
		cin>>M.data[w].i>>M.data[w].j>>M.data[w].e;
	   }
	cout<<"please input the number of NOT ZERO in N"<<endl;
	cin>>N.tu;
	if(N.tu>0&&N.tu<num2+1)
	{cout<<"please input the data of NOT ZERO in N,data(i,j,e)"<<endl;
	for(int w=1;w<=N.tu;w++)
		cin>>N.data[w].i>>N.data[w].j>>N.data[w].e;
	}
	else if(N.tu!=0)
		cout<<"input error!"<<endl;
	}
	else if(M.tu!=0)
	       cout<<"input error!"<<endl;

	if(M.tu>=0&&M.tu<num1+1&&N.tu>=0&&N.tu<num2+1)
	flag2=1;
}

void print3(TSMatrix M,TSMatrix N)
{
	cout<<"the result is:"<<endl;
	for(int w=1;w<=M.mu;w++)
	{
		for(int t=1;t<=N.nu;t++)
		printf("%3d",a[w][t]);
		cout<<endl;
	}
}

void Interpret(char op)
  {
  if(op=='+')
  {
	 print1(M,'M');
	 if(flag1) print1(N,'N');
	 if(M.mu!=N.mu||M.nu!=N.nu)
	 cout<<"error ! "<<endl;
   else print2(M,N);
   add(M,N);
   cout<<"Addition has finished! Press p to see the result!"
       <<endl<<"operation:";

  }
  else if(op=='-')
  {
	print1(M,'M');
	if(flag1) print1(N,'N');
	if(M.mu!=N.mu||M.nu!=N.nu)
	 cout<<"error ! "<<endl;
    else print2(M,N);
    sub(M,N);
    cout<<"Subtraction has finished! Press p to see the result!"
	<<endl<<"operation:";
  }
  else if(op=='*')
  {
	  print1(M,'M');
	  if(flag1) print1(N,'N');
	  if(M.nu!=N.mu)
		  cout<<"error!"<<endl;
	  else print2(M,N);
	  makerpos(M);
      makerpos(N);
	  mul(M,N);
       cout<<"Multiplication has finished! Press p to see the result!"<<endl
      <<"operation:";
  }
  else if(op=='p')
  {
    if(flag&&flag2)
    {
    clrscr();
    Initialization();
    gotoxy(1,4);
    print3(M,N);
    cout<<"operation:";
    }
    else
    cout<<"you can't see the result before you setting up the array!"<<endl
	<<"operation:";
  }
}

⌨️ 快捷键说明

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