Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,063 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,583 people online right now. Registration is fast and FREE... Join Now!




help with structures(repost)

 
Reply to this topicStart new topic

help with structures(repost)

svuaddict12
22 Apr, 2008 - 07:30 PM
Post #1

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 12

Hello, i was just wondering if someone could explain to me how i can build a structure using the following code??

CODE
//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;
}
                                      


thanks

This post has been edited by svuaddict12: 23 Apr, 2008 - 06:10 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 06:36PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month