Please fix my program. You can change it however you like but only either #include <stdio.h> or #include <iostream>. Please rewrite the whole program.
Problem
This is my program:
#include <iostream>using namespace std;int main(){int choice;float Cs,C0,time,D,distance1,distance2,distance3;float Cx1,Cx2,Cx3;
cout << "Enter the Carbon Concentration at the Surface(Cs):\n";cin >> Cs;cout << "Enter the Carbon Concentration in bulk (C0):\n";cin >> C0;cout << "Enter a value for D:\n";cin >> D;cout << "Enter\n1. To compute Concentration Profile \n2. To compute Heat Treatment Time\n";cin >> choice;switch(choice){case 1:cout << "Enter Time(t):\n";cin >> time;cout << "Enter Distance 1:\n";cin >> distance1;cout << "Enter Distance 2:\n";cin >> distance2;cout << "Enter Distance 3:\n";cin >> distance3;Cx1= Cs-((Cs-C0)*(erf(distance1/(2*sqrt(D*time)))));Cx2 = Cs-((Cs-C0)*(erf(distance2/(2*sqrt(D*time)))));Cx3 = Cs-((Cs-C0)*(erf(distance3/(2*sqrt(D*time)))));cout << "DISTANCE(cm):\t";cout << distance1 << '\t';cout << distance2 << '\t';cout << distance3 << '\n';cout << "Cx: \t" << Cx1 << '\t' << Cx2 << '\t' << Cx3;break;case 2:float depth;float Cx;float anst;cout << "Enter Depth:\n";cin >> depth;cin >> Cx;float temp1 = ((Cs - Cx) / (Cs - C0));float temp2[5];int time[5];// compute errorfor(int count = 1; count < 6;count++){temp2[count] = erf(depth / (2 * sqrt(D * count * 10)));}float smallest = temp1 - temp2[1];int ansTime=0;for(int count = 1; count < 6; count++){if((temp1 - temp2[count]) <= smallest){smallest = temp1 - temp2[count];ansTime = count*10;}}cout << "The Time taken is roughly: " << ansTime << "s";break;}}
The output should look like this:
Carburization Heat Treatment. Write a computer program for calculating carburization heat treatments. The program should ask the user to provide an input for the carbon concentration at the surface (cs), and the concentration of carbon in the bulk (c0). The program should also ask the user to provide the temperature and a value for D (or values for DO and Q, that will allow for D to be calculated). The program should then provide an output of the concentration profile in tabular form. The distances at which concentrations of carbon are to be determined can be provided by the user or defined by the person writing the program. The program should also be able to handle calculation of heat treatment times if the user provides a level of concentration that is needed at a specified depth. This program will require calculation of the error function. The programming language or spreadsheet you use may have a built-in function that calculates the error function. If that is the case, use that function. You can also calculate the error function as the expansion of the following series: +...) erf(2)=1- TTZ 1 2z² 1x3 (2z²)² + 1x3x5 (22²)3 or use an approximation erf(=) = 1-[(√²+] In these equations, z is the argument of the error function. Also, in certain situations, you will know the value of the error function (if all concentrations are provided) and you will have to figure out the argument of the error function. This can be handled by having part of the program compare different values for the argument of the error function and by minimizing the difference between the value of the error function you require and the value of the error function that was approximated.
Enter the Carbon Concentration at the Surface(Cs): 1.2 Enter the Carbon Concentration in bulk (CO): 0.1 Enter a value for D: 0.00198 Enter 1. To compute Concentration Profile 2. To compute Heat Treatment Time 2 Enter Depth: 0.2 Enter Carbon Concentration at depth 0.2 0.45 The Time taken is roughly: 10s
Please fix my program. You can change it however you like but only either #include or #include . Ple
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am