|
khalid khalidos wrote: Without repetion
For that last part, you'd need a way to remember which numbers you already used. If you request a new number, check, and if already used, request another one until you have a new, unused number.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Seems he did not understand what you were saying or possibly because there was no code and down voted your reply - reversed!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Tx
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
khalid khalidos wrote: how to randomly the Question from Databse Without repetion
Looks like you need to use the same algorithm as the one used to shuffle a deck of cards.
1) make an array the size of your number of questions, fill it with question numbers.
2) draw a position in possible ones, swap with last question, repeat without the last place.
for usage: get questions numbers from array in order.
This way you shuffle 52 questions with 51 draws, no repetition.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
|
What have you tried?
Where are you stuck?
What help do you need?
What environment are you coding for?
To be honest, a question that just has a subject line and one word: "none" isn't really showing us any willingness to help us to help you - or any sign that you've even tried to do this yourself. That doesn't improve your chances of getting a quick solution.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I had try many time to convert .mats file into text file with change utf-8 encoding because it contain Devanagari hind font but it is not visible to readable textual data in c# .net.
|
|
|
|
|
|
Windows uses internally UTF-16 for strings. When having UTF-8 encoded strings, they must be converted to the encoding used by Windows.
With C# this requires having the UTF-8 string in a byte[] array. Then use the encoding class to convert the byte array to a string. See Encoding.GetString Method (Byte[]) (System.Text)[^] for example code.
BTW: What is a "mats" file? A MATLAB file?
If so read the UTF-8 string into a byte array and perform the conversion as described above.
|
|
|
|
|
How to convert this pascal code in C# :
uses crt;
var najbl:int64;
u,pok,zad,a:longint;
l:integer;
niz:array[1..946686] of int64;
uzet:array[1..6] of boolean;
w:string;
lpl:boolean;
function abs(x:int64):int64;
begin
if x>0 then abs:=x
else abs:=-x;
end;
function num2str(y:integer):string;
begin
num2str:='';
repeat
num2str:=chr(y mod 10+48)+num2str;
y:=y div 10
until y=0;
end;
procedure inc_uzet;
var ss:byte;
begin
for ss:=1 to 6 do
uzet[ss]:=false;
end;
procedure oznaci_po_redu(s:integer);
begin
l:=0;
while (s>0) do
begin
inc(l);
if not(uzet[l]) then dec(s);
end;
uzet[l]:=true;
end;
procedure dekodiraj(i:longint);
begin
if i<7 then uzet[i]:=true
else if i<127 then begin
dekodiraj((i-7) div 4 div 5 + 1);
oznaci_po_redu((i-7) div 4 - (i-7) div 4 div 5 * 5 + 1);
end
else if i<2047 then begin
dekodiraj((i-127) div 4 div 4 + 7);
oznaci_po_redu((i-127) div 4 - (i-127) div 4 div 4 * 4 + 1);
end
else if i<25087 then begin
dekodiraj((i-2047) div 4 div 3 + 127);
oznaci_po_redu((i-2047) div 4 - (i-2047) div 4 div 3 * 3 + 1);
end
else if i<209407 then begin
dekodiraj((i-25087) div 4 div 2 + 2047);
oznaci_po_redu((i-25087) div 4 - (i-25087) div 4 div 2 * 2 + 1);
end
else begin
dekodiraj((i-209407)div 4 + 25087);
oznaci_po_redu(1);
end;
end;
procedure dekodiraj1(i:longint);
var a:longint;
begin
if i<7 then begin
uzet[i]:=true;
w:=w+num2str(niz[i]);
lpl:=false;
end
else begin
if i<127 then begin
a:=(i-7) div 4 div 5 + 1;
dekodiraj1(a);
oznaci_po_redu((i-7) div 4 - 5*(a-1)+1);
end
else if i<2047 then begin
a:=(i-127) div 4 div 4 + 7;
dekodiraj1(a);
oznaci_po_redu((i-127) div 4 - 4*(a-7)+1);
end
else if i<25087 then begin
a:=(i-2047) div 4 div 3 + 127;
dekodiraj1(a);
oznaci_po_redu((i-2047) div 4 - 3*(a-127)+1);
end
else if i<209407 then begin
a:=(i-25087) div 4 div 2 + 2047;
dekodiraj1(a);
oznaci_po_redu((i-25087) div 4 - 2*(a-2047)+1);
end
else begin
a:=(i-209407)div 4 + 25087;
dekodiraj1(a);
oznaci_po_redu(1);
end;
case ((i+1) mod 4) of
0: begin
w:=w+'+'+num2str(niz[l]);
lpl:=true;
end;
1: begin
if niz[a]>niz[l] then begin
w:=w+'-'+num2str(niz[l]);
end
else begin
if not(lpl) then w:=num2str(niz[l])+'-'+w
else w:=num2str(niz[l])+'-('+w+')';
end;
lpl:=true;
end;
2: begin
if lpl then w:='('+w+')*'+num2str(niz[l])
else w:=w+'*'+num2str(niz[l]);
lpl:=false;
end;
3: begin
if niz[a]>niz[l] then begin
if lpl then w:='('+w+')/'+num2str(niz[l])
else w:=w+'/'+num2str(niz[l]);
end
else begin
if i<127 then w:=num2str(niz[l])+'/'+w
else w:=num2str(niz[l])+'/('+w+')';
end;
lpl:=false;
end;
end;
end;
end;
procedure ispisi;
begin
writeln(zad);
writeln(w);
repeat until keypressed;
halt(0);
end;
procedure kraj;
begin
if niz[pok]=zad then begin
inc_uzet;
dekodiraj1(pok);
ispisi;
end;
end;
procedure uradi(k:longint);
var j:integer;
begin
inc_uzet;
dekodiraj(k);
for j:=1 to 6 do
if not(uzet[j]) then begin
niz[pok]:=niz[k]+niz[j];
kraj;
inc(pok);
niz[pok]:=abs(niz[k]-niz[j]);
kraj;
inc(pok);
niz[pok]:=niz[k]*niz[j];
kraj;
inc(pok);
niz[pok]:=0;
if niz[k] mod niz[j]=0 then niz[pok]:=niz[k] div niz[j]
else if niz[k]>0 then if niz[j] mod niz[k]=0 then niz[pok]:=niz[j] div niz[k];
kraj;
inc(pok);
end;
end;
procedure resi_6;
begin
for u:=1 to 946686 do
if abs(niz[u]-zad)<abs(najbl-zad) then begin
najbl:=niz[u];
pok:=u;
end;
inc_uzet;
dekodiraj1(pok);
if najbl=zad then ispisi;
end;
procedure resi_3_3;
var v:longint;
w1:string;
uzet1:array[1..6] of boolean;
begin
for u:=7 to 2045 do
for v:=u+1 to 2046 do
begin
inc_uzet;
dekodiraj(v);
for pok:=1 to 6 do
uzet1[pok]:=uzet[pok];
inc_uzet;
dekodiraj(u);
if not((uzet[1] and uzet1[1])or(uzet[2] and uzet1[2])or(uzet[3] and uzet1[3])or(uzet[4] and uzet1[4])or(uzet[5] and uzet1[5])or(uzet[6] and uzet1[6]))
then begin
if abs(niz[u]+niz[v]-zad)<abs(najbl-zad) then begin
najbl:=niz[u]+niz[v];
w:='';
inc_uzet;
dekodiraj1(v);
w1:=w;
w:='';
inc_uzet;
dekodiraj1(u);
w:=w+'+'+w1;
if najbl=zad then ispisi;
end;
if abs(abs(niz[u]-niz[v])-zad)<abs(najbl-zad) then begin
najbl:=abs(niz[u]-niz[v]);
w:='';
inc_uzet;
if niz[u]>niz[v] then begin
dekodiraj1(v);
if lpl then w1:='('+w+')'
else w1:=w;
w:='';
inc_uzet;
dekodiraj1(u);
end
else begin
dekodiraj1(u);
if lpl then w1:='('+w+')'
else w1:=w;
w:='';
inc_uzet;
dekodiraj1(v);
end;
w:=w+'-'+w1;
if najbl=zad then ispisi;
end;
if abs(niz[u]*niz[v]-zad)<abs(najbl-zad) then begin
najbl:=niz[u]*niz[v];
w:='';
inc_uzet;
dekodiraj1(v);
if lpl then w1:='('+w+')'
else w1:=w;
w:='';
inc_uzet;
dekodiraj1(u);
if lpl then w:='('+w+')*'+w1
else w:=w+'*'+w1;
if najbl=zad then ispisi;
end;
if (niz[v]>0) and (niz[u] mod niz[v]=0) then
if abs(niz[u] div niz[v]-zad)<abs(najbl-zad) then begin
najbl:=niz[u] div niz[v];
w:='';
inc_uzet;
dekodiraj1(v);
w1:='('+w+')';
w:='';
inc_uzet;
dekodiraj1(u);
if lpl then w:='('+w+')/'+w1
else w:=w+'/'+w1;
if najbl=zad then ispisi;
end
else
else
if (niz[u]>0) and (niz[v] mod niz[u]=0) then
if abs(niz[v] div niz[u]-zad)<abs(najbl-zad) then begin
najbl:=niz[v] div niz[u];
w:='';
inc_uzet;
dekodiraj1(u);
w1:='('+w+')';
w:='';
inc_uzet;
dekodiraj1(v);
if lpl then w:='('+w+')/'+w1
else w:=w+'/'+w1;
if najbl=zad then ispisi;
end;
end;
end;
end;
procedure resi_2_2_2;
var v,v1:longint;
w1:string;
uzet1:array[1..6] of boolean;
begin
for u:=7 to 126 do
for v:=7 to 126 do
begin
inc_uzet;
dekodiraj(v);
for pok:=1 to 6 do
uzet1[pok]:=uzet[pok];
inc_uzet;
dekodiraj(u);
if not((uzet[1] and uzet1[1])or(uzet[2] and uzet1[2])or(uzet[3] and uzet1[3])or(uzet[4] and uzet1[4])or(uzet[5] and uzet1[5])or(uzet[6] and uzet1[6]))
then begin
for pok:=1 to 6 do
uzet1[pok]:=uzet[pok] or uzet1[pok];
for v1:=1 to 126 do
begin
inc_uzet;
dekodiraj(v1);
if not((uzet[1] and uzet1[1])or(uzet[2] and uzet1[2])or(uzet[3] and uzet1[3])or(uzet[4] and uzet1[4])or(uzet[5] and uzet1[5])or(uzet[6] and uzet1[6]))
then begin
if abs(niz[u]+niz[v]+niz[v1]-zad)<abs(najbl-zad) then begin
najbl:=niz[u]+niz[v]+niz[v1];
w:='';
inc_uzet;
dekodiraj1(v1);
w1:=w;
w:='';
inc_uzet;
dekodiraj1(v);
w1:=w+'+'+w1;
w:='';
inc_uzet;
dekodiraj1(u);
w:=w+'+'+w1;
if najbl=zad then ispisi;
end;
if abs(abs(niz[u]+niz[v]-niz[v1])-zad)<abs(najbl-zad) then begin
najbl:=abs(niz[u]+niz[v]-niz[v1]);
w:='';
inc_uzet;
if niz[u]+niz[v]>niz[v1] then begin
dekodiraj1(v1);
if lpl then w1:='('+w+')'
else w1:=w;
w:='';
inc_uzet;
dekodiraj1(v);
w1:=w+'-'+w1;
w:='';
inc_uzet;
dekodiraj1(u);
w:=w+'+'+w1;
end
else begin
dekodiraj1(v);
w1:=w;
w:='';
inc_uzet;
dekodiraj1(u);
w1:='('+w+'+'+w1+')';
w:='';
inc_uzet;
dekodiraj1(v1);
w:=w+'-'+w1;
end;
if najbl=zad then ispisi;
end;
if abs((niz[u]+niz[v])*niz[v1]-zad)<abs(najbl-zad) then begin
najbl:=(niz[u]+niz[v])*niz[v1];
w:='';
inc_uzet;
dekodiraj1(v1);
if lpl then w1:='('+w+')'
else w1:=w;
w:='';
inc_uzet;
dekodiraj1(v);
w1:=w+')*'+w1;
w:='';
inc_uzet;
dekodiraj1(u);
w:='('+w+'+'+w1;
if najbl=zad then ispisi;
end;
if (niz[v1]>0) and ((niz[u]+niz[v]) mod niz[v1]=0) then
if abs((niz[u]+niz[v]) div niz[v1]-zad)<abs(najbl-zad) then begin
najbl:=(niz[u]+niz[v]) div niz[v1];
w:='';
inc_uzet;
dekodiraj1(v1);
if v1<7 then w1:=w
else w1:='('+w+')';
w:='';
inc_uzet;
dekodiraj1(v);
w1:=w+')/'+w1;
w:='';
inc_uzet;
dekodiraj1(u);
w:='('+w+'+'+w1;
if najbl=zad then ispisi;
end
else
else
if (niz[u]+niz[v]>0) and (niz[v1] mod (niz[u]+niz[v])=0) then
if abs(niz[v1] div (niz[u]+niz[v])-zad)<abs(najbl-zad) then begin
najbl:=niz[v] div (niz[u]+niz[v]);
w:='';
inc_uzet;
dekodiraj1(v);
w1:=w+')';
w:='';
inc_uzet;
dekodiraj1(u);
w1:='('+w+'+'+w1;
w:='';
inc_uzet;
dekodiraj1(v1);
if lpl then w:='('+w+')/'+w1
else w:=w+'/'+w1;
if najbl=zad then ispisi;
end;
if abs(abs(niz[u]-niz[v])*niz[v1]-zad)<abs(najbl-zad) then begin
najbl:=abs(niz[u]-niz[v])*niz[v1];
w:='';
inc_uzet;
dekodiraj1(v1);
if lpl then w1:='('+w+')'
else w1:=w;
w:='';
inc_uzet;
if niz[u]>niz[v] then begin
dekodiraj1(v);
if lpl then w1:='('+w+'))*'+w1
else w1:=w+')*'+w1;
w:='';
inc_uzet;
dekodiraj1(u);
end
else begin
dekodiraj1(u);
if lpl then w1:='('+w+'))*'+w1
else w1:=w+')*'+w1;
w:='';
inc_uzet;
dekodiraj1(v);
end;
w:='('+w+'-'+w1;
if najbl=zad then ispisi;
end;
if (niz[v1]>0) and (abs(niz[u]-niz[v]) mod niz[v1]=0) then
if abs(abs(niz[u]-niz[v]) div niz[v1]-zad)<abs(najbl-zad) then begin
najbl:=abs(niz[u]-niz[v]) div niz[v1];
w:='';
inc_uzet;
dekodiraj1(v1);
if v1<7 then w1:=w
else w1:='('+w+')';
w:='';
inc_uzet;
if niz[u]>niz[v] then begin
dekodiraj1(v);
if lpl then w1:='('+w+'))/'+w1
else w1:=w+')/'+w1;
w:='';
inc_uzet;
dekodiraj1(u);
end
else begin
dekodiraj1(u);
if lpl then w1:='('+w+'))/'+w1
else w1:=w+')/'+w1;
w:='';
inc_uzet;
dekodiraj1(v);
end;
w:='('+w+'-'+w1;
if najbl=zad then ispisi;
end
else
else
if (abs(niz[u]-niz[v])>0) and (niz[v1] mod abs(niz[u]-niz[v])=0) then
if abs(niz[v1] div abs(niz[u]-niz[v])-zad)<abs(najbl-zad) then begin
najbl:=niz[v1] div abs(niz[u]-niz[v]);
w:='';
inc_uzet;
if niz[u]>niz[v] then begin
dekodiraj1(v);
if lpl then w1:='('+w+'))'
else w1:=w+')';
w:='';
inc_uzet;
dekodiraj1(u);
end
else begin
dekodiraj1(u);
if lpl then w1:='('+w+'))'
else w1:=w+')';
w:='';
inc_uzet;
dekodiraj1(v);
end;
w1:='('+w+'-'+w1;
w:='';
inc_uzet;
dekodiraj1(v1);
if lpl then w:='('+w+')/'+w1
else w:=w+'/'+w1;
if najbl=zad then ispisi;
end;
if abs(niz[u]*niz[v]+niz[v1]-zad)<abs(najbl-zad) then begin
najbl:=niz[u]*niz[v]+niz[v1];
w:='';
inc_uzet;
dekodiraj1(v1);
w1:=w;
w:='';
inc_uzet;
dekodiraj1(v);
if lpl then w1:='('+w+')+'+w1
else w1:=w+'+'+w1;
w:='';
inc_uzet;
dekodiraj1(u);
if lpl then w:='('+w+')*'+w1
else w:=w+'*'+w1;
if najbl=zad then ispisi;
end;
if abs(abs(niz[u]*niz[v]-niz[v1])-zad)<abs(najbl-zad) then begin
najbl:=abs(niz[u]*niz[v]-niz[v1]);
w:='';
inc_uzet;
if niz[u]*niz[v]>niz[v1] then begin
dekodiraj1(v1);
if lpl then w1:='('+w+')'
else w1:=w;
w:='';
inc_uzet;
dekodiraj1(v);
if lpl then w1:='('+w+')-'+w1
else w1:=w+'-'+w1;
w:='';
inc_uzet;
dekodiraj1(u);
if lpl then w:='('+w+')*'+w1
else w:=w+'*'+w1;
end
else begin
dekodiraj1(v);
if lpl then w1:='('+w+')'
else w1:=w;
w:='';
inc_uzet;
dekodiraj1(u);
if lpl then w1:='('+w+')*'+w1
else w1:=w+'*'+w1;
w:='';
inc_uzet;
dekodiraj1(v1);
w:=w+'-'+w1;
end;
if najbl=zad then ispisi;
end;
if abs(niz[u]*niz[v]*niz[v1]-zad)<abs(najbl-zad) then begin
najbl:=niz[u]*niz[v]*niz[v1];
w:='';
inc_uzet;
dekodiraj1(v1);
if lpl then w1:='('+w+')'
else w1:=w;
w:='';
inc_uzet;
dekodiraj1(v);
if lpl then w1:='('+w+')*'+w1
else w1:=w+'*'+w1;
w:='';
inc_uzet;
dekodiraj1(u);
if lpl then w:='('+w+')*'+w1
else w:=w+'*'+w1;
if najbl=zad then ispisi;
end;
if (niz[v1]>0) and (niz[u]*niz[v] mod niz[v1]=0) then
if abs(niz[u]*niz[v] div niz[v1]-zad)<abs(najbl-zad) then begin
najbl:=niz[u]*niz[v] div niz[v1];
w:='';
inc_uzet;
dekodiraj1(v1);
if v1<7 then w1:=w
else w1:='('+w+')';
w:='';
inc_uzet;
dekodiraj1(v);
if lpl then w1:='('+w+')/'+w1
else w1:=w+'/'+w1;
w:='';
inc_uzet;
dekodiraj1(u);
if lpl then w:='('+w+')*'+w1
else w:=w+'*'+w1;
if najbl=zad then ispisi;
end
else
else
if (niz[u]*niz[v]>0) and (niz[v1] mod (niz[u]*niz[v])=0) then
if abs(niz[v1] div (niz[u]*niz[v])-zad)<abs(najbl-zad) then begin
najbl:=niz[v] div (niz[u]*niz[v]);
w:='';
inc_uzet;
dekodiraj1(v);
if lpl then w1:='('+w+'))'
else w1:=w+')';
w:='';
inc_uzet;
dekodiraj1(u);
if lpl then w1:='(('+w+')*'+w1
else w1:='('+w+'*'+w1;
w:='';
inc_uzet;
dekodiraj1(v1);
if lpl then w:='('+w+')/'+w1
else w:=w+'/'+w1;
if najbl=zad then ispisi;
end;
if (niz[v]>0) and (niz[u] mod niz[v]=0) then
begin
if abs(niz[u] div niz[v]+niz[v1]-zad)<abs(najbl-zad) then begin
najbl:=niz[u] div niz[v]+niz[v1];
w:='';
inc_uzet;
dekodiraj1(v1);
w1:=w;
w:='';
inc_uzet;
dekodiraj1(v);
w1:='('+w+')+'+w1;
w:='';
inc_uzet;
dekodiraj1(u);
if lpl then w:='('+w+')/'+w1
else w:=w+'/'+w1;
if najbl=zad then ispisi;
end;
if abs(abs(niz[u] div niz[v]-niz[v1])-zad)<abs(najbl-zad) then begin
najbl:=abs(niz[u] div niz[v]-niz[v1]);
w:='';
inc_uzet;
if niz[u] div niz[v]>niz[v1] then begin
dekodiraj1(v1);
if lpl then w1:='('+w+')'
else w1:=w;
w:='';
inc_uzet;
dekodiraj1(v);
w1:='('+w+')-'+w1;
w:='';
inc_uzet;
dekodiraj1(u);
if lpl then w:='('+w+')/'+w1
else w:=w+'/'+w1;
end
else begin
dekodiraj1(v);
w1:='('+w+')';
w:='';
inc_uzet;
dekodiraj1(u);
if lpl then w1:='('+w+')/'+w1
else w1:=w+'/'+w1;
w:='';
inc_uzet;
dekodiraj1(v1);
w:=w+'-'+w1;
end;
if najbl=zad then ispisi;
end;
end
else if (niz[u]>0) and (niz[v] mod niz[u]=0) then
begin
if abs(niz[v] div niz[u]+niz[v1]-zad)<abs(najbl-zad) then begin
najbl:=niz[v] div niz[u]+niz[v1];
w:='';
inc_uzet;
dekodiraj1(v1);
w1:=w;
w:='';
inc_uzet;
dekodiraj1(u);
w1:='('+w+')+'+w1;
w:='';
inc_uzet;
dekodiraj1(v);
if lpl then w:='('+w+')/'+w1
else w:=w+'/'+w1;
if najbl=zad then ispisi;
end;
if abs(abs(niz[v] div niz[u]-niz[v1])-zad)<abs(najbl-zad) then begin
najbl:=abs(niz[v] div niz[u]-niz[v1]);
w:='';
inc_uzet;
if niz[v] div niz[u]>niz[v1] then begin
dekodiraj1(v1);
if lpl then w1:='('+w+')'
else w1:=w;
w:='';
inc_uzet;
dekodiraj1(u);
w1:='('+w+')-'+w1;
w:='';
inc_uzet;
dekodiraj1(v);
if lpl then w:='('+w+')/'+w1
else w:=w+'/'+w1;
end
else begin
dekodiraj1(u);
w1:='('+w+')';
w:='';
inc_uzet;
dekodiraj1(v);
if lpl then w1:='('+w+')/'+w1
else w1:=w+'/'+w1;
w:='';
inc_uzet;
dekodiraj1(v1);
w:=w+'-'+w1;
end;
if najbl=zad then ispisi;
end;
end;
end;
end;
end;
end;
end;
begin
readln(zad);
for u:=1 to 6 do
begin
read(niz[u]);
if niz[u]=zad then begin
writeln(zad);
writeln(zad);
repeat until keypressed;
halt(0);
end;
end;
pok:=7;
w:='';
for u:=1 to 209406 do
uradi(u);
najbl:=0;
resi_6;
resi_3_3;
resi_2_2_2;
writeln(najbl);
writeln(w);
repeat until keypressed;
end.
|
|
|
|
|
LMGTFY[^]
Seriously? You dump 743 lines of Pascal in a question, and expect someone here to convert it for you?
Either find a tool to do the conversion, or convert it yourself.
If you get stuck with A SPECIFIC PART of the conversion, someone here will probably be able to help. But nobody is going to convert the whole program for you!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Don't.
It may seem to fit the bill for you homework question, but blindly converting code from one language to another does not normally produce code that is any good in the destination language. Pascal is not C#, and does not use the same underlying framework. If you must, understand how it's doing whatever it is doing, and adapt the algorithms to C# in a new application. But don't try and get it translated and assume you will get a good grade: you won't. And that's ignoring that your tutor is aware this site exists and will almost certainly spot the plagiarism...
Besides: that code is very, very poor - it looks like it was written by three chimpanzees who never actually spoke to each other ...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
And, as everyone knows, Pascal code must be in all caps. 
|
|
|
|
|
OriginalGriff wrote: written by three chimpanzees
Chimpanzees write better code than that... Maybe it was actually written by a cat walking across the keyboard?
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
modified 13-Dec-16 15:33pm.
|
|
|
|
|
NotPolitcallyCorrect wrote: Chimpanzees write better code than that...
They certainly do! Primate Programming(tm) Inc[^]
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
|
|
I draw a radar screen with C#. In radar screen, planes(PictureBox) can move from start point to end Point. Scanning Line can also run. Although, I cannot code tracking line behind the planes for my poor knowledge. May you help me?
<pre lang="c#"> private void timer1_Tick(object sender, EventArgs e)
{
if (i > 361)
{
i = 0;
rotate = true;
}
else
{
i += 1;
angle = i;
foreach (Control con in this.picRadarRing.Controls)
{
if (con is PictureBox)
{
PictureBox pb = con as PictureBox;
if (angle > s)
{
rotate = true;
}
degg = 90 - (int)Angle(pb.Location, new Point((picRadarRing.Width / 2), (picRadarRing.Height / 2)));
startX = pb.Location.X;
startY = pb.Location.Y;
double dis = Math.Sqrt(Math.Pow(endX - startX, 2) + Math.Pow(endY - startY, 2));
double directionX = (endX - startX) / dis;
double directionY = (endY - startY) / dis;
if (degg == 0)
{
degg = 1;
}
if (degg < 0)
{
degg += 360;
}
if (angle == degg)
{
if (rotate)
{
x1 = pb.Location.X;
y1 = pb.Location.Y;
x1 += directionX * speed * elapsed;
y1 += directionY * speed * elapsed;
pb.Location = new Point((int)x1, (int)y1);
}
rotate = false;
s = (90 - (int)Angle(pb.Location, new Point((picRadarRing.Width / 2), (picRadarRing.Height / 2))));
if (s < 0)
{
s += 360;
}
}
}
private void picRadarRing_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.ResetTransform();
g.TranslateTransform(picRadarRing.Width / 2, picRadarRing.Height / 2);
g.RotateTransform(angle);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawImage(hand, 0.00f, 0.00f, 5, (picRadarRing.Width / 2) - 4);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
private void btnAdd_Click(object sender, EventArgs e)
{
if ((txtSy.Text == "") || (txtSx.Text == "") || (txtEndY.Text == "") || (txtEndX.Text == ""))
{
MessageBox.Show("Enter Point");
}
else
{
count += 1;
endX = Convert.ToDouble(txtEndX.Text);
endY = Convert.ToDouble(txtEndY.Text);
Tx = Convert.ToInt32(txtSx.Text);
Ty = Convert.ToInt32(txtSy.Text);
Airplane(Tx, Ty);
timer1.Start();
}
}
private double Angle(Point start, Point end)
{
return Math.Atan2(start.Y - end.Y, end.X - start.X) * Rad2Deg;
}
private void Airplane(int TX, int TY) // to Create air thread picturebox
{
PictureBox pic = new PictureBox();
foreach (Control con in this.picRadarRing.Controls)
{
if (con is PictureBox)
{
if (con.Name == "airplane")
{
this.picRadarRing.Controls.Remove(con);
}
}
}
this.picRadarRing.Controls.Add(pic);
pic.BackColor = Color.Red;
pic.Location = new Point(TX, TY);
pic.Size = new Size(7, 7);
pic.Name = "airplane-" + count;
}
modified 13-Dec-16 14:23pm.
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
So show us what you do to make the planes move, and what you have tried to draw the "scanning lines" - we can't really help from little or no information!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
You're going about this all wrong.
Specifically, you're liberal use of PictureBoxes. The PB control is just a quick'n'dirty control to show an image. It is not designed to handle layering and animation and is just going to complicate things for you, immensly.
What you should do is get rid of all the PictureBox controls and handle all the drawing yourself on the surface of a control, like a Panel. You get the greatest amount of control this way. This is kind of what you're doing in the Paint event of whatever control that is.
Also, SetStyle calls should never show up in a Paint handler or any other drawing code. That's a one-time use call that should show up only in the constructor of a custom control or form.
|
|
|
|
|
To elaborate on Dave Kreskowiak's post.
- You need a panel (you can change the background color if you like)
- Learn GDI+ if working with winforms. Basically it involves putting the handle of the panel into a Graphics object and from there you get access to drawing tools like lines, ellipses, rectangles, ...
- If you do have the Graphics object you need code in place to redraw everything, else all the updates will draw over the previous situation.
This should get you started.
|
|
|
|
|
|
hello pple, my name is patrick, a university student persuing a bsc in computer science. am thinking of coming up with a software that uses fingerprint to carry pout transactions, i need help on how to do it kindly
|
|
|
|
|
What have you tried?
Where are you stuck?
What help do you need?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|