Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Napisati klasu Predmet koja sadrži polja:
- Id – automatski generisan celi broj
- Naziv
- Šifra
- Ocena
- Napraviti formu koja omogućava unos pomenutih podataka (osim ID-a) i smešta objekte tipa Predmet u ListBox kontrolu. Dodati dugme “prosek” koje omogućava prikaz prosečne ocene za sve unete predmete.
- Na postojeću formu dodati tekstualno polje za unos broja indeksa studenta u formatu SSSS-BB/GG (smer-broj-godina).
- Dodati dugme “snimi” koje će omogućiti snimanje unetih predmeta u datoteku koja sadži broj indeksa studenta i ekstenziju “pol” (položeno).
- Dodati dugme “pročitaj” koje će omogućiti pronalaženje datoteke sa zadatim brojem indeksa i prikaz položenih predmeta (pročitanih iz datoteke) u ListBox kontroli.
- Voditi računa o mogućim izuzecima u radu sa datotekama, prikazivati korisniku odgovarajuće poruke.
- 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;
- using System.IO;
- namespace V6G1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void btnDodaj_Click(object sender, EventArgs e)
- {
- Predmet p = new Predmet(txtNaziv.Text, txtSifra.Text,
- int.Parse(txtOcena.Text));
- lbPredmeti.Items.Add(p);
- }
- private void btnProsek_Click(object sender, EventArgs e)
- {
- int s=0;
- for (int i = 0; i < lbPredmeti.Items.Count; i++)
- {
- Predmet p = lbPredmeti.Items[i] as Predmet;
- s += p.Ocena;
- }
- lblProsek.Text = (s*1.0 / lbPredmeti.Items.Count).ToString();
- }
- private void btnSnimi_Click(object sender, EventArgs e)
- {
- //NRT-10/10 -> NRT1010.pol
- string putanja=txtIndeks.Text.Replace("-","").Replace("/", "");
- putanja+=".txt";
- FileStream fs =
- new FileStream(putanja, FileMode.Create, FileAccess.Write);
- StreamWriter writer = new StreamWriter(fs);
- for (int i = 0; i < lbPredmeti.Items.Count; i++)
- {
- Predmet p = lbPredmeti.Items[i] as Predmet;
- string linija = p.Naziv + "|" + p.Sifra + "|" + p.Ocena;
- writer.WriteLine(linija);
- }
- writer.Close();
- }
- private void btnProcitaj_Click(object sender, EventArgs e)
- {
- string putanja = txtIndeks.Text.Replace("-", "").Replace("/", "");
- putanja += ".txt";
- FileStream fs =
- new FileStream(putanja, FileMode.Open, FileAccess.Read);
- StreamReader reader = new StreamReader(fs);
- lbPredmeti.Items.Clear();
- while (!reader.EndOfStream)
- {
- string linija = reader.ReadLine();
- string[] podaci = linija.Split('|');
- Predmet p = new Predmet(podaci[0], podaci[1],
- int.Parse(podaci[2]));
- lbPredmeti.Items.Add(p);
- }
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace V6G1
- {
- class Predmet
- {
- static int idGen = 1;
- int id = idGen++;
- string naziv;
- string sifra;
- int ocena;
- public Predmet(string naziv, string sifra, int ocena)
- {
- this.naziv = naziv;
- this.sifra = sifra;
- this.ocena = ocena;
- }
- public override string ToString()
- {
- return naziv + " " + ocena;
- }
- public string Naziv { get { return naziv; } }
- public string Sifra { get { return sifra; } }
- public int Ocena { get { return ocena; } }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Forms;
- namespace V6G1
- {
- static class Program
- {
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
- }
- }
- }
Add Comment
Please, Sign In to add comment