Problem Statement Your company manufactures electrically conductive metal bars w
ID: 3856147 • Letter: P
Question
Problem Statement Your company manufactures electrically conductive metal bars with custom polygonal cross- sections. The metal extrusion machine is limited to producing metal bars with a four-sided polygon as the cross-section. You are given the assignment to calculate the electrical resistance of the bar given its cross-section shape, length, and type of metal Background P3 P4 Pl P2 Arbitrary Cross-section The DC resistance of a conductor having a length L and a uniform cross-sectional area A is given by this equation: where is the electrical conductivity of the conductor. Table 1 shows the conductivity of common metals used in electrical wires. Table 1: Metal electrical conductivity Conductor Silver Copper Gold Aluminum Platinum Conductivity (S/m) 6.30x10 5.96x107 4.10x10 3.50x10 0.943x107Explanation / Answer
The program for the given problem has been written in C++, with comments mentioning their purpose.
Everything within a line mentioned after // are comments and are ignored by the compiler
Program:
#include<bits/stdc++.h>
using namespace std;
int main(){
//p1(x1,y1),p2(x2,y2) and so on
int x1=6,y1=4,x2=17,y2=4; //Coordinates of P1 and P2 are initialized
int x3,y3,x4,y4;
int choice=1;
while(choice!=0){
cout<<"Enter the x and y coordinates of P3 in mm"<<endl;
cin>>x3>>y3;
cout<<"Enter the x and y coordinates of P4 in mm"<<endl;
cin>>x4>>y4;
//Constraints: p3 and p4 must be distinct
if((x3==x4) && (y3==y4)){
cout<<"Error: P3 and P4 are having same coordinate"<<endl;
return 0;
}
//Constraints: p3 and p4 must be located within the defined grid
if((x3>25) || (x3<0) || (x4>25) || (x4<0) || (y3<5) || (y3>25) || (y4<5) || (y4>25) ){
cout<<"Error: P3 and P4 are outside the defined grid"<<endl;
return 0;
}
//Constraints: P4 must be located strictly to the left of P3
if(x4>=x3){
cout<<"Error: P3 is to the left of P4"<<endl;
return 0;
}
//Constraints: P3 and P4 must be above P1 and P2
if( (y1>=y3) || (y1>=y4) || (y2>=y3) ||(y2>=y4) ){
cout<<"Error: Either P1 or P2 is located above P3 or P4"<<endl;
return 0;
}
// Calculating the area of cross section
double a=0,l=0;//a=area,l=length
a=abs(x1*y2+x2*y3+x3*y4+x4*y1-x2*y1-x3*y2-x4*y3-x1*y4)/2;// Calculated using shoelace formula
cout<<"Area A="<<setprecision(3)<<fixed<<a<<" mm²"<<endl;
//Length in meters
cout<<"Enter the length in meters"<<endl;
cin>>l;
//Constraints: Length is valid or not
if(l<0){
cout<<"Error: Length is invalid"<<endl;
return 0;
}
//Check the metal type and assign conductivity using switch case
char type;
double c=0;//c is for conductivity
cout<<"Enter the desired metal type(initials)"<<endl;
cin>>type;
switch(type){
case 's':
case 'S':
c=6.30*10000000;
break;
case 'c':
case 'C':
c=5.96*10000000;
break;
case 'g':
case 'G':
c=4.10*10000000;
break;
case 'a':
case 'A':
c=3.50*10000000;
break;
case 'p':
case 'P':
c=0.943*10000000;
break;
default:
cout<<"Error: Invalid type"<<endl;
return 0;
}
//Calculation of resistance R
double R=0;
// We need to convert area from mm² to m² to get resistance in Ohms
a=a/1000000;//1m²=1000000mm²
R=l/(c*a);
cout<<"Resistance R="<<R<<" ohms"<<endl;
cout<<"Enter 0 to quit or any other input to start with the same process"<<endl;
cin>>choice;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.