GIDForums  

Go Back   GIDForums > Computer Programming Forums > .NET Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Apr-2008, 02:01
Max_Payne Max_Payne is offline
New Member
 
Join Date: Oct 2007
Posts: 21
Max_Payne has a little shameless behaviour in the past

[C#] Method that recieves matrix values as a string


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 ] "

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:

C-SHARP / C# 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();
        }
    }
}

I'm having problems with this function:
C-SHARP / C# 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);
                }
            }
        }
Last edited by LuciWiz : 07-Apr-2008 at 08:36. Reason: Changed [cpp] tags to [c#] ;)
  #2  
Old 17-Jun-2008, 06:44
erniegerdie erniegerdie is offline
Junior Member
 
Join Date: Feb 2004
Location: England
Posts: 71
erniegerdie will become famous soon enough

Re: [C#] Method that recieves matrix values as a string


Where is your Fraction class?
 
 

Recent GIDBlogWelcome to Baghdad by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help - complex matrix, complex vector mosquito C++ Forum 30 10-Apr-2008 03:16
Message Class TransformedBG C++ Forum 5 29-Nov-2006 21:28
a tester class and then some. postage Java Forum 1 06-May-2006 15:48
Help with matrix and string combination bco1109 C++ Forum 9 25-Oct-2005 16:52
Help wit my source code compiler errors Krandygrl00 C++ Forum 1 06-Jun-2005 08:14

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:06.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.