Você está na página 1de 4

Probleme Lab.

5
Problema 1 macrouri
#include<stdio.h>
#include<conio.h>
enum boolean {false, true};
#define MAXIM(x,y) (x)>(y) ?(x):(y)
#define MINIM(x,y) (x)<(y) ?(x):(y)
#define EGAL(x,y) (x)==(y)?true:false
void main(void){
int a,b;
int m;
clrscr();
scanf("a=%d b=%d", &a, &b);
m = MAXIM(a,b);
printf("\nMaximul este:%d",m);
m = MINIM(a,b);
printf("\nMinimul este:%d",m);
puts("\nTestarea egalitatii:");
if(EGAL(a,b))
puts("Sunt egale!");
else
puts("Nu sunt egale!");
getch();
}

Problema 2 desenare deptunghi simplu si dublu


#include<stdio.h>
#include<conio.h>
#include<ctype.h>
//functie pentru trasare linie orizontala
void linieOrizontala(int startX, int stopX, int coordY, char tipLinie) {
int i;
gotoxy(startX, coordY);
for(i=startX; i<=stopX; i++)
putch(tipLinie);
}
//functie pentru trasare linie verticala
void linieVerticala(int startY, int stopY, int coordX, char tipLinie) {
int i;
for(i=startY; i<=stopY; i++) {
gotoxy(coordX, i);
putch(tipLinie);
}
}
//finctie pentru trasare colturi
void colt(int coordX, int coordY, char tipColt) {
gotoxy(coordX, coordY);
putch(tipColt);
}
void dreptunghiSimplu(int xs, int ys, int xj, int yj) {
colt(xs, ys, 0xda);
linieOrizontala(xs+1, xj-1, ys, 0xc4);
colt(xj,ys, 0xbf);
linieVerticala(ys+1, yj-1, xj, 0xb3);
colt(xj, yj, 0xd9);
linieVerticala(ys+1, yj-1, xs, 0xb3);
colt(xs, yj, 0xc0);

linieOrizontala(xs+1, xj-1, yj, 0xc4);


}
void dreptunghiDublu(int xs, int ys, int xj, int yj) {
colt(xs, ys, 0xc9);
linieOrizontala(xs+1, xj-1, ys, 0xcd);
colt(xj,ys, 0xbb);
linieVerticala(ys+1, yj-1, xj, 0xba);
colt(xj, yj, 0xbc);
linieVerticala(ys+1, yj-1, xs, 0xba);
colt(xs, yj, 0xc8);
linieOrizontala(xs+1, xj-1, yj, 0xcd);
}
void fereastra(int x1, int y1, int x2, int y2, char tipDr) {
switch(tolower(tipDr)) {
case 's':
dreptunghiSimplu(x1, y1, x2, y2);
break;
case 'd':
dreptunghiDublu(x1, y1, x2, y2);
break;
}

};

void main(void) {
_setcursortype(_NOCURSOR);
clrscr();
fereastra(1,1,79,25,'s');
fereastra(10,10, 40, 20,'d');
getch();
_setcursortype(_NORMALCURSOR);
clrscr();
}

Problema 3- desenarea unui dreptunghi care se misca cu ajutorul sagetilor


#include<stdio.h>
#include<conio.h>
#define
#define
#define
#define
#define
#define
void
void
void
void
void
void
void
void
void

ESC 0x1b
SAGEATA_STANGA 0x4B
SAGEATA_SUS 0x48
SAGEATA_DREAPTA 0x4D
SAGEATA_JOS 0x50
PAS 1

desen(int& x1, int& y1, int& x2, int& y2);


linieOrizontala(int startX, int stopX, int coordY, char tipLinie);
linieVerticala(int startY, int stopY, int coordX, char tipLinie);
colt(int coordX, int coordY, char tipColt);
dreptunghiSimplu(int xs, int ys, int xj, int yj);
mutaStanga(int& x1, int y1, int& x2, int y2);
mutaDreapta(int& x1, int y1, int& x2, int y2);
mutaSus(int x1, int& y1, int x2, int& y2);
mutaJos(int x1, int& y1, int x2, int& y2);

void main(void) {
_setcursortype(_NOCURSOR);
int x1, y1, x2, y2;
clrscr();

//parametrii ecranului
struct text_info parecr;
gettextinfo(&parecr);
printf("\ninaltimea ecranului: %d latimea ecranului %d",
parecr.screenheight, parecr.screenwidth);
printf("\nx1="); scanf("%d", &x1);
printf("\ny1="); scanf("%d", &y1);
printf("\nx2="); scanf("%d", &x2);
printf("\ny2="); scanf("%d", &y2);
fflush(stdin);
desen(x1, y1, x2, y2);
gotoxy(30,25);
cprintf("S-a apasat tasta ESC");
getch();
clrscr();
_setcursortype(_NORMALCURSOR);
}
void mutaStanga(int& x1, int y1, int& x2, int y2) {
if(x1-PAS >=1) {
x1 -=PAS;
x2 -=PAS;
clrscr();
dreptunghiSimplu(x1,y1,x2, y2);
}
}
void mutaSus(int x1, int& y1, int x2, int& y2) {
if(y1-PAS >=1) {
y1 -=PAS;
y2 -=PAS;
clrscr();
dreptunghiSimplu(x1,y1,x2, y2);
}
}
void mutaDreapta(int& x1, int y1, int&x2, int y2) {
if(x2+PAS <= 80) {
x1 += PAS;
x2 += PAS;
clrscr();
dreptunghiSimplu(x1,y1,x2,y2);
}
}
void mutaJos(int x1, int& y1, int x2, int& y2) {
if(y2 + PAS < 25) {
y1 +=PAS;
y2 +=PAS;
clrscr();
dreptunghiSimplu(x1,y1,x2, y2);
}
}
void desen(int& x1, int& y1, int& x2, int& y2) {
char c;
dreptunghiSimplu(x1, y1, x2, y2);
do {
c = getch();
if(c==0x00)
c=getch();

switch(c){
case SAGEATA_STANGA:
mutaStanga(x1, y1, x2, y2);
break;
case SAGEATA_DREAPTA:
mutaDreapta(x1,y1,x2,y2);
break;
case SAGEATA_SUS:
mutaSus(x1,y1,x2,y2);
break;
case SAGEATA_JOS:
mutaJos(x1,y1,x2,y2);
break;
default: fflush(stdin);
};
}while(c != ESC);

//functie pentru trasare linie orizontala


void linieOrizontala(int startX, int stopX, int coordY, char tipLinie) {
int i;
gotoxy(startX, coordY);
for(i=startX; i<=stopX; i++)
putch(tipLinie);
}
//functie pentru trasare linie verticala
void linieVerticala(int startY, int stopY, int coordX, char tipLinie) {
int i;
for(i=startY; i<=stopY; i++) {
gotoxy(coordX, i);
putch(tipLinie);
}
}
//finctie pentru trasare colturi
void colt(int coordX, int coordY, char tipColt) {
gotoxy(coordX, coordY);
putch(tipColt);
}
void dreptunghiSimplu(int xs, int ys, int xj, int yj) {
colt(xs, ys, 0xda);
linieOrizontala(xs+1, xj-1, ys, 0xc4);
colt(xj,ys, 0xbf);
linieVerticala(ys+1, yj-1, xj, 0xb3);
colt(xj, yj, 0xd9);
linieVerticala(ys+1, yj-1, xs, 0xb3);
colt(xs, yj, 0xc0);
linieOrizontala(xs+1, xj-1, yj, 0xc4);
}

Você também pode gostar