please can anyone code this program for me
Question: We call the matrix where there is a matrix of zeros perforated so it is stored and the dimensions of the matrix elements of non-zero only in a linear series
Where val: the value of the item in the line i and column J
The required language c + +:
Determine the structure of the data and writing the necessary software required partial
readhmat: read the matrix elements of income and stores it in a variable pattern of holemat
writehmat: writes matrix pattern of holemat ( different elements from zero only)
addhmat: combines two matrices of pattern holemat and puts the output in a matrix of the same pattern
sumhmat: combines all the elements of the matrix pattern holemat
maxmat: gives the largest element of the matrix elements of style holemat
this is my try but in pascal
Program test;
Const nmax=50;
Type
Pemat = ^emat;
emat=record
col:integer;
val:real;
next:pemat;
end;
holemat =array [1..nmax] of pemat;
----------------------------
Procedure insert(var ph:pemat; j:integer; x:real);
Var
p,prev: pemat;
Begin
if ph=nil then
begin
new(ph);
ph^.col:=j;
ph^.val:=x;
ph^.next:=nil;
end
else
begin
if ph^.col > j then
begin
p:=ph;
new(ph);
ph^.col:=j;
ph^.val:=x;
ph^.next:=nil;
end
else
begin
p:=ph; prev:=nil(أو ph);
while (p<>nil) and(p^.col>j) do
begin
prev:=p;
p:=p^.next;
end;
new(prev^.next);
prev^.next^.col:=j;
prev^.next^.val:=x;
prev^.next^.next:=p;
end;
end; {procedure}
--------
Procedure readmat(var n,m:integer; var a:holemat;);
Var
i,j:integer;
Begin
writeln('enter the two dimention mat');
readln(n,m);
for k:=1 to nmax do
a[k]:=nil;
repeat
writeln('enter Line , coloume, value');
readln(i ,j ,x);
insert(a[i] ,j ,x);
until (i=0) and (j=0) and (x=0);
End;{procedure}
-------
Procedure writehmat (n ,m : integer; a:holemat);
var p:pemat;
begin
for k:=1 to n do
begin
p:=a[k];
while p<> nil do
begin
writeln('a[',k,',p^.col',']=',p^,val);
p:=p^.next;
end;
end;
-----------------------------
Function Max_mat(n,m:integer; a:holemat): real;
Var
p:pemat;
i:integer;
found:Boolean;
Begin
i:=1;
found:=false;
while (i=<n) and (not found) do
begin
if a[i]<>nil then
begin
found:=true;
max:=a[i]^.val;
end;
i:=i+1;
end;
if not(found) then
writeln( max:=0)
else
begin
for i-1 to n do
begin
p:=a[i];
while p<> nil do
begin
if p^.val>max then
max:=p^.va;
p:=p^.next;
end;
end;
max_mat:=max;
end;
------------------
Procedure append (var ph,pt:pemat; j:integer; x:real);
Var
P:pemat;
Begin
if ph=nil then
begin
new((ph);
pt:=ph;
ph^.val:=x;
ph^.next:=nil;
end
else
begin
new(pt^.next);
pt:=pt^.next;
pt^.col:=j;
pt^.next:=nil;
end;
end;
-------------
Procedure add_two_mat (n ,m:integer; a,b:holemat; var c:holemat);
Var
p ,q :pemat;
i: integer;
Begin
for i:=1 to n do
begin
c[i]:=nil; current:=nil;
p:=a[i]; q:=q[i] ;
while (p<>nil) and (q<>nil) do
begin
if p^.col<q^.col then
begin
append(c[i],current,p^.col,p^.val);
p:=p^.next;
end
else
if q^.col>p^.col then
begin
append(c[i],cuurent,q^.col,q^.val);
q:=q^.next;
end
else
begin
append(c[i],q^.col,q^.val+p^.val);
p:=p^.next;
q:=q^.next;
end;
end;
while p<>nil do
begin
append(c[i],current,p^.col,p^.val);
p:=p^.next;
end;
while q<>nil do
begin
append(c[i],current,q^.col,q^.val);
q:=q^.next;
end;
end;{for}
end;