Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone translate my C# code to C or C++. Thanks! using System.Text; using S

ID: 3808229 • Letter: C

Question

Can someone translate my C# code to C or C++. Thanks!

using System.Text;
using System.Threading.Tasks;

class StressAnalysis
{
    static void Main(string[] args)
    {
        string[] mat = {"Stainless Steel", " Titanium", "Aluminum"};
        double[] yieldstr = { 200 * Math.Pow(10, 6), 900 * Math.Pow(10, 6), 350 * Math.Pow(10, 6) }; // Pa
        double[] density = { 8000, 4420, 2700 }; // kg/m^3
        double[] E = { 200 * Math.Pow(10, 9), 115 * Math.Pow(10, 9), 70 * Math.Pow(10, 9) }; // Pa

        double v = 0.3;

        double H = 0.05; //m
        double tw = 0.0005; //m
        // ti = tw, fail at same conditions
        double tf = 0.0005; //m
        double b = 0.1; //m
        double Mx = 2000; //N-m
        double V = 1000; // N

       
// storing best values
        double Hb = 0;
        double twb = 0;
        double tfb = 0;
        double tib = 0;
        double weight = 10 * Math.Pow(10, 9); //kg
        double cs = 0;
        double fs = 0;
        double ws = 0;
        double ys = 0;
        double vmf = 0;
        double vmw = 0;
        double cfb = 0;
        double cwb = 0;
        double fss = 0;
        double fcss = 0;
        double wss = 0;
        double wcss = 0;
        string m = "";
        int config = 10;

        for (int i = 0; i <= 2; i++)
       
{
            double D = (Math.PI * Math.PI * E[i]) / (12 * (1 - v * v));
            for (int n = 0; n <= 2; n++)
            {
                while (H <= 0.1)
                {
                    while (tf <= 0.003)
                    {
                        while (tw <= 0.003)
                        {
                            var Ixx = (tw * Math.Pow(H, 3)) / 6 + (tf * b * Math.Pow(H, 2)) / 2 + n * (tw * Math.Pow(H, 3)) / 12;
                            var compressivestress = (Mx / Ixx) * H / 2; //Pa
                            var calcweight = density[i] * (2 * H * tw + 2 * b * tf + n * H * tw) * 2; // kg
                            var shearflow = (V * tf * H * b) / (4 * (n + 1) * Ixx);
                            var vonmisesflange = Math.Sqrt(compressivestress * compressivestress + 3 * (shearflow / tf) * (shearflow / tf));
                            var vonmisesweb = Math.Sqrt(compressivestress * compressivestress + 3 * (shearflow / tw) * (shearflow / tw));
                            var fcriticalnormalstress = 4 * D * Math.Pow((tf / (b / (n + 1))), 2);
                            var wcriticalnormalstress = 24 * D * Math.Pow((tw / H), 2);
                            var fshearstress = shearflow / tf;
                            var fcriticalshearstress = 5.36 * D * Math.Pow(tf / (b / (n + 1)), 2);
                            var wshearstress = shearflow / tw;
                            var wcriticalshearstress = 5.36 * D * Math.Pow(tw / H, 2);
                            var combinedflangebuckling = Math.Pow(compressivestress / fcriticalnormalstress, 2) + Math.Pow(fshearstress / fcriticalshearstress, 2);
                            var combinedwebbuckling = Math.Pow(compressivestress / wcriticalnormalstress, 2) + Math.Pow(wshearstress / wcriticalshearstress, 2);
                            if (yieldstr[i] >= vonmisesflange && yieldstr[i] >= vonmisesweb && combinedflangebuckling <= 1 && combinedwebbuckling <= 1 && calcweight < weight)
               
             {
                                weight = calcweight;
                                Hb = H;
                                twb = tw;
                                tfb = tf;
                                tib = tw;
                                cs = compressivestress;
                                ys = yieldstr[i];
                                fs = fcriticalnormalstress;
                                vmf = vonmisesflange;
                                vmw = vonmisesweb;
                                cfb = combinedflangebuckling;
                                cwb = combinedwebbuckling;
                                ws = wcriticalnormalstress;
                                m = mat[i];
                                config = n;
                                fss = fshearstress;
                                fcss = fcriticalshearstress;
                                wss = wshearstress;
                                wcss = wcriticalshearstress;
                            }
                            tw += 0.00001; // add more decimal places for higher precision
                        }
                        tw = 0.0005;
                        tf += 0.00001; // add more decimal places for higher precision
                    }
                    tf = 0.0005;
                    H += 0.001; // add more decimal places for higher precision
                }
                H = 0.05;
            }
        }

Explanation / Answer

Here is the C++ code for you:

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
string mat[] = {"Stainless Steel", " Titanium", "Aluminum"};
double yieldstr[] = { 200 * pow(10, 6), 900 * pow(10, 6), 350 * pow(10, 6) }; // Pa
double density[] = { 8000, 4420, 2700 }; // kg/m^3
double E[] = { 200 * pow(10, 9), 115 * pow(10, 9), 70 * pow(10, 9) }; // Pa
double v = 0.3;
double H = 0.05; //m
double tw = 0.0005; //m
// ti = tw, fail at same conditions
double tf = 0.0005; //m
double b = 0.1; //m
double Mx = 2000; //N-m
double V = 1000; // N


       // storing best values
double Hb = 0;
double twb = 0;
double tfb = 0;
double tib = 0;
double weight = 10 * pow(10, 9); //kg
double cs = 0;
double fs = 0;
double ws = 0;
double ys = 0;
double vmf = 0;
double vmw = 0;
double cfb = 0;
double cwb = 0;
double fss = 0;
double fcss = 0;
double wss = 0;
double wcss = 0;
string m = "";
int config = 10;

for (int i = 0; i <= 2; i++)

       {
double D = (M_PI * M_PI * E[i]) / (12 * (1 - v * v));
for (int n = 0; n <= 2; n++)
{
while (H <= 0.1)
{
while (tf <= 0.003)
{
while (tw <= 0.003)
{
double Ixx = (tw * pow(H, 3)) / 6 + (tf * b * pow(H, 2)) / 2 + n * (tw * pow(H, 3)) / 12;
double compressivestress = (Mx / Ixx) * H / 2; //Pa
double calcweight = density[i] * (2 * H * tw + 2 * b * tf + n * H * tw) * 2; // kg
double shearflow = (V * tf * H * b) / (4 * (n + 1) * Ixx);
double vonmisesflange = sqrt(compressivestress * compressivestress + 3 * (shearflow / tf) * (shearflow / tf));
double vonmisesweb = sqrt(compressivestress * compressivestress + 3 * (shearflow / tw) * (shearflow / tw));
double fcriticalnormalstress = 4 * D * pow((tf / (b / (n + 1))), 2);
double wcriticalnormalstress = 24 * D * pow((tw / H), 2);
double fshearstress = shearflow / tf;
double fcriticalshearstress = 5.36 * D * pow(tf / (b / (n + 1)), 2);
double wshearstress = shearflow / tw;
double wcriticalshearstress = 5.36 * D * pow(tw / H, 2);
double combinedflangebuckling = pow(compressivestress / fcriticalnormalstress, 2) + pow(fshearstress / fcriticalshearstress, 2);
double combinedwebbuckling = pow(compressivestress / wcriticalnormalstress, 2) + pow(wshearstress / wcriticalshearstress, 2);
if (yieldstr[i] >= vonmisesflange && yieldstr[i] >= vonmisesweb && combinedflangebuckling <= 1 && combinedwebbuckling <= 1 && calcweight < weight)

                {
weight = calcweight;
Hb = H;
twb = tw;
tfb = tf;
tib = tw;
cs = compressivestress;
ys = yieldstr[i];
fs = fcriticalnormalstress;
vmf = vonmisesflange;
vmw = vonmisesweb;
cfb = combinedflangebuckling;
cwb = combinedwebbuckling;
ws = wcriticalnormalstress;
m = mat[i];
config = n;
fss = fshearstress;
fcss = fcriticalshearstress;
wss = wshearstress;
wcss = wcriticalshearstress;
}
tw += 0.00001; // add more decimal places for higher precision
}
tw = 0.0005;
tf += 0.00001; // add more decimal places for higher precision
}
tf = 0.0005;
H += 0.001; // add more decimal places for higher precision
}
H = 0.05;
}
}
}
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote