64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include <cstdlib> //exit()
#include <iomanip>
#include <cmath>
#include <string>
#include <ctime>
using namespace std;
const int MAX_SEC = 5; //杆件断面分段数最大取5段
const int MAX_LOAD = 100; //最大荷载数目
const int MAX_BEAM = 10000; //最大杆件数目
struct BEAM_ELEMENT
{
int beam_no;
int j1,j2;
int beamtype_no;
string steel;
double beta;
double length;
};
struct Q_STEEL
{
int thick1,thick2;
double r_tense; //抗拉
double r_press; //抗压抗弯
double r_shear; //抗剪
double r_phole; //孔壁承压
};
struct DATA
{
string Q1,Q2,Q3;
Q_STEEL QC[3];
double QY1,QY2,QY3; //Y=Yield屈服
}steel_data;
struct FORCE
{
double sec_dis; //断面距离(从杆件始端到末端)
double fx,fy,fz;
double mx,my,mz;
};
struct BEAM_FORCE
{
int load_number; //荷载编号
string load_name; //荷载名称
FORCE F[MAX_SEC];
};
struct BEAM_FORCE_FILE
{
int beam_number; //梁编号
BEAM_FORCE BF[MAX_LOAD];
}BFF[MAX_BEAM];
struct BEAM_PROPERTY
{
int beam_type_no;
int side;
int SD; //STRAT DIAMETER
int ED; //END DIAMETER
int THICKNESS;
string ST_TYPE; //STEEL TYPE
};
int COUNT_LINE_NUMBER(char * filename);
int main()
{
int beam_pcs; //梁单元数量
int load_pcs; //工况数量
int beam_sec; //每根杆件断面数
string ENTER; //吃掉换行符用
string NOTHING; //吃掉最上面中文用
ifstream fin;
fin.open("BEAM_FORCE.txt");
if(!fin.is_open())
{
cout << "Fail to open file!" << endl;
cin.get();
exit(EXIT_FAILURE);
}
fin >> beam_pcs;
fin >> load_pcs;
fin >> beam_sec;
getline(fin,ENTER);
getline(fin,NOTHING);
// BEAM_FORCE_FILE BFF[MAX_BEAM];
int i,j,k;
for(i=0;i<beam_pcs;i++)
{
fin >> BFF[i].beam_number;
for(j=0;j<load_pcs;j++)
{
fin >> BFF[i].BF[j].load_number;
fin >> BFF[i].BF[j].load_name;
for(k=0;k<beam_sec;k++)
{
fin >> BFF[i].BF[j].F[k].sec_dis;
fin >> BFF[i].BF[j].F[k].fx;
fin >> BFF[i].BF[j].F[k].fy;
fin >> BFF[i].BF[j].F[k].fz;
fin >> BFF[i].BF[j].F[k].mx;
fin >> BFF[i].BF[j].F[k].my;
fin >> BFF[i].BF[j].F[k].my;
}
}
}
fin.close();
ofstream fout;
fout.open("BEAM_FORCE_COMPARE.TXT");
fout << right << fixed;
for(i=0;i<beam_pcs;i++)
{
fout << setw(3) << BFF[i].beam_number;
for(j=0;j<load_pcs;j++)
{
fout << setw(6) << BFF[i].BF[j].load_number;
fout << setw(20)<< BFF[i].BF[j].load_name;
for(k=0;k<beam_sec;k++)
{
fout << setw(6) << setprecision(3) << BFF[i].BF[j].F[k].sec_dis;
fout << setw(6) << setprecision(3) << BFF[i].BF[j].F[k].fx;
fout << setw(6) << setprecision(3) << BFF[i].BF[j].F[k].fy;
fout << setw(6) << setprecision(3) << BFF[i].BF[j].F[k].fz;
fout << setw(6) << setprecision(3) << BFF[i].BF[j].F[k].mx;
fout << setw(6) << setprecision(3) << BFF[i].BF[j].F[k].my;
fout << setw(6) << setprecision(3) << BFF[i].BF[j].F[k].my << endl;
fout << setw(29);
fout.fill(' ');
}
fout << endl;
}
fout << endl;
}
fout << endl;
fout.close();
return 0;
}
int COUNT_LINE_NUMBER(char * filename)
{
ifstream fin;
fin.open(filename);
int n=0;
string line_data;
if(!fin.is_open())
{
cout << "Fail to open " << filename << "." <<endl;
cin.get();
exit(EXIT_FAILURE);
}
while(getline(fin,line_data))
{
n++;
}
fin.close();
return n;
}
struct BEAM_FORCE_FILE
{
int beam_number; //梁编号
BEAM_FORCE BF[MAX_LOAD];
}BFF[MAX_BEAM];
// BEAM_FORCE_FILE BFF[MAX_BEAM];
BEAM_FORCE_FILE *p = new BEAM_FORCE_FILE[MAX_BEAM];