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

📄 jiedianfinal.cpp

📁 计算简单电路的c++程序
💻 CPP
字号:
#include<iostream.h>
#include<math.h>
#include<fstream.h>
  #define   ABS(x)   (x   <   0   ?   -(x)   :   (x))   
  #define   EPS   0.00001   
  #define   TRUE     1   
  #define   FALSE   0 
#define ERR 1.e-15
	double y[11][12];
	double z[12][11];
	double x[11];
	int xishu[22][5];
	int n;
     int   GSolve(double   a[12][11],int   n,double   *x)   
  {   
        int   i,j,k;   
        double   tmp;   
    
        for   (i=0;i<n;i++)   {   
    
              
    
              /*   Eliminate   the   ith   element   of   the   jth   row   */   
              for   (j=i+1;j<n;j++)   {   
                    for   (k=n;k>=i;k--)   {   
                          a[k][j]   -=   a[k][i]   *   a[i][j]   /   a[i][i];   
                    }   
              }   
        }   
    
        /*   Do   the   back   substitution   */   
        for   (j=n-1;j>=0;j--)   {   
              tmp   =   0;   
              for   (k=j+1;k<n;k++)   
                    tmp   +=   a[k][j]   *   x[k];   
              x[j]   =   (a[n][j]   -   tmp)   /   a[j][j]; 
			  cout<<"第"<<j<<"个根是"<<x[j]<<endl;
        }   
    
        return(TRUE);   
  }  
	


  
    


void main() 
{

	cout<<"输入n"<<endl;
	cin>>n;

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n+1;j++) y[i][j]=0;
	}
	fstream read;
	read.open("d://save.txt",ios::in|ios::out);			//‘d://save.txt’文件的路径需改动
	for(int I=0;I<21;I++)
	{	
		for(int h=0;h<5;h++)
		{	
			read>>xishu[I][h];
		
		}
		int j=xishu[I][1];
		int k=xishu[I][2];
		if(xishu[I][3]==2&&j!=0&&k!=0)
		{
			y[j-1][k-1]-=xishu[I][4];
			y[k-1][j-1]-=xishu[I][4];
			y[j-1][j-1]+=xishu[I][4];
			y[k-1][k-1]+=xishu[I][4];
		}
		else
			if(xishu[I][3]==6)
			{
				y[j-1][n]+=xishu[I][4];
				y[k-1][n]-=xishu[I][4];
			}
		else	if(k==0)
			{
			y[j-1][j-1]+=xishu[I][4];
		}
		else   if(j==0)
		{
			y[k-1][k-1]+=xishu[I][4];
		}
		else continue;
	}
	for(int f=0;f<n+1;f++)
		for(int m=0;m<n;m++)
			z[f][m]=y[m][f];

	GSolve(z,n,x);
	

	
}

⌨️ 快捷键说明

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