this is the summary of program and i only include the addition of matrices my problem would be the variables in Addition class cannot read variables from the other class i need to know how to fix that the error would be :
The name 'a' does not exist in the current context
The name 'b' does not exist in the current context
that is why i cant sum the array to give the result help! thanks in advance
*****Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace matrix
{
class Program
{
static void Main(string[] args)
{
matrix.TypeOfMatrix.TypeSel();
}
}
}
*******TypeOfMatrix
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace matrix
{
class TypeOfMatrix
{
public static void TypeSel()
{
Console.WriteLine("Two Matrices are to be entered with the selection of different types");
Console.WriteLine("1-Regular Matrix:");
Console.WriteLine("2-Lower Triangular Matrix:");
Console.WriteLine("3-Upper Triangular Matrix:");
Console.WriteLine("4-Sparse Matrix:");
for (int i= 0; i<2; i++)
{
Console.WriteLine("Type of Matrice:");
string s = Console.ReadLine();
int e2 = int.Parse(s);
switch (e2)
{
case 1:
Console.WriteLine("\nRegular Expression");
matrix.RegularMatrix.Reg();
matrix.Operations.OpSelect();
break;
default:
Console.WriteLine("Invalid Entry (Please Try Again)");
matrix.TypeOfMatrix.TypeSel();
break;
}
}
}
}
}
******RegularMatrix
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace matrix
{
public class RegularMatrix
{
public static int k = 0, l = 0, m = 0, n = 0;
int[,] a = new int[10, 10];
int[,] b = new int[10, 10];
int[,] c = new int[10, 10];
int[,] d = new int[10, 10];
public static void Reg()
{
RegularMatrix cs = new RegularMatrix();
cs.ReadMatrix();
cs.arrange();
//Console.WriteLine();
//matrix.Operations.OpSelect();
}
public void ReadMatrix()
{
Console.Write("\n Enter the size:");
int m = int.Parse(Console.ReadLine());
int n = m;
a = new int[m, n];
Console.WriteLine("\n Enter the elements:");
for (int i = 0; i < a.GetLength(0); i++)
{
for (int j = 0; j < a.GetLength(1); j++)
{
a[i, j] = int.Parse(Console.ReadLine());
}
}
//Console.WriteLine("\n Size of Matrix 2 :");
//Console.Write("\n Enter the number of rows in Matrix 2 :");
//m = int.Parse(Console.ReadLine());
//Console.Write("\n Enter the number of columns in Matrix 2 :");
//n = int.Parse(Console.ReadLine());
//b = new int[m, n];
//Console.WriteLine("\n Enter the elements of Matrix 2:");
//for (int i = 0; i < b.GetLength(0); i++)
//{
// for (int j = 0; j < b.GetLength(1); j++)
// {
// b[i, j] = int.Parse(Console.ReadLine());
// }
//}
}
public void arrange()
{
Console.WriteLine("\n Matrix 1:");
for (int i = 0; i < a.GetLength(0); i++)
{
for (int j = 0; j < a.GetLength(1); j++)
{
Console.Write("\t" + a[i, j]);
}
Console.WriteLine();
}
//Console.WriteLine("\n Matrix 2:");
//for (int i = 0; i < b.GetLength(0); i++)
//{
// for (int j = 0; j < b.GetLength(1); j++)
// {
// Console.Write("\t" + b[i, j]);
// }
// Console.WriteLine();
//}
}
}
}
**** Operations
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace matrix
{
class Operations
{
public static void OpSelect()
{
Console.WriteLine("\n");
Console.WriteLine("Enter the type of operation:");
Console.WriteLine("1-Addition of the matrices:");
Console.WriteLine("2-Subtraction of the matrices:");
Console.WriteLine("3-Multiplication of the matrices:");
string s = Console.ReadLine();
int e = int.Parse(s);
switch (e)
{
case 1:
Console.WriteLine("Addition");
matrix.Addition.RegAdd();
;
break;
default:
Console.WriteLine("Invalid entry");
break;
}
}
}
}
**** Addition
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace matrix
{
class Addition
{
public static void RegAdd(){
Console.WriteLine("Matrix 1 + Matrix 2: ");
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Console.Write(a[i, j] + b[i, j] + " ");
} Console.WriteLine();
} Console.WriteLine();
}
}
}