// ------------------------------------------------------------------- // Department of Electrical and Computer Engineering // University of Waterloo // // Student Name: Aren Patel // UWDIR Userid: aspatel // // Assignment: Programming Assignment 1 // Submission Date: September 18, 2008 // // I declare that this program is my original work. // // ------------------------------------------------------------------- using System; class PA1 { static void Main() { // Constants of resistivity that are given in ohms/km, // obtained from the original information. const double res14 = 8.286d; const double res18 = 20.95d; // Make blank line for space - makes the program look better. // Tells the user what the program is. // Make blank line for space - makes the program look better. Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("Calculator for the Voltage Drop in a " + "Length of Speaker Wire"); Console.WriteLine(""); // Request for user's input. Console.WriteLine("What is the length of the speaker " + "wire in metres?"); // Takes the input, ensures it's stored as double (lengthm). // Takes the stored double (lengthm) coverts to km and stores // as another double (lengthkm). // Make blank line for space - makes the program look better. double lengthm = double.Parse(Console.ReadLine()); double lengthkm = lengthm/1000d; Console.WriteLine(""); // Request for the user's input. Console.WriteLine("What is the resistance of the speaker " + "in Ohms?"); // Takes the input, ensures it's stored as double (resspeak). // Make blank line for space - makes the program look better. double resspeaker = double.Parse(Console.ReadLine()); Console.WriteLine(""); // Store to memory the resistance of 14 & 18 AWG wire, // calculated by the given formula (Resistivity × Length) double rwire14 = lengthkm*res14; double rwire18 = lengthkm*res18; // Output to user the calculated resistance of the specified // length of 14 & 18 AWG wire, round to two decimal places. Console.WriteLine("The resistance of {0} metres of 14 AWG " + "speaker wire is {1:F2} Ohms", lengthm, rwire14); Console.WriteLine("The resistance of {0} metres of 18 AWG " + "speaker wire is {1:F2} Ohms", lengthm, rwire18); // Make blank line for space - makes the program look better. Console.WriteLine(""); // Output to user the % voltage drop of the specified length // of 14 & 18 AWG wire, rounded to one decimal place. Console.WriteLine("The voltage drop for 14 AWG wire is " + "{0:F1}%", (rwire14/(rwire14+resspeaker))*100d); Console.WriteLine("The voltage drop for 18 AWG wire is " + "{0:F1}%", (rwire18/(rwire18+resspeaker))*100d); // Make blank line for space - makes the program look better. Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("Press any key to exit."); Console.ReadLine(); } }