Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Param.NET - An Automated Command-line Parameter Parser

, 19 Oct 2005 CPOL
A library that allows developers to specify the parameters that they expect to receive from the command line and provides an easier way to access them
using System;
using System.Configuration;
using Params;

namespace ParamTest
{
	class MainClass
	{
		[STAThread]
		static void Main(string[] args)
		{
			ParamCollection p = ParamCollection.ApplicationParameters;
			float a = (float)p["a"].Value;
			float b = (float)p["b"].Value;
			float c = (float)p["c"].Value;
			bool verbose = (bool)p["v"].Value;
			bool complex = (bool)p["C"].Value;

            if(verbose)	Console.WriteLine("a = {0}\nb = {1}\nc = {2}", a, b, c);

			float delta = b*b - 4*a*c;

			if(verbose)
				Console.WriteLine("Delta = {0}", delta);

			if(delta < 0 && !complex)
			{
				Console.WriteLine("There are no real solutions to this equation");
				return;
			}

			if(delta < 0)
			{
				float real = -b / (2*a);
				if(verbose)
					Console.WriteLine("Calculated the real part: {0}", real);

				float imag = (float)Math.Sqrt(-delta);

				if(verbose)
					Console.WriteLine("Calculated the imaginary part: {0}", imag);
				
				Console.WriteLine("S1 = {0} + {1}i,\tS2 = {0} + {1}i", real, imag);
			}
			else
			{
				float dsqrt = (float)Math.Sqrt(delta);

				float s1 = (-b + dsqrt)/(2*a);

				if(verbose)
					Console.WriteLine("Calculated the first solution: {0}", s1);

				float s2 = (-b - dsqrt)/(2*a);

				if(verbose)
					Console.WriteLine("Calculated the second solution: {0}", s2);

				if(s1 == s2)
					Console.WriteLine("S1 = S2 = {0}", s1);
				else
                    Console.WriteLine("S1 = {0},\tS2 = {1}", s1, s2);
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

eugen.anghel
Web Developer
Romania Romania
Just you average programmer geek from Romania. Student at Faculty of Computer Science, Al. I. Cuza University Iasi, Romania.

| Advertise | Privacy | Mobile
Web03 | 2.8.141022.1 | Last Updated 20 Oct 2005
Article Copyright 2005 by eugen.anghel
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid