Google Answers Logo
View Question
 
Q: C# program: hints/example given:plz help ASAP ( No Answer,   2 Comments )
Question  
Subject: C# program: hints/example given:plz help ASAP
Category: Computers > Programming
Asked by: sean07-ga
List Price: $30.00
Posted: 04 Oct 2004 22:10 PDT
Expires: 05 Oct 2004 22:48 PDT
Question ID: 410445
Develop a library that adds two mixed currencies together and return a
US dollar amount. For example, adds 5 francs and 500 Yen together ( u
can include some other currecies also). The library should handle any
currency as long as the exchange rates are provided. ( you can get
some conversion rates at http://www.exchangerate.com/).

Clarification of Question by sean07-ga on 04 Oct 2004 22:12 PDT
The program should be written in C# in a way that it can be tested using nUnit. 
You also need to write the test cases(as shown below)..without them
this thing will be incomplete. I'm giving an example of the test cases
as well as a program in C# , which can make it much easier for u. The
program checks and accepts only a four leter passwd "TEST". Here it
goes(first see the example of test cases and then the implementation
code...write test cases and implementation code for the given
problem):

Representative tests:
---------------------

using System;
using NUnit.Framework;

namespace Authentication
{
	/*
	 * Class to test Password
	 */
	[TestFixture]
	public class TestPassword
	{
		[Test]
		// Representative Tests For the method verify
		public void testRepVerifyMoreChar()
		{
			Password pw = new Password();
			Assert.IsFalse(pw.verify("TESTTEST"));
		}

		public void testRepVerifyLessChar()
		{
			Password pw = new Password();
			Assert.IsFalse(pw.verify("TES"));
		}
		public void testRepVerifyBlankSpace()
		{
			Password pw = new Password();
			Assert.IsFalse(pw.verify("   "));
		}
		public void testRepVerifyEmptyString()
		{
			Password pw = new Password();
			Assert.IsFalse(pw.verify(""));
		}
		public void testRepVerifyCase()
		{
			Password pw = new Password();
			Assert.IsFalse(pw.verify("test"));
		}
		public void testRepVerifySpecialChar()
		{
			Password pw = new Password();
			Assert.IsFalse(pw.verify("T1#T"));
		}
		public void testRepVerifyNumeric()
		{
			Password pw = new Password();
			Assert.IsFalse(pw.verify("1234"));
		}
		public void testRepVerifyActual()
		{
			Password pw = new Password();
			Assert.IsTrue(pw.verify("TEST"));
		}


Implementation code:
-----------------------
using System;

namespace Authentication
{
	/* 
	 * The class Password, accepts a 4-letter string,
	 * and verifies it with passwd
	 */
	public class Password
	{
		private string passwd = "TEST";
		public bool verify(string s)
		{
			if(s.Length != 4)	return false;

			char[] c = s.ToCharArray();
			foreach(int ch in c)
			{
				if (ch >= 'A' && ch <='Z') 
					continue;
				return false;
			}
			/* 
			 * Implementation for 4c : passes all
			 * representative & exhaustive test cases
			 */
			/*
			char[] pwd = passwd.ToCharArray();
			for(int i=0; i<s.Length; i++)
			{
				if(c[i] != pwd[i])
					return false;
			}
			return true;
			*/

			/* 
			 * Implementation for 4c : passes all
			 * representative but FAILS exhaustive test cases
			 * It fails as the position of each characters are 
			 * not checked. So TETT, SETS .. all are treated as
			 * valid with the following code.
			 */			
			foreach(int ch in c)
			{
				if(passwd.IndexOf((char)ch) < 0) 
					return false;
			}
			return true;
		}
	}
}
Answer  
There is no answer at this time.

Comments  
Subject: Re: C# program: hints/example given:plz help ASAP
From: chris2002micrometer-ga on 05 Oct 2004 12:42 PDT
 
It seems to me to be far simpler to keep a conversion table for world
currencies, convert to dollars and add.
Subject: Re: C# program: hints/example given:plz help ASAP
From: sean07-ga on 05 Oct 2004 15:41 PDT
 
This program doesn't need a conversion table for all the
currencies...it just needs a few of them as example. And the idea of
converting them into dollar seems good. But, I need the implementation
code and the test cases in C#. I'll have to test them in NUnit.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy