gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control system
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 97dc71e)
raw | patch | inline | side by side (parent: 97dc71e)
author | Doni Pracner <quinnuendo@gmail.com> | |
Tue, 26 May 2015 12:15:35 +0000 (14:15 +0200) | ||
committer | Doni Pracner <quinnuendo@gmail.com> | |
Tue, 26 May 2015 12:15:35 +0000 (14:15 +0200) |
kodovi/polinomi/PolinomFajlovi.java | [new file with mode: 0644] | patch | blob |
kodovi/polinomi/poli1.txt | [new file with mode: 0644] | patch | blob |
kodovi/polinomi/poli2.txt | [new file with mode: 0644] | patch | blob |
diff --git a/kodovi/polinomi/PolinomFajlovi.java b/kodovi/polinomi/PolinomFajlovi.java
--- /dev/null
@@ -0,0 +1,49 @@
+/**
+ * U fajlu je polinom predstavljen parovima koeficijenata i stepenova (tip
+ * double i int). Učitati dva polinoma iz fajlova “poli1.txt” i “poli2.txt” i
+ * njihov zbir ispisati u “polizbir.txt”, a proizvod u “poliproizvod.txt”, u
+ * formatu kao što je u ulaznim fajlovima (parovi koeficijent i stepen za svaki
+ * monom).
+ *
+ */
+public class PolinomFajlovi {
+
+ public static PolinomL ucitajPolinom(String imef) {
+ PolinomL rez = new PolinomL();
+ while (!Svetovid.in(imef).isEmpty()) {
+ double koef = Svetovid.in(imef).readDouble();
+ int step = Svetovid.in(imef).readInt();
+ rez.postaviClan(koef, step);
+ }
+ Svetovid.in(imef).close();
+
+ return rez;
+ }
+
+ public static void snimiPolinom(PolinomL p, String imef) {
+ // pravimo petlju da prodjemo kroz sve stepene koji mogu postojati
+ int maksimalniStepen = p.maksimalniStepen();
+ for (int stepen = maksimalniStepen; stepen >= 0; stepen--) {
+ double koef = p.koeficijentUz(stepen);
+ // ne zelimo da stampamo nula koeficijente
+ if (koef != 0.0) {
+ Svetovid.out(imef).print(koef);
+ Svetovid.out(imef).print(" ");
+ Svetovid.out(imef).println(stepen);
+ }
+ }
+ Svetovid.out(imef).close();
+ }
+
+ public static void main(String[] args) {
+ PolinomL p1 = ucitajPolinom("poli1.txt");
+ PolinomL p2 = ucitajPolinom("poli2.txt");
+
+ System.out.println(p1);
+ System.out.println(p2);
+
+ snimiPolinom(p1.saberi(p2), "polizbir.txt");
+ snimiPolinom(p1.puta(p2), "poliproizvod.txt");
+ }
+
+}
diff --git a/kodovi/polinomi/poli1.txt b/kodovi/polinomi/poli1.txt
--- /dev/null
@@ -0,0 +1,3 @@
+2 8
+0.5 3
+-2 1
\ No newline at end of file
diff --git a/kodovi/polinomi/poli2.txt b/kodovi/polinomi/poli2.txt
--- /dev/null
@@ -0,0 +1,3 @@
+37.2 112
+-0.8 111
+-2 8
\ No newline at end of file