Proszę o wytłumaczenie mi, jak wykorzystać dane przykłady dla moich celów.
-
Phobos core_thread
Chcę stworzyć listę wątków, gdzie każdemu z nich podczas tworzenia będzie podawany real a. Wątek będzie wypisywał w konsoli sin(a) zwracał sin(a).
Chcę przeciążyć operator "sin" tak aby rozpoczynał nowy wątek, aby wypisywał w konsoli sin(a) zwracał sin(a).
input
2
1,2,3,4,5
sin 8
outuput
a= 2 sin(2) = 0.909
a= 1 sin(1) = 0.84
a= 2 sin(2) = 0.909
a= 3 sin(3) = 0.141
a= 4 sin(4) = -0.75
a= 5 sin(5) = -0.95
a=8 sin(8 radius) = 0.989 -
Kod który uruchamia aplikację serwerową, która oblicza sin z argumentu.
Chcę uruchomić aplikację na danym adresie i porcie, która działa podobnie jak pierwszy przykład.
Za pomocą aplikacji klienta chcę wysyłać do serwera argument auto a i otrzymywać wynik sin(a).
Nadal muszę przeciążyć operator "sin"
Tu moje kody jakie udało się doprowadzić do kompilacji:
import std.stdio;
import core.thread;
import core.math;
class DerivedThread : Thread
{
this()
{
super(&run);
}
private:
void run()
{
// Derived thread running.
}
}
void threadFunc()
{
// Composed thread running.
}
class Klasa
{
int a; //to raczej nie potrzebne
this()
{
a=0; //to raczej nie potrzebne
}
private:
real sinus(real liczba){
write("a = ");
writeln(liczba);
write("sin(a)= ");
writeln(sin(liczba));
return sin(liczba);
}
}
void main() {
// create and start instances of each type
auto derived = new DerivedThread().start();
auto composed = new Thread(&threadFunc).start();
new Thread({
// Codes to run in the newly created thread.
}).start();
string c = "Witaj swiecie";
writeln(c);
}
Jak przeciążyć operator "sin "?
Jak wrzucić go aby był możliwy do użycia?
Jak podać listę argumentów do funkcji?
Tu pojawi się drugi kod.