C# programming
using System;
public class Matrix {
public int[,] elements;
public Matrix(int[,] init) {
elements = init;
}
public void Display() {
for (int i=0;i<elements.GetLength(0);i++) {
for (int j=0;j<elements.GetLength(1);j++) {
Console.Write(elements[i,j]+" ");
}
Console.WriteLine();
}
}
}
public class Program
{
public static void Main()
{
Matrix m = new Matrix(new int[,] {{3,4,5},{6,7,8},{9,0,0}});
m.Display();
}
}
In the method Display, we display the matrix to the console. This, however, makes the class unusable in a GUI environment. There are many ways to separate Model/VIew here. One way is to create a MatrixDisplayer class that is responsible for displaying Matrix objects.
Please do the following:
C# programming using System; public class Matrix { public int[,] elements; &nb
For the following C# program: Let’s add one more user defined method to the program. This method, called ReverseDump is to output the values in the array in revere order (please note that you are NOT to use the Array.Reverse method from the Array class). The approach is quite simple: your ReverseDump method will look very similar to the Dump method with the exception that the for loop will count backwards from num 1 to 0 . The method header...
cant understand why my toString method wont work... public class Matrix { private int[][] matrix; /** * default constructor -- * Creates an matrix that has 2 rows and 2 columns */ public Matrix(int [][] m) { boolean valid = true; for(int r = 1; r < m.length && valid; r++) { if(m[r].length != m[0].length) valid = false; } if(valid) matrix = m; else matrix = null; } public String toString() { String output = "[ "; for (int i...
C# Arrays
pne and Look at the code below Notice that the program has one class called Tournament. . It defines an integer array called scores to hold all the scores in the tournament .The constructor for the class then actually creates the array of the required size. class Tournament int[ ] scores; const int MAX = 6; // define scores as an integer array // set a constant size public static void Main() //program starts executing here Tournament myTournament...
Draw a flowchart for this program public class InsertionSort { public static void main(String a[]) { int[] array = {7, 1, 3, 2, 42, 76, 9}; insertionSort(array); } public static int[] insertionSort(int[] input) { int temp; for (int i = 1; i < input.length; i++) { for (int j = i; j > 0; j--) { if (input[j] < input[j - 1]) { temp = input[j]; input[j] = input[j - 1]; input[j - 1] = temp; } } display(input, i);...
public class PQueue<E extends Comparable<E>> { private E[] elements; private int size; private int head; private int tail; Private int count; } public void enqueue(E item) { if(isFull()){ return; } count++; elements[tail] = item; tail = (tail + 1) % size; } public E dequeue() { if(isEmpty()) return null; int ct = count-1; E cur = elements[head]; int index = 0; for(i=1;ct-->0;i++) { if(cur.compareTo(elements[head+i)%size])<0) cur = elements[(head+i)%size]; index = i; } } return remove((head+index%size); public E remove(int index) { E...
import java.util.Scanner; public class Chpt7_Project { public static void bubbleSort(int[] list) { int temp; for (int i = list.length - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (list[j] > list[j + 1]) { temp = list[j]; list[j] = list[j + 1]; list[j + 1] = temp; } } } ...
I cannot figure out why my removeAll for var = 7 is not
working.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnorderedArrayListNamespace;
namespace Array
{
public class Program
{
public static void Main(string[] args)
{
UnorderedArrayList u = new UnorderedArrayList();
u.print();
int var = 5;
u.insert(ref var);
var = 12;
u.insert(ref var);
var = 2;
u.insert(ref var);
var = 29;
u.insert(ref var);
var = 7;
u.insert(ref var);
var = 33;
u.insert(ref var);
var = 49;
u.insert(ref var);
var...
Debug the following matrix program in C: // Program to read integers into a 3X3 matrix and display them #include <stdio.h> void display(int Matrix[3][3],int size); int main(void) { char size; double Matrix[size][size+1]; printf("Enter 9 elements of the matrix:\n"); int i; for (i = 0: i <= size: i++) { int j = 0; for (; j <= size++; j++){ scanf("%d", matrix[i--][4]) } } Display(Matrix,9); return 0; void...
//Banner.cs //Created on Page 277 //Modified on Page 288 //Modified on Page 289 //Modified on Page 292 //Modified on Page 295 //Modified on Page 301 //Example10_1, page Page 452 using System; public class Example10_1 { public static void Main (string[] args) { Banner[] x = new Banner[10]; x[0] = new Banner(); x[0].favoriteProgram = "C#"; x[0].Display(); x[1] = new Banner(); x[1].favoriteProgram = "Visual Basic"; x[1].Display(); for (int row = 0; row < 2; row++) { Console.WriteLine(x[row].favoriteProgram); } } } public class...
Finish the class Matrix.h: class Matrix { public: Matrix(); //default constructor ~Matrix(); //destructor Matrix(const Matrix &); //copy constror Matrix(int row, int col); Matrix operator+(const Matrix &)const; //overload operator“+” Matrix& operator=(const Matrix &); //overload operator“=” Matrix transpose()const; //matrix transposition void display()const; //display the data private: int row; //row int col; //column int** mat; //to save the matrix }; //main.cpp #include <iostream> #include"Matrix.h" using namespace std; int main() { int row, col; cout << "input the row and the col for Matrix...