PDA

Tam Sürümünü Görmek İçin : #include "msoftcon.h"


ubuntu
30/03/2007, 20:37
"msoftcon.h" olmadığı için program hata veriyor. Onun yerine ne kullanabilirim? Amaç circle yapısını aktarmak. Program;


#include "msoftcon.h"

struct circle
{
int xCo, yCo;
int radius;
color fillcolor;
fstyle fillstyle;
};

void circ_draw(circle c)
{
set_color(c.fillcolor);
set_fill_style(c.fillstyle);
draw_circle(c.xCo, c.yCo, c.radius);
}

int main()
{
init_graphics();

circle c1={15, 7, 5, cBLUE, X_FILL};
circle c2={41, 12, 7, cRED, O_FILL};
circle c3={65, 18, 4, cGREEN, MEDIUM_FILL};

circ_draw(c1);
circ_draw(c2);
circ_draw(c3);
set_sursor_pos(1, 25);
return 0;
}




Aldığım hatalar;

error: "msoftcon.h" : No such file or directory
error: 'color' does not name a type


quasimodo
30/03/2007, 20:44
Bence bu ornege takilinmamali. Bu header file i ilk defa goruyorum
ama bir cember cizip icini bir renge boyuyor olsa gerek...
Burada ogretilmek istenen asil konu struct in yapisi, yarattigi
nesneye ilk deger verilmesi gibi konular...

Bu hangi kitaptan alinti acaba ...?

ubuntu
30/03/2007, 20:53
Yok struct ile ilgili değil. Asıl anlatılmak istenen circle yapısını aktarmak.
Kitap alfa yayınlarının nesne yönelimli c++ programlama klavuzu Robert Lafore.

necipakif
31/03/2007, 11:53
ubuntu, bu kütüphane ihitmaldir ki kitabın yanında cd felan geldiyse ya da kitabın sitesinde örneklerin bulunduğu yerde hazır verilmiş olabilir.

Selâmetle....

ubuntu
31/03/2007, 12:52
Kitabın sonunda dosyayı vermiş ama biraz uzun sürecek yazmak. 4 dosya vermiş. İkisi microsoft için ikiside borland c++ için. Ben linux ve code::blocks kullanıyorum. Bunları ekleme imkanım yok sanırım?

acehreli
01/04/2007, 00:33
Kitaplarin siteleri oluyor. Aradigin dosyalar su sayfanin en altinda:

http://server.oersted.dtu.dk/personal/sn/teaching/31027_2003/?./Course_Reading/main.html

Biraz bekle; yakin bir zamanda onlarin Linux'ta kabul edilir derecede benzerlerini yazarim.

Ali

ubuntu
01/04/2007, 00:36
Teşekkür ederim acehreli bekliyorum.

acehreli
01/04/2007, 02:01
Yaptim ama

1) Renk yok

2) Onlarin ekrani 1,1 noktasindan basliyormus ben 0,0 gibi dusundum

3) Ekranin istenen noktasina basmak yerine butun ekrani bastan gosteriyor

4) Mutlaka baska hatalar da vardir ama senin programina ekleyerek butun cizim islevlerini denedim

5) vs. :)

msoftcon.cpp dosyasina Ekran diye bir sinif tanimladim. O sinif, butun cizim islemlerini kendi icindeki bir vector'de yapiyor, sonra 'goster' islevi cagrilinca cout'a yazdiriyor.

// deneme.cpp

#include "msoftcon.h"

struct circle
{
int xCo, yCo;
int radius;
color fillcolor;
fstyle fillstyle;
};

void circ_draw(circle c)
{
set_color(c.fillcolor);
set_fill_style(c.fillstyle);
draw_circle(c.xCo, c.yCo, c.radius);
}

int main()
{
init_graphics();

circle c1={15, 7, 5, cBLUE, X_FILL};
circle c2={41, 12, 7, cRED, O_FILL};
circle c3={65, 18, 4, cGREEN, MEDIUM_FILL};

circ_draw(c1);
circ_draw(c2);
circ_draw(c3);
set_cursor_pos(1, 25);

draw_line(15, 15, 19, 19);
draw_rectangle(5, 20, 15, 24);

set_fill_style(LIGHT_FILL);
draw_pyramid(70, 7, 5);

return 0;
}


//msoftcon.h
//declarations for Lafore's console graphics functions
//uses Window's console functions

#ifndef _INC_WCONSOLE //don't let this file be included
#define _INC_WCONSOLE //twice in the same source file

// #include <windows.h> //for Windows console functions
// #include <conio.h> //for kbhit(), getche()
#include <math.h> //for sin, cos

enum fstyle { SOLID_FILL, X_FILL, O_FILL,
LIGHT_FILL, MEDIUM_FILL, DARK_FILL };

enum color {
cBLACK=0, cDARK_BLUE=1, cDARK_GREEN=2, cDARK_CYAN=3,
cDARK_RED=4, cDARK_MAGENTA=5, cBROWN=6, cLIGHT_GRAY=7,
cDARK_GRAY=8, cBLUE=9, cGREEN=10, cCYAN=11,
cRED=12, cMAGENTA=13, cYELLOW=14, cWHITE=15 };
//--------------------------------------------------------------
void init_graphics();
void set_color(color fg, color bg = cBLACK);
void set_cursor_pos(int x, int y);
void clear_screen();
void wait(int milliseconds);
void clear_line();
void draw_rectangle(int left, int top, int right, int bottom);
void draw_circle(int x, int y, int rad);
void draw_line(int x1, int y1, int x2, int y2);
void draw_pyramid(int x1, int y1, int height);
void set_fill_style(fstyle);
#endif /* _INC_WCONSOLE */


//msoftcon.cpp
//provides routines to access Windows console functions

//compiler needs to be able to find this file
//in MCV++, /Tools/Options/Directories/Include/type path name

#include "msoftcon.h"
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <iostream>
#include <unistd.h>

struct COORD
{
int X;
int Y;

COORD(int x = 0, int y = 0)
:
X(x),
Y(y)
{}
};

typedef unsigned int WORD;

class Ekran
{
typedef std::string Satir;
typedef std::vector<Satir> Konsol;

COORD boyutlar_;
COORD yazilacakYer_;
WORD kalemRengi_;
WORD sayfaRengi_;
Konsol konsol_;

void cizgiCek() const
{
std::fill_n(std::ostream_iterator<char>(std::cout, ""),
boyutlar_.X,
'-');

std::cout << '\n';
}

public:

Ekran()
:
kalemRengi_(0), // koddan anladigima gore siyah
sayfaRengi_(15) // koddan anladigima gore beyaz
{}

void SetConsoleScreenBufferSize(COORD boyutlar)
{
boyutlar_ = boyutlar;

// Aslinda boyutlari yeniden belirlemek ekrani temizlememeli
// ama ben kolaylik olsun diye bu yolu sectim.
ekraniTemizle();
}

void SetConsoleTextAttribute(WORD yaziOzellikleri)
{
kalemRengi_ = yaziOzellikleri & 0xf;
sayfaRengi_ = (yaziOzellikleri >> 4) & 0xf;
}

void SetConsoleCursorPosition(COORD yer)
{
yazilacakYer_ = yer;
}

void ekraniTemizle()
{
konsol_ = Konsol(boyutlar_.Y, Satir(boyutlar_.X, ' '));
}

void cputs(std::string satir)
{
if (satir.size() > boyutlar_.X)
{
satir.resize(boyutlar_.X);
}

// Olasi uzun satirlarin sonunu kirpalim
konsol_[yazilacakYer_.Y].replace(yazilacakYer_.X,
satir.size(),
satir);
}

void putch(char karakter)
{
konsol_[yazilacakYer_.Y][yazilacakYer_.X] = karakter;
}

void goster() const
{
cizgiCek();

std::copy(konsol_.begin(),
konsol_.end(),
std::ostream_iterator<Satir>(std::cout, "\n"));

cizgiCek();
}
};

Ekran hConsole; //console handle
char fill_char; //character used for fill
//--------------------------------------------------------------
void init_graphics()
{
COORD console_size(80, 25);
hConsole.SetConsoleScreenBufferSize(console_size);
//set text to white on black
hConsole.SetConsoleTextAttribute((WORD)((0 << 4) | 15) );

fill_char = '\xDB'; //default fill is solid block
clear_screen();
}
//--------------------------------------------------------------
void set_color(color foreground, color background)
{
hConsole.SetConsoleTextAttribute( (WORD)((background << 4) | foreground) );
} //end setcolor()

/* 0 Black 8 Dark gray
1 Dark blue 9 Blue
2 Dark green 10 Green
3 Dark cyan 11 Cyan
4 Dark red 12 Red
5 Dark magenta 13 Magenta
6 Brown 14 Yellow
7 Light gray 15 White
*/
//--------------------------------------------------------------
void set_cursor_pos(int x, int y)
{
COORD cursor_pos(x - 1, y - 1); //origin in upper left corner
//Windows starts at (0, 0)
//we start at (1, 1)
hConsole.SetConsoleCursorPosition(cursor_pos);
}

//--------------------------------------------------------------
void clear_screen()
{
set_cursor_pos(1, 25);
hConsole.ekraniTemizle();
hConsole.goster();
}
//--------------------------------------------------------------
void wait(int milliseconds)
{
usleep(1000 * milliseconds);
}
//--------------------------------------------------------------
void clear_line() //clear to end of line
{ //80 spaces
//..............123456789012345678901234567890123456 7890
//..............0........1.........2.........3...... ...4
hConsole.cputs(" ");
hConsole.cputs(" ");

hConsole.goster();
}
//--------------------------------------------------------------
void draw_rectangle(int left, int top, int right, int bottom)
{
char temp[80];
int width = right - left + 1;

int j;
for(j=0; j<width; j++) //string of squares
temp[j] = fill_char;
temp[j] = 0; //null

for(int y=top; y<=bottom; y++) //stack of strings
{
set_cursor_pos(left, y);
hConsole.cputs(temp);
}

hConsole.goster();
}
//--------------------------------------------------------------
void draw_circle(int xC, int yC, int radius)
{
double theta, increment, xF, pi=3.14159;
int x, xN, yN;

increment = 0.8 / static_cast<double>(radius);
for(theta=0; theta<=pi/2; theta+=increment) //quarter circle
{
xF = radius * cos(theta);
xN = static_cast<int>(xF * 2 / 1); //pixels not square
yN = static_cast<int>(radius * sin(theta) + 0.5);
x = xC-xN;
while(x <= xC+xN) //fill two horizontal lines
{ //one for each half circle
set_cursor_pos(x, yC-yN); hConsole.putch(fill_char); //top
set_cursor_pos(x++, yC+yN); hConsole.putch(fill_char); //bottom
}
} //end for

hConsole.goster();
}
//--------------------------------------------------------------
void draw_line(int x1, int y1, int x2, int y2)
{

int w, z, t, w1, w2, z1, z2;
double xDelta=x1-x2, yDelta=y1-y2, slope;
bool isMoreHoriz;

if( fabs(xDelta) > fabs(yDelta) ) //more horizontal
{
isMoreHoriz = true;
slope = yDelta / xDelta;
w1=x1; z1=y1; w2=x2, z2=y2; //w=x, z=y
}
else //more vertical
{
isMoreHoriz = false;
slope = xDelta / yDelta;
w1=y1; z1=x1; w2=y2, z2=x2; //w=y, z=x
}

if(w1 > w2) //if backwards w
{
t=w1; w1=w2; w2=t; // swap (w1,z1)
t=z1; z1=z2; z2=t; // with (w2,z2)
}
for(w=w1; w<=w2; w++)
{
z = static_cast<int>(z1 + slope * (w-w1));
if( !(w==80 && z==25) ) //avoid scroll at 80,25
{
if(isMoreHoriz)
set_cursor_pos(w, z);
else
set_cursor_pos(z, w);
hConsole.putch(fill_char);
}
}

hConsole.goster();
}
//--------------------------------------------------------------
void draw_pyramid(int x1, int y1, int height)
{
int x, y;
for(y=y1; y<y1+height; y++)
{
int incr = y - y1;
for(x=x1-incr; x<=x1+incr; x++)
{
set_cursor_pos(x, y);
hConsole.putch(fill_char);
}
}

hConsole.goster();
}
//--------------------------------------------------------------
void set_fill_style(fstyle fs)
{
switch(fs)
{
case SOLID_FILL: fill_char = '\xDB'; break;
case DARK_FILL: fill_char = '\xB0'; break;
case MEDIUM_FILL: fill_char = '\xB1'; break;
case LIGHT_FILL: fill_char = '\xB2'; break;
case X_FILL: fill_char = 'X'; break;
case O_FILL: fill_char = 'O'; break;
}
}
//--------------------------------------------------------------


Ali

ubuntu
01/04/2007, 02:13
Tekrar teşekkür ederim acehreli. Bunları nasıl ekleyecem bilmiyorum ama biraz karıştırim belki bulurum.

acehreli
01/04/2007, 02:24
Oteki dosyalarin yerine bunlari koy iste.

Ali

ubuntu
01/04/2007, 02:32
Öteki dosyalar dediğin diğer kaynak dosyalarımı? /usr/include altında c++ ve codeblocks dosyaları vardı onların içine kopyaladım. Senin yazdığın deneme.cpp yi denedim fakat birsürü hata verdi.

undefined reference to 'set_color(color, color)'
undefined reference to 'set_fill_style(fstyle)'
undefined reference to 'init_graphics()'
...
..
gibi.

acehreli
01/04/2007, 03:44
Derlemek icin nasil bir komut kullaniyorsun? Eger soyle bir seyse:

gcc deneme.cpp -o deneme

o satira bir de msoftcon.cpp'yi ekle:

gcc deneme.cpp msoftcon.cpp -o deneme

Ama msoftcon.cpp'yi /usr/include'un altina koyma tabii. O da deneme.cpp nerede ise orada dursun. Hatta msoftcon.h'yi de /usr/include'a kopyalamasan daha iyi olur ama o kadar da onemli degil herhalde...

Ali

ubuntu
01/04/2007, 12:58
Delemek için komut kullanmıyorum derleyici ile (code::blocks) derliyorum. Kısaca F9 :)

acehreli
01/04/2007, 22:38
Code Blocks bilmiyorum ama projenin kaynak dosyalarinin belirtildigi bir yer olmali... msoftcon.cpp'yi de o projenin kaynak dosyalari (source files) arasina eklersin.

Ali