Janett X

Janett X

  • NA
  • 7
  • 0

method that receives the matrix values as a string

Apr 7 2008 3:42 PM
I need to make a method that receives the matrix values as a string as
[code]"[ 1/4 1/3 1/2; 2/3 1/5 2/5; 1/6 1/5 7/8 ] "[/code]
 
and initializes the matrix ( ex. “[ 1/4 1/3 1/2 ; 2/3 1/5 2/5 ; 1/6 1/5 7/8 ] “)
 
I don't how to implement the functions parameters to accept this string...
Any help would be appreciated.
 
 
here's the code:
 
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace HomeWork1
{
    class FractionMatrix
    {
        private Fraction [,] arr = new Fraction[3, 3];
 
        Fraction a11 = new Fraction();
        Fraction a12 = new Fraction();
        Fraction a13 = new Fraction();
 
        Fraction a21 = new Fraction();
        Fraction a22 = new Fraction();
        Fraction a23 = new Fraction();
 
        Fraction a31 = new Fraction();
        Fraction a32 = new Fraction();
        Fraction a33 = new Fraction();
 
        public FractionMatrix()
        {
            Fraction frac = new Fraction();
            frac.SetFraction(0, 1);
        }
 
        // A method that receives the matrix values as a string
        public void SetValues(string  value)
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    arr[i, j] = Int32.Parse(value);
                }
            }
        }
 
        // A 2Dimensional indexer to set and return the value
        // of any matrix element as a string (ex.A[1,1]=“1/3”)
        public void SetValue(string value)
        {
 
        }
    }
 
 
    class Program
    {
        static void Main(string[] args)
        {
            FractionMatrix A = new FractionMatrix ();
            FractionMatrix B = new FractionMatrix ();
 
            A.SetValues("[ 1/6 1/3 1/2; 2/3 1/5 2/5; 1/6 1/5 7/8 ] ");
            B.SetValues("[ 1/4 2/3 1/2; 4/3 10/5 7/5; 4/5 4/3 9/10 ] ");
 
            //A[1,1].SetValue("4/13");
 
            //Console.WriteLine("{0} + {1} = {2}\n\n\n", A, B, A + B);
            //Console.WriteLine("{0} * {1} = {2}\n\n\n", A, B, A * B);
            //Console.WriteLine("det(A) = {0} + det(B) = {1}", A.Det(), B.Det());
 
            Console.Read();
        }
    }
}
[/code]
 
I'm having problems with this function:
[code]
        // A method that receives the matrix values as a string
        public void SetValues(string  value)
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    arr[i, j] = Int32.Parse(value);
                }
            }
        }
[/code]


Answers (7)