Advertisement
ramonguzman

Untitled

Dec 3rd, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. class Program
  2.     {
  3.         const int SIZE = 50;
  4.         static void Main(string[] args)
  5.         {
  6.             int index = 0;
  7.             double res = 0;
  8.             string inputString = "";
  9.  
  10.             Resistor[] resistor = new Resistor[SIZE];
  11.  
  12.             string enviroment = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "//";
  13.  
  14.             Write("please enter the file name:");
  15.             string input = Console.ReadLine();
  16.             StreamReader myFile = new StreamReader(enviroment + input);
  17.                 inputString = myFile.ReadLine();
  18.  
  19.                 string[] data = inputString.Split();
  20.                 double specifcR = double.Parse(data[0]);
  21.                 double maxium = double.Parse(data[1]);
  22.             while(myFile.EndOfStream == false)
  23.             {
  24.                 inputString = myFile.ReadLine();
  25.                 res = double.Parse(inputString);
  26.  
  27.                 resistor[index++] = new Resistor(res, specifcR);
  28.             }
  29.  
  30.             WriteLine("Res#\tDissipitation\tPassed");
  31.  
  32.             for (int i = 0; i < index; i++)
  33.             {
  34.                 if(resistor[i].GetOhm() < maxium)
  35.                 {
  36.                     WriteLine($"{i + 1}\t{resistor[i].GetOhm()}\t            no");
  37.                 }
  38.                 else
  39.                 {
  40.                     WriteLine($"{i + 1}\t{resistor[i].GetOhm()}\t            yes");
  41.                 }
  42.             }
  43.  
  44.             ReadLine();
  45.  
  46.         }
  47. class Resistor
  48.     {      
  49.         private double volts;
  50.         private double restance;
  51.         /// <summary>
  52.         /// constructor
  53.         /// </summary>
  54.         /// <param name="v"></param>
  55.         /// <param name="r"></param>
  56.         public Resistor(double v,double r)
  57.         {
  58.             restance = r;
  59.             volts = v;
  60.         }
  61.         /// <summary>
  62.         /// ohm law
  63.         /// </summary>
  64.         /// <returns></returns>
  65.         public double GetOhm()
  66.         {
  67.             return (volts * volts)/restance;
  68.         }
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement