Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Uses crt;
- Type
- point= ^da_thuc;
- da_thuc= record
- he_so, so_mu: integer;
- link: point;
- end;
- Var
- firstT, lastT, firstP, firstQ, T, P, Q : point;
- stt,vtriQ,num1,num2:integer;
- tl1:byte;
- {Ve 1 phan tu}
- Procedure Ve_DS(a,x,stt,mau:integer);
- var hag,cot:integer;
- begin
- textcolor(mau);
- hag:=stt div 6+1;
- cot:=(stt mod 6)+1;
- if ((hag<>2) and (hag<>3) and (hag>1) and (cot=1)) then
- begin
- writeln;
- write('-',#16);
- end;
- {Ve khung}
- gotoxy(-10+cot*13,hag*3+5); writeln('ÉÍÍÍËÍÍÍËÍ»');
- gotoxy(-10+cot*13,hag*3+6); writeln('º',a:2,' º',x:2,' º º');
- gotoxy(-10+cot*13,hag*3+7); writeln('ÈÍÍÍÊÍÍÍÊͼ');
- {Ve them dau ->}
- if cot>1 then
- begin
- gotoxy(-1+(cot-1)*13,hag*3+6);
- writeln('ĺ-',#16);
- end;
- textcolor(white);
- End;
- {Ve khung hien thi tren dau}
- Procedure Box(s:string);
- var k:integer;
- begin
- textcolor(white);
- gotoxy(20,2); write('É');
- for k:=21 to 54 do write('Í');
- write('»');
- gotoxy(20,3); write('º');
- gotoxy(55,3); write('º');
- gotoxy(20,4); write('º');
- gotoxy(55,4); write('º');
- textcolor(red);
- gotoxy(31,3); writeln('Cong hai da thuc');
- textcolor(yellow);
- gotoxy(25,4); writeln(s);
- textcolor(white);
- gotoxy(20,5); write('È');
- for k:=21 to 54 do write('Í');
- writeln('¼');
- End;
- {Ve tat ca cac phan tu}
- Procedure Display(Z,first:point; vtri,mau:integer; name:char);
- var vt:integer;
- begin
- Z:=first;
- vt:=vtri;
- gotoxy(1,9+vt div 2); writeln(name);
- while z<> nil do
- begin
- Ve_DS(z^.he_so,z^.so_mu,vt,mau);
- inc(vt);
- z:=z^.link;
- end;
- End;
- {Nhap thong tin cho da thuc}
- Procedure input(Var X,firstX:point;var num:integer; name:char);
- var n,a,temp,i: integer;
- answer:char;
- s:string[40];
- begin
- s:='Nhap du lieu cho da thuc '+name;
- firstX:=nil; i:=0;
- repeat
- clrscr;
- Box(s);
- inc(i);
- writeln('Nhap hang tu thu ', i,': ');
- if i=1 then
- begin
- write('nhap so mu: ');
- readln(n);
- end
- else
- repeat
- textcolor(red);
- Writeln('Luu y: so mu phai lon hon so mu truoc');
- writeln('So mu cua phan tu truoc la: ',temp);
- textcolor(white);
- write('nhap so mu cua hang tu: '); readln(n);
- until n>temp;
- Repeat
- write('nhap he so(a # 0): '); readln(a);
- until a<>0;
- new(x);
- x^.so_mu:=n;
- x^.he_so:=a;
- x^.link:=firstX;
- firstX:=x;
- temp:=n; {Luu lai so mu cua phan tu de so sanh voi so mu cua ptu tiep theo}
- write('Tiep tuc (C/K)?????: ');
- readln(answer);
- until (answer='K') or (answer='k');
- num:=i;
- End;
- {In da thuc voi cac truong hop dac biet }
- procedure writeout(X:point);
- begin
- if x^.he_so=1 then
- if x^.so_mu=0 then write('1')
- else
- if x^.so_mu=1 then write('x ')
- else
- write('x',x^.so_mu,' ')
- else
- if x^.he_so=-1 then
- if x^.so_mu=0 then write('-1')
- else
- if x^.so_mu=1 then write('-x ')
- else
- write('-x',x^.so_mu,' ')
- else
- if x^.so_mu=0 then write(x^.he_so,' ')
- else
- if x^.so_mu=1 then write(x^.he_so,'x ')
- else
- write(x^.he_so,'x',x^.so_mu,' ')
- End;
- {In da thuc}
- procedure output(X,firstX:point; name:char; mau:integer);
- begin
- textcolor(mau);
- write('Da thuc ',name, '= ');
- x:=firstX;
- if firstX=nil then write('0'); {danh sach khong co phan tu nao}
- while x<>nil do
- begin
- if x^.he_so < 0 then
- writeout(x)
- else
- begin
- if x=firstX then writeout(x) {In phan tu dau tien >0}
- else {In cac phan tu tiep theo}
- begin
- write('+ ');
- writeout(x);
- end;
- end;
- x:=x^.link;
- end;
- writeln;
- textcolor(white);
- End;
- {Ghi thong tin vao DSLK Tong}
- procedure attach(a,n,stt: integer; var Z, firstZ, lastZ: point);
- begin
- new(z);
- z^.he_so:=a;
- z^.so_mu:=n;
- Ve_DS(a,n,stt,12);
- writeln;
- if firstZ=nil then
- begin
- firstZ:=z;
- lastZ:=z;
- lastZ^.link:=nil;
- end
- else
- begin
- lastZ^.link:=z;
- lastZ:=z;
- lastZ^.link:=nil;
- end;
- delay(2500);
- End;
- {Tinh tong hai da thuc}
- procedure plus(X,firstX,Y,firstY: point; var Z,firstZ,lastZ:point);
- var add,vtP,vtQ:integer;
- begin
- x:=firstX;
- y:=firstY;
- firstZ:=nil;
- lastZ:=nil;
- vtP:=0; vtQ:=vtriQ;
- delay(1000);
- {To mau cho phan tu dau tien cua 2 da thuc}
- Ve_DS(x^.he_so,x^.so_mu,vtP,4);
- Ve_DS(y^.he_so,y^.so_mu,vtQ,4);
- delay(1111);
- while (x<>nil) and (y<>nil) do
- begin
- if x^.so_mu=y^.so_mu then
- begin
- add:=x^.he_so+y^.he_so;
- if add<>0 then
- begin
- attach(add,x^.so_mu,stt,Z,firstZ,lastZ);
- inc(stt);
- end;
- x:=x^.link;
- y:=y^.link;
- inc(vtP); inc(vtQ);
- {To mau cho phan tu tiep theo cua 2 da thuc neu con}
- if (x<>nil)then
- Ve_DS(x^.he_so,x^.so_mu,vtP,4);
- if (y<>nil)then
- Ve_DS(y^.he_so,y^.so_mu,vtQ,4);
- delay(1000);
- end
- else
- begin
- if x^.so_mu>y^.so_mu then
- begin
- attach(x^.he_so,x^.so_mu,stt,Z,firstZ,lastZ);
- inc(stt);
- x:=x^.link;
- inc(vtP);
- if x<> nil then
- begin
- Ve_DS(x^.he_so,x^.so_mu,vtP,4); {To mau phan tu tiep theo neu con}
- delay(1000);
- end;
- end
- else
- begin
- attach(y^.he_so,y^.so_mu,stt,Z,firstZ,lastZ);
- inc(stt);
- y:=y^.link;
- inc(vtQ);
- if y<>nil then
- begin
- Ve_DS(y^.he_so,y^.so_mu,vtQ,4); {To mau phan tu tiep theo neu con}
- delay(1000);
- end;
- end;
- end;
- end;
- {Khi da thuc Q het}
- while x<>nil do
- begin
- attach(x^.he_so,x^.so_mu,stt,Z,firstZ,lastZ);
- inc(stt);
- x:=x^.link;
- inc(vtP);
- if x<>nil then
- begin
- Ve_DS(x^.he_so,x^.so_mu,vtP,4);
- delay(1000);
- end;
- end;
- {Khi da thuc P het}
- while y<>nil do
- begin
- attach(y^.he_so,y^.so_mu,stt,Z,firstZ,lastZ);
- inc(stt);
- y:=y^.link;
- inc(vtQ);
- if y<> nil then
- begin
- Ve_DS(y^.he_so,y^.so_mu,vtQ,4);
- delay(1000);
- end;
- end;
- End;
- BEGIN
- Repeat
- clrscr;
- Box(' Bai tap so 4');
- gotoxy(10,7); write('Menu Chuc nang.');
- gotoxy(10,9); write('Phim 1. Nhap da thuc.');
- gotoxy(10,10); write('Phim 2. Mo phong qua trinh tinh tong.');
- gotoxy(10,11); write('Phim 3. Ket qua.');
- gotoxy(10,12); write('Phim 4. Thoat.');
- gotoxy(10,14); write('Phim chuc nang: '); readln(tl1);
- case tl1 of
- 1: begin
- writeln('nhap da thuc P:');
- input(P,firstP,num1,'P');
- writeln('nhap da thuc Q:');
- input(Q,firstQ,num2,'Q');
- writeln('Nhan Enter de quay lai Menu chuc nang.');
- readln;
- end;
- 2: begin
- clrscr;
- Box('Mo phong qua trinh tinh tong.');
- output(P,firstP,'P',3);
- output(Q,firstQ,'Q',2);
- Display(P,firstP,0,3,'P');
- writeln;
- if num1<7 then
- begin
- vtriQ:=6;
- if num2<7 then
- stt:=12
- else
- stt:=18;
- end
- else
- begin
- vtriQ:=12;
- if num2<7 then
- stt:=18
- else
- stt:=24;
- end;
- Display(Q,firstQ,vtriQ,2,'Q');
- plus(P,firstP,Q,firstQ,T,firstT,lastT);
- output(T,firstT,'T',7);
- writeln('Nhan Enter de quay lai Menu chuc nang.');
- readln;
- end;
- 3: begin
- clrscr;
- Box(' Ket qua');
- output(P,firstP,'P',3);
- output(Q,firstQ,'Q',2);
- output(T,firstT,'T',7);
- writeln('Nhan Enter de quay lai Menu chuc nang.');
- readln;
- end;
- 4: begin
- Textmode(c40);
- textcolor(red);
- gotoxy(16,13); write('Hen gap lai.');
- delay(1250);
- end;
- end;
- until tl1=4;
- END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement