C++ 1.利用结构实现阶梯型电阻电路计算 2.利用类实现阶梯型电阻电路计算 3.阶梯型电阻电路的计算与图形显
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/19 22:08:54
C++ 1.利用结构实现阶梯型电阻电路计算 2.利用类实现阶梯型电阻电路计算 3.阶梯型电阻电路的计算与图形显
请按照上述内容编程给我,别抄.网上能有的我基本看了.好的话加分.发我邮箱ldljzcc@yeah.net
前两个请做下,实在忙一定做做第二个,谢谢·了
这个网上有了- -
请按照上述内容编程给我,别抄.网上能有的我基本看了.好的话加分.发我邮箱ldljzcc@yeah.net
前两个请做下,实在忙一定做做第二个,谢谢·了
这个网上有了- -
//LadderNetwork.h
struct Struction
{double E;
double risister[50];
};
struct Output
{double current[50];
double voltage[50];
};
//main.cpp
#include <iostream>
using namespace std;
#include "LadderWork.h"
int main( )
{void input( int ,Struction & );
void calculate( int, Struction &, Output & );
void output( int, Output & );
Struction struction;
Output result;
int amount;
cout <<"欢迎使用阶梯型电阻电路计算程序" << endl;
cout << "请输入所有电阻的数目:";
cin >> amount;
while (amount%2!=0) {cout << "电阻的数目应为偶数,请重新输入:";
cin >> amount; }
input ( amount, struction );
calculate ( amount, struction, result );
output ( amount, result );
cout << "谢谢使用!" << endl;
system( "Pause" );
return 0;
}
//input.cpp
#include <iostream>
using namespace std;
#include "LadderWork.h"
void input( int n, Struction &str )
{int i=1;
cout << "请输入电压源的电势E:";
cin >> str.E;
cout << "请按次序输入电阻值:";
for( i=0; i<n; i++ )
{cin >> str.risister[i];
while (str.risister[i] <= 0) {
cout << "电阻值应为正值,请重新输入:";
cin >> str.risister[i];
}
}
cout << endl;
}
//calculate.cpp
#include<iostream>
using namespace std;
#include "LadderWork.h"
void calculate( int n, Struction &p, Output &q )
{int i;
double R;
R = p.risister[n-1]+p.risister[n-2];
for (i=n-3;i>=1;i=i-2)
R=R*p.risister[i]/(R+p.risister[i])+p.risister[i-1];
for (i=0;i<n;i+=2)
{q.current[i] = p.E/R;
q.voltage[i] = q.current[i] * p.risister[i];
R = p.risister[i+1] * ( R - p.risister[i] ) / ( p.risister[i+1] - R + p.risister[i] );
p.E= p.E - q.voltage[i];
q.current[i+1] = p.E / p.risister[i+1];
q.voltage[i+1] = p.E;
}
}
//output.cpp
#include <iostream>
using namespace std;
#include "LadderWork.h"
void output( int n, Output &q )
{ int i;
for ( i=0; i<n; i++ )
cout << "电阻" << 'R' << i+1 << "的电压为" << q.voltage[i] << ",电流为" << q.current[i] << endl;
}
希望对你有帮助
struct Struction
{double E;
double risister[50];
};
struct Output
{double current[50];
double voltage[50];
};
//main.cpp
#include <iostream>
using namespace std;
#include "LadderWork.h"
int main( )
{void input( int ,Struction & );
void calculate( int, Struction &, Output & );
void output( int, Output & );
Struction struction;
Output result;
int amount;
cout <<"欢迎使用阶梯型电阻电路计算程序" << endl;
cout << "请输入所有电阻的数目:";
cin >> amount;
while (amount%2!=0) {cout << "电阻的数目应为偶数,请重新输入:";
cin >> amount; }
input ( amount, struction );
calculate ( amount, struction, result );
output ( amount, result );
cout << "谢谢使用!" << endl;
system( "Pause" );
return 0;
}
//input.cpp
#include <iostream>
using namespace std;
#include "LadderWork.h"
void input( int n, Struction &str )
{int i=1;
cout << "请输入电压源的电势E:";
cin >> str.E;
cout << "请按次序输入电阻值:";
for( i=0; i<n; i++ )
{cin >> str.risister[i];
while (str.risister[i] <= 0) {
cout << "电阻值应为正值,请重新输入:";
cin >> str.risister[i];
}
}
cout << endl;
}
//calculate.cpp
#include<iostream>
using namespace std;
#include "LadderWork.h"
void calculate( int n, Struction &p, Output &q )
{int i;
double R;
R = p.risister[n-1]+p.risister[n-2];
for (i=n-3;i>=1;i=i-2)
R=R*p.risister[i]/(R+p.risister[i])+p.risister[i-1];
for (i=0;i<n;i+=2)
{q.current[i] = p.E/R;
q.voltage[i] = q.current[i] * p.risister[i];
R = p.risister[i+1] * ( R - p.risister[i] ) / ( p.risister[i+1] - R + p.risister[i] );
p.E= p.E - q.voltage[i];
q.current[i+1] = p.E / p.risister[i+1];
q.voltage[i+1] = p.E;
}
}
//output.cpp
#include <iostream>
using namespace std;
#include "LadderWork.h"
void output( int n, Output &q )
{ int i;
for ( i=0; i<n; i++ )
cout << "电阻" << 'R' << i+1 << "的电压为" << q.voltage[i] << ",电流为" << q.current[i] << endl;
}
希望对你有帮助