You are on page 1of 2

Vtor parcijalen ispit po

APLIKATIVEN SOFTVER
Skopje, 12.06.2003
Na po~etokot na programata vo komentar da se napi{e
ime, prezime i broj na indeks.

Da se razvie klasa Polinom koja slu`i za rabota so polinomi so celobrojni


koeficienti. Za sekoj polinom se ~uva negoviot red (order) i koeficientite.
Koeficientite se smesteni vo dinami~ki alocirano pole od order+1 celi broevi kon
koe poka`uva koef. Pri toa koeficientot pred slobodniot ~len se ~uva vo koef[0] i
soodvetno koeficientot pred n-tiot ~len vo koef[n]. Osnovniot konstruktor,
pomo{nata funkcija Reduce() i operatorot << se dadeni gotovi. Konstruktorot
konstruira Polinom od negovata reprezentacija kako niza od znaci.
Na primer polinomot: 3x 5  5 x 2  3x  1 se zadava kako nizata “3x5+5x2+3x1-1” ili
“3x5+5x2+3x1-x0”. Da se napi{at potrebnite konstruktori, funkcii i da se
preoptovarat potrebnite operatori taka da programata:
#include <stdlib.h> cout << "C=" << C << endl;
#include <stdio.h> cout << "D=" << D << endl;
#include <string.h> cout << "E=" << E << endl;
#include <iostream.h> cout << "F=" << F << endl;
cout << "G=" << G << endl;
class Polinom // ============= Faza 2
{ cout << "== Faza 2 ==" << endl;
public: D=B; C=-A;
Polinom(const char * = 0, const char x = 'x'); cout << "D.Order=" << D.Order() <<
friend ostream &operator<<(ostream &output, const " D=" << D << endl;
Polinom &x); cout << "C.Order=" << C.Order() <<
. . . " C=" << C << endl;
private: // ============= Faza 3
void Reduce(); cout << "== Faza 3 ==" << endl;
int *koef; if (D==B) cout << "D==B" << endl;
int order; if (D!=B) cout << "D!=B" << endl;
}; if (C==A) cout << "C==A" << endl;
void Polinom::Reduce() // dadena if (C!=A) cout << "C!=A" << endl;
. . . cout << "D(2.5)=" << D.Evaluate(2.5) <<
// Go namaluva redot na polinomot so endl; //vrednosta na polinomot za x=2.5
// otstranuvanje na nulevite koeficienti // ============= Faza 4
// pred povisokite stepeni: cout << "== Faza 4 ==" << endl;
// order4: 0x4+0x3+2x2+0x1+2 -> G=A+B; F+=A;
// order2: 2x2+0x1+2 cout << "G=" << G << endl;
cout << "F=" << F << endl;
Polinom::Polinom(const char * spoli, const char G=A-B; F-=A;
x) // dadena e gotova (dolga) cout << "G=" << G << endl;
. . . cout << "F=" << F << endl;
// Konstruktor koi od niza na znaci // ============= Faza 5
// kostruira polinom so dinamicko cout << "== Faza 5 ==" << endl;
// alociranje na memorijata za G=A*B; // mnozenje na polinomi
// koeficientite cout << "G=" << G << endl;
G[0]++; G[5]=A[1]; // pristap do
ostream &operator<<(ostream &output, const // i menuvanje na koeficientite
Polinom &x) cout << "G=" << G << endl;
// dadena e gotova // ============= Faza 6
cout << "== Faza 6 ==" << endl;
// * * * M A I N * * * Polinom X("7x7+4x6-x5+3x4-5x3+8x2-
main() 3x1+10");
{ Polinom Y("2x3+x2-2x1+1");
// ============= Faza 1 Polinom W,Z;
Polinom A("3x5+5x2+3x1-1"); W="3x2-1";
Polinom B("-2x5-2x3+x5-x1-1x0+2x2+x5+1- cout << "X=" << X << endl;
x0+2"); cout << "Y=" << Y << endl;
Polinom C("7y13-y1-2+2y1-2y2+2",'y'); Z=X/Y; W=X%Y; // delenje na polinomi
Polinom D("x7 -x1 -3+2x1 -4x2 +2"); // i ostatok pri delenje na polinomi
Polinom E("-x5-x3-3+2x1+2x2+2+x3"); cout << "Z=" << Z << endl;
Polinom F(B), G; cout << "W=" << W << endl;
Z=Y/X; W=Y%X;
cout << "A=" << A << endl; cout << "Z=" << Z << endl;
cout << "B=" << B << endl; cout << "W=" << W << endl;
grupa II
dava ispis:
== Faza 1 == == Faza 4 ==
A=3x5+5x2+3x1-1 G=3x5-2x3+7x2+2x1
B=-2x3+2x2-x1+1 F=3x5-2x3+7x2+2x1
C=7x13-2x2+x1 G=3x5+2x3+3x2+4x1-2
D=x7-4x2+x1-1 F=-2x3+2x2-x1+1
E=-x5+2x2+2x1-1 == Faza 5 ==
F=-2x3+2x2-x1+1 G=-6x8+6x7-3x6-7x5+4x4+3x3+4x1-1
G=0 G=-6x8+6x7-3x6+3x5+4x4+3x3+4x1
== Faza 2 == == Faza 6 ==
D.Order=3 D=-2x3+2x2-x1+1 X=7x7+4x6-x5+3x4-5x3+8x2-3x1+10
C.Order=5 C=-3x5-5x2-3x1+1 Y=2x3+x2-2x1+1
== Faza 3 == Z=3x4+2x2-x1
D==B W=x7+x6+x5+4x2-2x1+10
C!=A Z=0
D(2.5)=-20.25 W=2x3+x2-2x1+1