Skip to content

Instantly share code, notes, and snippets.

@nebjak
Created May 14, 2011 17:25
Show Gist options
  • Save nebjak/972410 to your computer and use it in GitHub Desktop.
Save nebjak/972410 to your computer and use it in GitHub Desktop.
predavanje2
using System;
namespace predavanje2
{
public class NizOblika
{
private Oblik[] nizO;
private int duzina;
public NizOblika(int d) {
nizO = new Oblik[d];
duzina = d;
}
public void popuniNiz() {
double pp, a, b;
for(int i=0; i < duzina; i++) {
Console.Write("Sta zelite da dodate? Krug ili Pravougaonik (k/p):");
switch(Convert.ToChar(Console.ReadLine())) {
case 'k':
Console.Write("Unesite poluprecnik kruga br. "+ (i+1) +": ");
pp = Convert.ToDouble(Console.ReadLine());
dodajKrug(new Krug(pp), i);
break;
case 'p':
Console.Write("Unesite duzinu stranice a: ");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("Unesite duzinu stranice b: ");
b = Convert.ToDouble(Console.ReadLine());
dodajPravougaonik(new Pravougaonik(a,b), i);
break;
default:
Console.WriteLine("Pogresan unos! Dodacete krug!");
Console.Write("Unesite poluprecnik kruga br. "+ (i+1) +": ");
pp = Convert.ToDouble(Console.ReadLine());
dodajKrug(new Krug(pp), i);
break;
}
}
}
private void dodajKrug(Krug k, int i) {
nizO[i] = k;
}
private void dodajPravougaonik(Pravougaonik p, int i) {
nizO[i] = p;
}
public void ispisiSve() {
for(int i=0; i<duzina;i++) {
nizO[i].ispis();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment