Co ma byt na zapoctovke? z coho? a chcem sy spatat...bude aj opravak...ked ano tak kedy?
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Zobrazi» príspevky MenuQuote from: ursus on 07.11.2010, 22:43:49Quote from: profesionale on 07.11.2010, 18:54:48
Moje zadanie
* - Do lava -priorita 2
/ - Do prava - priorita 1
Mozem poprosit o kontrolu ci je to takto spravne. Dakujem// Interpretator vyrazov s gramatikou
// Expr -> Term { ( <*> | </> ) Term }
// Term -> <Value> | <(> Expr <)>
//
// Pozn: Terminalne symboly su v zatvorkach < >
int expr();
int term()
{ int value;
switch (symbol)
{
case LPAR : getsymbol(); value = expr(); getsymbol(); break;
case VALUE: value = attr; getsymbol(); break;
}
return value;
}
int expr()
{ int leftOp, rightOp; SymType sy;
leftOp = term();
while ((E symbol) & (E DELENIE | E NASOBENIE))
{
sy = symbol; getsymbol(); rightOp = term();
switch (sy)
{
case DELENIE : leftOp = leftOp / rightOp ; break;
case NASOBENIE: leftOp = rightOp * leftOp ; break;
}
}
return leftOp;
}
asociativity som nekukal, ale uz len z toho ze mas rozdielne priority nemozes mat obe operatory v jednej funkcii,
// Interpretator vyrazov s gramatikou
// Expr -> Term { ( <*> | </> ) Term }
// Term -> <Value> | <(> Expr <)>
//
// Pozn: Terminalne symboly su v zatvorkach < >
int expr();
int term()
{ int value;
switch (symbol)
{
case LPAR : getsymbol(); value = expr(); getsymbol(); break;
case VALUE: value = attr; getsymbol(); break;
}
return value;
}
int expr()
{ int leftOp, rightOp; SymType sy;
leftOp = term();
while ((E symbol) & (E DELENIE | E NASOBENIE))
{
sy = symbol; getsymbol(); rightOp = term();
switch (sy)
{
case DELENIE : leftOp = leftOp / rightOp ; break;
case NASOBENIE: leftOp = rightOp * leftOp ; break;
}
}
return leftOp;
}
void draw() //funkcia na vykreslenie sveta
{
start_color();
init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
//nastavenie podla OS na ktorom je program spusteny
#ifdef _WIN32
system("cls"); //pre OS Windows
#else
system("clear"); //pre ostatne OS
#endif
int i, j; //definovanie premennych i a j
drawStatus();
attrset(COLOR_PAIR(COLOR_CYAN)); //zobrzenie informacii o svete a pohyboch karla
printw("+");
for(i=0; i<3*world.width; i++)
printw("-"); //vykreslovanie sveta podla danych hodnot sveta
printw("+\n");
for(i=world.height-1; i>=0; i--) //vytvaranie sveta po osi y
{
printw("|");
for(j=0; j<world.width; j++) //vytvaranie sveta po osi x
{ //ked je 0<world.width tak k j pripocitam +1 az dovtedy pokial
printw(" "); //j nenabudne rovnaku hodnotu ako world.width
if(i == karel.y && j == karel.x)
{
switch(karel.direction) //vykreslenie orientacie karla podla hodnoty v karel.direction
{
case 0: //ak je karel.direction = 0 vykresli sa >
printw(">");
break;
case 90: //ak je karel.direction = 90 vykresli sa ^
printw("^");
break;
case 180: //ak je karel.direction = 180 vykresli sa <
printw("<");
break;
case 270: //ak je karel.direction = 270 vykresli sa v
printw("v");
break;
}
}
else if(world.data[i][j] == EMPTY) //ak je hodnota na suradniciach [x,y] 0 vykresli .
{
printw(".");
}
else if(world.data[i][j] == WALL) //ak je hodnota na suradniciach [x,y] -1 hodnota vykresli #
{
printw("#");
}
else //inak vykresli hodnotu na suradniciach [x,y]
{
printw("%d", world.data[i][j]);
}
printw(" ");
}
printw("|\n");
}
printw("+"); //ukoncenie sveta - spodna stena
for(i=0; i<3*world.width; i++) printw("-");
printw("+\n");
setStepDelay(200);
refresh(); //nastavenie rychlosti krokov karla
}
Quote from: Maroshv on 11.05.2010, 23:31:32No ja sa bojim ze to asi nedas dokopy....lebo usleep je to iste ako sleep ale s tym rozdielom ze uslep je na unix. Pri windows sa do sleep udavaju ms tak pri unixe su to sekundy.
[Linker error] undefined reference to `usleep'
[Linker error] undefined reference to `WinMain@16'
ld returned 1 exit status
stále nejaka chyba, jednu chybu odstranim, a objavà sa dalšia a nakoniec toto
prosĂm pomĂ´Ĺľte, najlepšie cez ICQ 262322023, pošlem zdrojak
#ifndef LIBRARY_H
#define LIBRARY_H
#include <stdio.h>
#include <stdlib.h>
#define MAX_HEIGHT 20
#define MAX_WIDTH 20
#define WALL -1
#define EMPTY 0
#define EAST 0
#define NORTH 90
#define WEST 180
#define SOUTH 270
char * smer();
enum Boolean {
False = 0,
True = 1
};
struct Robot {
int x;
int y;
int beepers;
int direction;
};
struct Robot karel;
struct World {
int width, height;
int data[MAX_HEIGHT][MAX_WIDTH];
};
// World 'world' - global variable
struct World world;
void drawStatus();
// Saves world to file output.kw.
// File will be rewritten if exists.
void turnOff();
// Draws world to standard output.
void draw();
// Draws information about world to standard output.
void drawStatus();
// Returns false if in front of robot is wall or is
// out of map.
int frontIsClear();
// Negation of frontIsClear()
int frontIsBlocked();
// Returns false if left to the robot is wall or is
// out of map.
int leftIsClear();
// Negation of leftIsClear()
int leftIsBlocked();
// See leftIsClear().
int rightIsClear();
// Negation of rightIsClear()
int rightIsBlocked();
// Returns true if there are any beepers in the bag.
int beepersInBag();
// Returns true if there are no beepers in the bag.
int noBeepersInBag();
// Returns count of beepers at current position.
int _beepersAtCurrentPosition();
// Returns robot's direction as string.
char * smer();
// Converts (int) direction to character, like N, S, E, W.
char directionToWord(int direction);
// Loads world from file specified by path parameter.
void readWorldFile(char *path);
// Saves current world to file specified by path parameter.
void writeWorldFile(char *path);
#endif
#include <stdio.h>
#include <stdlib.h>
#define MAX_HEIGHT 20
#define MAX_WIDTH 20
#define WALL -1
#define EMPTY 0
int karel_beepers = 20;
int karel_direction = 0;
int beepS = 1;
char * smer();
// aktualna poloha robota
//enum Direction
enum Direction {
EAST = 0,
WEST = 180,
NORTH = 90,
SOUTH = 270
};
enum Boolean {
False = 0,
True = 1
};
//struktura Robot
struct Robot {
int x;
int y;
int beepers;
};
struct Robot karel;
struct World {
int width, height;
int data[MAX_HEIGHT][MAX_WIDTH];
};
if(facingEast())
{
int turnBack();
}
else if(facingSouth())
{
int turnRight();
}
else if(facingNorth())
{
int turnLeft();
}
if(!frontIsClear())
{
turnLeft();
while(frontIsClear())
movek();
turnLeft();
}
else
{
while(frontIsClear())
movek();
turnLeft();
movek();
while(frontIsClear())
movek();
turnLeft();
movek();
}
}
int facingSouth()
{
if (karel_direction == 270) return 1;
else return 0;
}
void turnOn()
{
int world1[5][4] = {
{ 1, 1, 2, 3 },
{ 0, 4, 3, 1 },
{ 2, 0, 0, 2 },
{ 5, 1, 0, 3 },
{ 0, 0, 0, 0 }
};
world.width = 4;
world.height = 5;
karel.x = 2;
karel.y = 3;
int x, y;
for(x=0; x<world.height; x++){
for(y=0; y<world.width; y++)
world.data[x][y]=world1[x][y];
}
}
void draw()
{
system("cls");
drawStatus();
int x,y;
for(x=0; x<world.height; x++)
{
for(y=0; y<world.width; y++)
{
if(x == karel.y && y == karel.x)
{
switch(karel_direction)
{
case 0:
printf(">");
break;
case 90:
printf("v");
break;
case 180:
printf("<");
break;
case 270:
printf("^");
break;
}
}
else if(world.data[x][y] == EMPTY)
{
printf(".");
}
else if(world.data[x][y] == WALL)
{
printf("#");
}
else
{
if(beepS == 1)
{
printf("%d", world.data[x][y]);
}
else
{
printf("*");
}
}
}
printf("\n");
}
printf("\n");
sleep(1000);
}
Quote from: mirek on 05.05.2010, 17:19:24Quote from: Bc. nemtom on 05.05.2010, 17:11:52presne tak. dokonca aj google hodi pomerne dobry preklad: "ak Karel stojà na východ"
iba z nazvu funkcii usudzujem ze zistuje na aku svetovu stranu sa pozera karel ci sipka ci co to tam mate