0% found this document useful (0 votes)
59 views

Vezba 02 Visual Studio

The document describes adding controls and classes to a form application to calculate the perimeter and area of squares and rectangles. Radio buttons are added to select square or rectangle, with text boxes for length and width. Classes are created for Rectangle and Square, with Square inheriting from Rectangle. On a button click, the appropriate class is instantiated and its perimeter and area methods called and displayed in a message box. The homework is to extend this to calculate perimeter and area of different types of triangles using inheritance.

Uploaded by

slomljeni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Vezba 02 Visual Studio

The document describes adding controls and classes to a form application to calculate the perimeter and area of squares and rectangles. Radio buttons are added to select square or rectangle, with text boxes for length and width. Classes are created for Rectangle and Square, with Square inheriting from Rectangle. On a button click, the appropriate class is instantiated and its perimeter and area methods called and displayed in a message box. The homework is to extend this to calculate perimeter and area of different types of triangles using inheritance.

Uploaded by

slomljeni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

VEBA 2

Na formu se dodaju sledee kontrole:



radio button - rbKvadrat
radio button - rbPravougaonik
tekstualno polje - txtStranicaA
tekstualno polje - txtStranicaB
dugme - btnIzracunaj

(imena labela neemo posebno postavljati)

Dodaju se sledee klase:

Pravougaonik.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Trigonometrija
{
class Pravougaonik
{
private double stranicaA;
private double stranicaB;

public Pravougaonik() { }

public Pravougaonik(double aa, double bb)
{
StranicaA = aa;
StranicaB = bb;
}

public double StranicaA
{
get { return stranicaA; }
set
{
stranicaA = value;
if (stranicaA < 0)
{
stranicaA = 0;
}
}
}

public double StranicaB
{
get { return stranicaB; }
set
{
stranicaB = value;
if (stranicaB < 0)
{
stranicaB = 0;
}
}
}

public virtual double Obim()
{
if ((StranicaA == 0) || (StranicaB == 0))
return 0;
return 2 * StranicaA + 2 * StranicaB;
}

public virtual double Povrsina()
{
if ((StranicaA == 0) || (StranicaB == 0))
return 0;
return StranicaA * StranicaB;
}
}
}

Kvadrat.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Trigonometrija
{
class Kvadrat : Pravougaonik
{
public Kvadrat() { }
public Kvadrat(double aa) : base(aa, aa) { }
}
}


Kod koji se dodaje u pozadinu forme je sledei:

Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Trigonometrija
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
txtStranicaB.Enabled = false;
}

private void rbKvadrat_CheckedChanged(object sender, EventArgs e)
{
txtStranicaB.Enabled = false;
}

private void rbPravougaonik_CheckedChanged(object sender, EventArgs e)
{
txtStranicaB.Enabled = true;
}

private void btnIzracunaj_Click(object sender, EventArgs e)
{
if (rbKvadrat.Checked)
{
Kvadrat k = new Kvadrat(Convert.ToDouble(txtStranicaA.Text));
MessageBox.Show("Obim: " + k.Obim() + "\n" +
"Povrsina: " + k.Povrsina());
}
else
{
Pravougaonik p = new Pravougaonik(
Convert.ToDouble(txtStranicaA.Text),
Convert.ToDouble(txtStranicaB.Text));
MessageBox.Show("Obim: " + p.Obim() + "\n" +
"Povrsina: " + p.Povrsina());
}
}
}
}

Potrebno je povezati dogaaje u kodu sa komponentama na formi!

Zadatak za domai rad:

Napraviti aplikaciju koja rauna obim i povrinu raznostraninog, jednakokrakog i
jednakostraninog trougla. Aplikaciju uraditi primenom nasleivanja.

You might also like