Can someone help me out?!

I have assignment but the teacher didnt tell me what should i do, there's code in a paper and he gave it to me. I wrote down the whole things but i couldn't compile it. can someone take a look at it and help me out?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
  #include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dir.h>

#define CLIP_ON 1
#define CLIP_OFF 0

char judul1[] = "Window 1";
char judul2[] = "Window dengan viewport on";
char judul3[] = "Window dengan viewport off";

int Maxx, Maxy;

void jendela(int, int, int, int, char *, int);
void CetakInformasiViewport( void );
void kotak( void );
void demo( void );
void TampilkanGambar( char* );

char *load(char *);
long UkuranFile(char *);

int main(void)
{
	int gdriver = DETECT, gmode, errorcode;
	initgraph(&gdriver, &gmode, "d:\\borlandc\\bgi");
	errorcode = graphresult();
	if(errorcode != grOk)
	{
		printf("Graphics Error: %s\n", grapherrormsg(errorcode));
		printf("press any button to cancel:");
		getch();
		exit(1);
	}
	
	Maxx = getmaxx();
	Maxy = getmaxy();
	setcolor(getmaxcolor());
	demo();
	cleardevice();
	closegraph();
	return 0;
}

void kotak( void )
{
	float xa, ya, xb, yb, xc, yc, xd, yd;
	float xxa, yya, xxb, yyb, xxc, yyc, xxd, yyd;
	float p, q;
	int i, warna=0;
	
	p = 0.95; q = 1.0-p;
	xa = 2.0; xb = Maxx; xc = Maxx; xd = 2.0;
	ya = 2.0; yb = 2.0; yc = Maxy; yd = Maxy;
	
	for(i=0; i<50; i++)
	{
		setcolor( warna++);
		if(warna > getmaxcolor()) warna = 0;
		moveto(xa, ya);
		lineto(xb, yb); lineto(xc, yc);
		lineto(xd, yd);
		lineto(xa, ya);
		xxa = p*xa+q*xb;
		yya = p*ya+q*yb;
		xxb = p*xb+q*xc;
		yyb = p*yb+q*yc;
		xxc = p*xc+q*xd;
		yyc = p*yc+q*yd;
		xxd = p*xd+q*xa;
		yyd = p*yd+q*ya;
		xa = xxa; xb = xxb; xc = xxc; xd = xxd;
		ya = yya; yb = yyb; yc = yyc; yd = yyd;
	}
}

void demo( void )
{
	unsigned ukuran;
	struct viewporttype vp;
	char NamaFile[] ="Gambar.aj";
	char buffer[80];
	char *BufferGambar;
	char teks1[] = "Demonstrasi penyimpanan dan pemanggilan gambar";
	char teks2[] = "Tekan sembarang kunci untuk menyimpan gambar";
	char teks3[] = "Tekan sembarang kunci";
	char teks4[] = "Untuk mengambil gambar";
	int x1, y1, x2, y2;
	
	outtextxy(0, 0, teks1);
	
	outtextxy(0, textheight("H")+3, teks2);
	
	x1 = Maxx/5; y1 = Maxy/5;
	x2 = Maxx - x1; y2 = Maxy - y1;
	jendela(x1, y1, x2, y2, judul2, CLIP_ON);
	
	kotak();
	getviewsettings(&vp);
	
	getch();
	simpan( vp.left, vp.top, vp.right, vp.bottom, NamaFile);
	clearviewport();
	
	setcolor(WHITE);
	outtextxy(10, 10, teks3);
	outtextxy(10, 20, teks4);
	getch();
	clearviewport();
	BufferGambar = load(NamaFile);
	TampilkanGambar(BufferGambar);
	getch();
}

void jendela(int x1, int y1, int x2, int y2, char *judul, int clip)
{
	int posx, posy;
	setviewport(0,0, Maxx, Maxy, CLIP_ON);
	
	setcolor(LIGHTGRAY);
	setlinestyle(SOLID_LINE, 0, THICK_WIDTH);
	rectangle(x1-2, y1-15, x2+2, y2+2);
	setcolor(BLACK);
	setlinestyle(SOLID_LINE, 0, NORM_WIDTH);
	line(x1, y1-1, x2, y1-1);
	setcolor(WHITE);
	setfillstyle(SOLID_FILL, WHITE);
	bar(x1, y1, x2, y2);
	setfillstyle(SOLID_FILL, DARKGRAY);
	bar(x1, y1-13, x2, y1-2);
	posx = x1 + ((x2-x1)/2);
	posy = y1-1-((y1-1) - (y1-14))/2;
	settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
	settextjustify(CENTER_TEXT, CENTER_TEXT);
	setcolor(WHITE);
	outtextxy(posx, posy, judul);
	
	setviewport(x1, y1, x2, y2, clip);
	settextjustify(LEFT_TEXT, TOP_TEXT);
}

simpan( int x1, int y1, int x2, int y2, char *NamaFile)
	{
	FILE *myfile;
	unsigned char *buffer;
	unsigned char *sem;
	int i;
	unsigned ukuran;
	
	ukuran = imagesize(x1, y1, x2, y2);
	buffer = (unsigned char *) malloc (ukuran);
	sem = buffer;
	if(buffer == NULL)
	{
		outtextxy(100, 100, "memori penuh");
		return;	
	}
	getimage(0, 0, x2 - x1, y2 - y1, buffer);
	myfile = fopen(NamaFile, "wb");
	for(i=0; i< ukuran; i++){
		putc((*buffer), myfile);
		buffer++;
	}
	free(sem);
	fclose(myfile);
}

char *load(char *NamaFile)
{
	FILE *myfile;
	unsigned char *buffer;
	long ukuran;
	int i;
	
	ukuran = UkuranFile( NamaFile );
	buffer = (unsigned char *) malloc (ukuran);
	if(buffer == NULL)
	{
		outtextxy(100, 100, "memori penuh");
		return NULL;
	}
	myfile = fopen(NamaFile, "rb");
	
	fread(buffer, ukuran, 1, myfile);
	fclose(myfile);
	return buffer;
}

long UkuranFile(char *NamaFile)
{
	struct ffblk ffblk;
	int selesai;
	
	selesai = findfirst(NamaFile,&ffblk,0);
	while (!selesai)
	{
		selesai = findnext(&ffblk);
	}
	return (ffblk.ff_fsize);
}

void TampilkanGambar( char *buffer)
{
	putimage(0, 0, buffer, COPY_PUT);
	free(buffer);
}
What do you mean by "I couldn't compile it"? That is not a helpful statement of your problem.

If your compiler is giving you errors, then you should look at those errors, understand what they are saying, and use that information to identify what needs to be changed in the code.

If there are errors you don't understand, then tell us what they are.
there are lots of errors.

https://i.imgur.com/YsSxSX7.png
Hello Sirss,

First question I have is this a class in C or C++?

I can not compile your program because I do not have the "<dir.h>" header file.

I am not sure if telling to upgrade your compiler or IDE is a good idea or not with out knowing which language you are wanting to learn.

I did notice that the function "CetakInformasiViewport" does not have a definition.

Andy
Topic archived. No new replies allowed.