Skip to content

Instantly share code, notes, and snippets.

@zuigon
Created May 7, 2014 10:14
Show Gist options
  • Save zuigon/5577b65827baa3cbc262 to your computer and use it in GitHub Desktop.
Save zuigon/5577b65827baa3cbc262 to your computer and use it in GitHub Desktop.
using System;
namespace LV11
{
class Zarulja {
private bool stanje;
public Zarulja(){
stanje = false;
}
public Zarulja(bool s){
stanje = s;
}
public void pali(){
System.Threading.Thread.Sleep(200);
Console.Write ("ON ");
stanje = true;
}
public void gasi(){
System.Threading.Thread.Sleep(200);
Console.Write ("OFF ");
stanje = false;
}
public bool is_on(){
return stanje;
}
}
public class Kompleksni
{
private double Re, Im;
public Kompleksni(double x, double y)
{
Re = x;
Im = y;
}
public void Ispisi()
{
Console.WriteLine("{0} + {1}i", Re, Im);
}
public void MnoziSkalarom(Kompleksni z, double skalar)
{
Re = z.Re * skalar;
Im = z.Im * skalar;
}
public void Zbroji(Kompleksni z1, Kompleksni z2)
{
Re = z1.Re + z2.Re;
Im = z1.Im + z2.Im;
}
public void Oduzmi(Kompleksni z1, Kompleksni z2)
{
Re = z1.Re - z2.Re;
Im = z1.Im - z2.Im;
}
public void MnoziKompleksnim(Kompleksni z1, Kompleksni z2)
{
// ac - bd + i(bc + ad)
Re = z1.Re * z2.Re - z1.Im * z2.Im;
Im = z1.Im * z2.Re + z1.Re * z2.Im;
}
public void DijeliKompleksnim(Kompleksni z1, Kompleksni z2)
{
if (z2.Im * z2.Im + z2.Re * z2.Re == 0)
throw new Exception ("Ne mogu ...");
// Re = z1.Re + z2.Re;
// Im = z1.Im + z2.Im;
}
public double Modul()
{
return Math.Sqrt (Re*Re + Im*Im);
}
}
class PrepaidKartica {
protected double stanje;
public PrepaidKartica(){
stanje = 10;
}
public PrepaidKartica(double k){
stanje = k;
}
public double iznos(){
return stanje;
}
public void nadoplati(double k){
stanje += k;
}
}
class Tele2Kart : PrepaidKartica {
const double cijena_sms = 0.29;
public void salji_sms(string poruka, string broj){
stanje -= cijena_sms;
}
}
class MainClass
{
public static void Main (string[] args)
{
var osram = new Zarulja ();
Console.WriteLine ("bok!");
for (int i = 0; i < 3; ++i) {
osram.pali ();
osram.gasi ();
}
Console.WriteLine ("Done.");
Console.WriteLine ();
Kompleksni a = new Kompleksni (2, 3);
Console.WriteLine("Modul kompl. broja: {0}", a.Modul ());
Console.WriteLine ();
var kart = new Tele2Kart ();
Console.WriteLine ("Pocetno stanje racuna: {0}kn", kart.iznos ());
kart.salji_sms ("Bok!", "0991234567");
Console.WriteLine ("A sad: {0}kn", kart.iznos());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment