//Resistivity
//Preprocessor directives needed for this program
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <math.h>
#include <fstream.h>
#include <cstring.h>
int main()
{
ofstream outfile;
//Assigning the variables in the program as floats and choice as an int.
float tungsten, copper, aluminum, mercury, lead, silver, res, temp;
float temp1[7], res1[7];
string met[7];
int choice, t0=20;
//Entering the metal in an array form
met[1]="tungsten";
met[2]="copper";
met[3]="aluminum";
met[4]="mercury";
met[5]="lead";
met[6]="silver";
//Entering the temperatures of the metals
temp1[1]=.00450;
temp1[2]=.00393;
temp1[3]=.00390;
temp1[4]=.00088;
temp1[5]=.00430;
temp1[6]=.00380;
//Entering the resistivity of the metals which was giving at t0=20
res1[1]=.0000000525;
res1[2]=.0000000172;
res1[3]=.0000000275;
res1[4]=.0000000950;
res1[5]=.0000000220;
res1[6]=.0000000147;
//opening the file
outfile.open("resistivity.txt");
//setting the header for the file
outfile.setf(ios::left);
outfile << setw(10) << "Tempature(C)" << setw(10) << "Resistivity" << "\n";
//User chooses which metal he/she wishes to see the resistivity for.
cout << "Choose a metal from the following and I will list the metals resistivity""\n";
cout << "\n""\n""\n";
cout << "1. Tungsten ""\n";
cout << "2. Copper ""\n";
cout << "3. Aluminum ""\n";
cout << "4. Mercury ""\n";
cout << "5. Lead ""\n";
cout << "6. Silver ""\n""\n";
cin >> choice;
//used if user enters an invalid choice not between 1 and 6
if (choice < 1 || choice > 6)
{
cout << "Enter a choice between 1 and 6 please""\n";
cin >> choice;
}
//Displaying the temp and resistivity for the metal the user chooses
cout << "The Resistivity for: " << met[choice] << "\n";
cout << "Temp(c)" << " " << "Resistivity" << "\n";
cout << "\n";
//Sending the resistivity data to an outfile
outfile << "The Resisitivity for: " << met[choice] << "\n";
outfile << "Temp(c)" << " " << "Resistivity" << "\n";
//loop used to increment the tempature to 5 degrees
for (temp=0; temp<=100; temp+=5)
{
//Equation calculating the resistivity for the metal chosen
res = temp1[choice] * (1.0 + temp1[choice] * (temp - t0));
//Displaying the tempature and resistivity from temp=0 to temp=100
cout << setw(3)<< temp << setw(10) << " " << res << "\n";
outfile << setw(3) << temp << setw(10) << " " << res << "\n";
}
outfile.close();
cout << "\n";
system("PAUSE");
return 0;
}
ok, i will have it soon. Also i will fix your header to C++. Oh and does this work. because it should be std::cout or using namespace std
I dont this this compiles write cause i tried on dev and it didnt. I get it to you in 10 mins
here it is i fixed some stuff.
i added namespace std so cout and cins work now.
fixed some depreciated header like cstring.h
and change the c header to c++
<stdlib.h> to <cstdlib>
i structured it and changed most comments to comment blocks so people can understand better.
a good idea is to put date and name and info at top where it says relativity or something like that.
NOTE: nice code im keeping this for science......hehehe:)
/*Resistivity*/
//Preprocessor directives needed for this program
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <cstring>
usingnamespace std;
int main()
{
ofstream outfile;
/*Assigning the variables in the program as floats and choice as an int.*/
float tungsten, copper, aluminum, mercury, lead, silver, res, temp;
float temp1[7], res1[7];
string met[7];
int choice, t0=20;
/*Entering the metal in an array form*/
met[1]="tungsten";
met[2]="copper";
met[3]="aluminum";
met[4]="mercury";
met[5]="lead";
met[6]="silver";
/*Entering the temperatures of the metals*/
temp1[1]=.00450;
temp1[2]=.00393;
temp1[3]=.00390;
temp1[4]=.00088;
temp1[5]=.00430;
temp1[6]=.00380;
/*Entering the resistivity of the metals which was giving at t0=20*/
res1[1]=.0000000525;
res1[2]=.0000000172;
res1[3]=.0000000275;
res1[4]=.0000000950;
res1[5]=.0000000220;
res1[6]=.0000000147;
/*opening the file*/
outfile.open("resistivity.txt");
/*setting the header for the file*/
outfile.setf(ios::left);
outfile << setw(10) << "Tempature(C)" << setw(10) << "Resistivity" << "\n";
/*User chooses which metal he/she wishes to see the resistivity for.*/
cout << "Choose a metal from the following and I will list the metals resistivity""\n";
cout << "\n""\n""\n";
cout << "1. Tungsten ""\n";
cout << "2. Copper ""\n";
cout << "3. Aluminum ""\n";
cout << "4. Mercury ""\n";
cout << "5. Lead ""\n";
cout << "6. Silver ""\n""\n";
cin >> choice;
/*used if user enters an invalid choice not between 1 and 6*/
if (choice < 1 || choice > 6)
{
cout << "Enter a choice between 1 and 6 please""\n";
cin >> choice;
}
/*Displaying the temp and resistivity for the metal the user chooses*/
cout << "The Resistivity for: " << met[choice] << "\n";
cout << "Temp(c)" << " " << "Resistivity" << "\n";
cout << "\n";
/*Sending the resistivity data to an outfile*/
outfile << "The Resisitivity for: " << met[choice] << "\n";
outfile << "Temp(c)" << " " << "Resistivity" << "\n";
/*loop used to increment the tempature to 5 degrees*/
for (temp=0; temp<=100; temp+=5)
{
//Equation calculating the resistivity for the metal chosen
res = temp1[choice] * (1.0 + temp1[choice] * (temp - t0));
//Displaying the tempature and resistivity from temp=0 to temp=100
cout << setw(3)<< temp << setw(10) << " " << res << "\n";
outfile << setw(3) << temp << setw(10) << " " << res << "\n";
}
outfile.close();
cout << "\n";
system("PAUSE");
return 0;
}