answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

Which character comprise the c character set?

C does not use, nor requires the use of, every character found on a modern computer keyboard. The only characters required by the C Programming Language are as follows:

  1. A - Z
  2. a -z
  3. 0 - 9
  4. space . , : ; ' $ "
  5. # % & ! _ {} [] () $$$$ &&&& |
  6. + - / * =

The use of most of this set of characters will be discussed throughout the course.

How do you get a single character from the keyboard in Linux using C?

Pick one:

1. Consult ncurses' manual, especially getch.
2. Consult termios' manual, especially cfmakeraw.

Where is the continue statement NOT usually used?

The continue statement is not actually used when it is the last statement of the body of the loop.

Plus: outside any loop it is rarely or never used.

Write a c program to display 1 4 9 16..100?

Answer:CODE:

#include

main(){

int i = 0;

int counter = 1;

while(i <= 100){

i = counter*counter;

counter++;

printf("The value of i is:%d\n", i);

}

exit(0);

}

END CODE

I think this should work and display the results in the terminal. I haven't tried it though, so it might not work.

Answer:#include

int main (void) { puts ("1 4 9 16..100"); retun 0; }

What is an activation record?

An activation record is a data structure containing subroutine state information located on the call stack.

What is bar bench and hearsay Please explain briefly with points?

The bar bench and hearsay mean that where is no return value. This is to void hello in points.

What is pre increment and post increment in c language?

Short Answer

The short answer is that both the prefix increment and postfix increment operators will increment the operand. The difference is not so much the operation but the evaluation of the operation. Prefix increment evaluates as a reference to the operand itself, after it is incremented. Postfix increment evaluates to a reference to the operand (or its value) before it was incremented. The same principal applies to prefix decrement and postfix decrement operators.

Long Answer

The first thing to bear in mind is that operators not only perform an operation upon one or more operands, the expression must also be evaluated. In other words, the expression must return a value to the caller, even if we choose to ignore that value (by not storing it).

Consider the following increment expressions which both ignore the evaluation:

int x = 1, int y = 1;

++x; // prefix increment.

y++; // postfix increment.

Both x and y are incremented, as you would rightly expect, so they are both 2 when the expressions are evaluated. But by ignoring the result of those evaluations it's impossible to actually see any difference between these two expressions. So let's re-evaluate these expressions:

int x = 1, int y = 1;

int eval_x = ++x;

int eval_y = y++;

Now the evaluations cannot be ignored because we've immediately assigned them to the variables eval_x and eval_y. Both x and y are still incremented, just as before, but while eval_x is assigned the value 2 (the new value of x), eval_y is assigned the value 1 (the old value of y).

Clearly the two expressions perform exactly the same operation upon x and y (incrementing them), but they evaluate quite differently.

The prefix increment operator is the easiest of the two to understand. The evaluation of any prefix increment upon any operand is always a reference to the operand itself. Since the operand is incremented by the operator, assigning the evaluation of the operator to another variable (by reference) effectively assigns the incremented value to that variable.

This is really no different to saying eval_x = ( x = x + 1 ). It looks complicated but its really simple if we evaluate it as the computer evaluates it, from right to left. If x is 1 then x + 1 evaluates to 1 + 1 which evaluates to 2. Thus the equation reduces to eval_x = ( x = 2 ). x = 2 is an assignment not only gives x the value 2, it evaluates as a reference to x. Thus the final expression is eval_x = x, thus eval_x is assigned the value of x, which is 2. We can safely ignore the fact eval_x = x evaluates as a reference to eval_x, as the expression is now fully evaluated. The upshot is that eval_x 2.

Still with me?

The postfix increment operator is more complex. It cannot be evaluated in the same way because the evaluation of y++ requires that y be incremented (y = y + 1), but the evaluation of y++ cannot be a reference to y because we are not remotely interested in the incremented value of y, we're interested in what it was before being incremented. To achieve this we need to imagine there's a temporary variable involved:

int y=1;

int temp = y;

y = y + 1;

int eval_y = temp;

Although this is a fair representation, it is not an accurate one. It would be too easy to assume that postfix increment incurs a penalty by virtue of the temporary variable. But while it is certainly true that postfix operators on an object (an instance of a class) will incur a performance penalty, the same is not true of primitive data types such as int. This is simply because primitive data types do not require temporary variables to perform a postfix operation.

To understand why, remember that the CPU has several registers available for processing and for storing return values (which could be an address or an actual value). The compiler can generate code that will store the current value of y in a return register and operate upon a reference to y in another register. The evaluation is already pre-empted because it already exists in the return register, so no temporary is actually required, and therefore no penalty incurred.

In other words, y++ is no slower or faster than ++x when x and y are both primitives.

Classes are a different matter altogether. We cannot use CPU trickery to optimise a postfix operator upon an object (we'd need a hugely dynamic register model which is impossible to implement in hardware -- but I live in hope :-), so we are forced to make a copy. And since classes are generally larger than primitive data types, that can be an expensive hobby if we're in the habit of using postfix operators upon primitives. If the return value (the evaluation) is of no consequence, it's far too easy to use postfix operators in for() loops and such like. But it's a hard habit to break and you end up using postfix for just about everything, whether you want the previous value or not, resulting in objects being copied but never actually used. If you can get into the habit of using prefix operators at all times, even for primitives, and use postfix only when you actually need the previous value, your code will be that little bit more spritely. If you can't break the habit, or choose not to, put simple traces in your copy constructors. I guarantee you'll be prefixing by default in no time.

To finish off, here's a simple class that implements prefix and postfix increment operators. Note how both implementations actually employ prefix operators but, more importantly, that the postfix operator must make a temporary copy of the current instance (with a tell-tale tracer in the copy constructor). Finally, note that both operators return references, not values. Despite the advice given elsewhere (you know who you are!), never return an object by value unless you absolutely must. Many sites will advise that postfix operators should "always" return by value. But if you do this, you will not only pay a penalty for making a temporary copy (which is unavoidable in non-primitives), you pay the penalty twice over by copying the temporary copy!

#include

class cNum

{

public:

cNum(): m_data( 0 ){}

cNum( int data ): m_data( data ){}

cNum( const cNum & num ): m_data( num.m_data ){ printf( "Copying!\n" ); }

public:

cNum & operator++ (){ ++m_data; return( *this ); } // prefix

cNum & operator++ ( int ){ cNum * tmp = new cNum( *this ); ++m_data; return( *tmp ); } // postfix

cNum & operator= ( const cNum & num ){ m_data = num.m_data; return( *this ); }

public:

int GetData() const { return( m_data ); }

private:

int m_data;

};

int main()

{

cNum num( 25 ), eval;

printf( "Initial values:\n" );

printf( "num: %d, eval: %d\n\n", num.GetData(), eval.GetData() );

printf( "Calling prefix increment:\n" );

eval = ++num;

printf( "num: %d, eval: %d\n\n", num.GetData(), eval.GetData() );

printf( "Calling postfix increment:\n" );

eval = num++;

printf( "num: %d, eval: %d\n\n", num.GetData(), eval.GetData() );

printf( "Calling prefix increment (ignoring evaluation):\n" );

++num;

printf( "num: %d, eval: %d\n\n", num.GetData(), eval.GetData() );

printf( "Calling postfix increment (ignoring evaluation):\n" );

num++;

printf( "num: %d, eval: %d\n\n", num.GetData(), eval.GetData() );

return( 0 );

}

Advantages of c in embedded system?

We don't have to bother much about hardware.Also it will take only less effort to change from one microcontroller to another.Its more easy to....More may be there....

Dixsa - C project free source code?

/* DIXSA */ /*

DIXSA

Project experience

Date: May 14, 2007

Place: Sullia (D.K) This is lisence free code but, I request for anybody using this piece of code to not to change the name of the project "DIXSA" since that has some special purpose in my personal view. "DIXSA" is my B.E. 6th semester "COMPUTER GRAPHICS LABORATORY Part-B" project work. This is written in C-language. It is possible to run this program on 'TURBO C' platform on WINDOWS operating system. The reason behind this game idea is an old game (LUDO like game) named "CHOWKA-BHARA" which I learnt from my grandmother by name "LILAVATHI". Hence I feel very happy to dedicate this project work on my grandmothers' name. It's easy to understand the game procedure. The game is built in such a way that user will have real experience while playing with the system. No external speakers are needed to run this software as it make use of CPU inbuilt speakers. The limitations of this game are sound effect produced is not compatible with C++, because of 'delay ( )' used for system sounds; and hence it's not easily portable with other links as well as other platforms. And another vital drawback is some of the imperfections in the design like display aberrance of user pawns movement which will be clear only after clicking on 'PLAY' button, & many others. I felt very happy to take up this project & enjoyed doing this game design up to the maximum extent. There are a lot of rules that could be implemented as per the instructions of my grandmother. However, I could implement a small portion of them. My project guide "Mr. Rajashekhar K advaith" helped me for coding am thankful to him a lot. I'm also thankful to my SKDB hostel mates who have helped me to develop a beautiful design for this project. By,

Raghu S */

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h> void initilize_arrays();

void draw();

void sample_draw();

void show_help(int random);

void introduce();

void give_rules();

int initmouse();

void hidemouseptr();

void showmouseptr();

void getmouseptr();

void firstdraw();

void drawp1();

void drawp2();

int finish();

int generate();

int select(int random);

int invalid(int sel,int random);

int invalid_comp(int sel,int random);

void draw_cavde(int random);

int can_play(int mx,int my,int random);

int getpon(int mx,int my,int random); union REGS i,o;

int maxx,maxy,p=0,q=0,box[25][10];

int player1[4]={0,0,0,0},player2[4]={0,0,0,0};

int p1[25]={2,1,0,5,10,15,20,21,22,23,24,19,14,9,4,3,8,13,18,17,16,11,6,7,12};

int p2[25]={22,23,24,19,14,9,4,3,2,1,0,5,10,15,20,21,16,11,6,7,8,13,18,17,12};

int ext[10],play[10],help[10],xp,yp; void main()

{

int gd=DETECT,gm,flag=1;

int a,b,c,d,i,j,k,x,y,xi,yi,button,random; initgraph(&gd,&gm,"c:\\tc\\bgi"); maxx=getmaxx();

maxy=getmaxy(); if(initmouse()==0)

{

printf("Mouse driver not loaded");

getch();

closegraph();

restorecrtmode();

exit(1);

} introduce(); initilize_arrays(); a=maxx/16;

b=maxx*3/4;

c=maxy/16;

d=maxy*3/4; xi=(b-a)/5;

yi=(d-c)/5; for(y=c;y<d;y+=yi)

for(x=a;x<b;x+=xi)

{

box[p][q++]=x;

box[p][q++]=y;

box[p][q++]=x+xi;

box[p][q++]=y;

box[p][q++]=x+xi;

box[p][q++]=y+yi;

box[p][q++]=x;

box[p][q++]=y+yi;

box[p][q++]=x;

box[p][q++]=y;

p++;

q=0;

} draw(); showmouseptr(); j=-1;

while(j==-1)

{

getmouseptr();

j=can_play(xp,yp,0);

} random=generate(); while(!finish())

{

draw_cavde(random); if(flag)

{

flag=0;

for(k=0;k<4 && invalid(k,random);k++);

if(k==4)

{

hidemouseptr();

setcolor(WHITE);

settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);

outtextxy(ext[0]-50,100,"No");

outtextxy(ext[0]-50,130,"PAWN move");

outtextxy(ext[0]-50,160,"for YOU"); sleep(1); setcolor(BLACK);

settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);

outtextxy(ext[0]-50,100,"No");

outtextxy(ext[0]-50,130,"PAWN move");

outtextxy(ext[0]-50,160,"for YOU");

showmouseptr();

}

else

{

j=-1;

while(j==-1)

{

getmouseptr();

j=getpon(xp,yp,random);

}

player2[j]+=random;

if(player2[j]!=4 && player2[j]!=8 && player2[j]!=12 && player2[j]!=24)

for(k=0;k<4;k++)

if(p2[player2[j]]==p1[player1[k]])

player1[k]=0;

}

random=generate();

}

else

{

flag=1;

for(k=0;k<4 && invalid_comp(k,random);k++);

if(k==4)

{

hidemouseptr();

setcolor(WHITE);

settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);

outtextxy(ext[0]-50,100,"No");

outtextxy(ext[0]-50,130,"PAWN move");

outtextxy(ext[0]-50,160,"for ME"); sleep(1); setcolor(BLACK);

settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);

outtextxy(ext[0]-50,100,"No");

outtextxy(ext[0]-50,130,"PAWN move");

outtextxy(ext[0]-50,160,"for ME");

showmouseptr();

}

else

{

j=select(random);

player1[j]+=random; if(player1[j]!=4 && player1[j]!=8 && player1[j]!=12 && player1[j]!=24)

for(k=0;k<4;k++)

if(p2[player2[k]]==p1[player1[j]])

player2[k]=0;

}

random=generate();

j=-1;

while(j==-1)

{

getmouseptr();

j=can_play(xp,yp,random);

}

} hidemouseptr();

firstdraw();

drawp1();

drawp2();

showmouseptr();

} delay(100000);

getmouseptr();

hidemouseptr();

closegraph();

restorecrtmode();

} int initmouse()

{

i.x.ax=0;

int86(0x33,&i,&o);

return(o.x.ax);

} void showmouseptr()

{

i.x.ax=1;

int86(0x33,&i,&o);

} void hidemouseptr()

{

i.x.ax=2;

int86(0x33,&i,&o);

} void getmouseptr()

{

int b=-1;

while(b!=1)

{

i.x.ax=3;

int86(0x33,&i,&o);

b=o.x.bx;

}

xp=o.x.cx;

yp=o.x.dx;

} void initilize_arrays()

{

ext[0]=maxx-100;

ext[1]=20;

ext[2]=maxx-85;

ext[3]=20;

ext[4]=maxx-85;

ext[5]=35;

ext[6]=maxx-100;

ext[7]=35;

ext[8]=maxx-100;

ext[9]=20; play[0]=maxx-130;

play[1]=maxy-150;

play[2]=play[0]+50;

play[3]=play[1];

play[4]=play[0]+50;

play[5]=play[1]+20;

play[6]=play[0];

play[7]=play[1]+20;

play[8]=play[0];

play[9]=play[1]; help[0]=play[0];

help[1]=ext[1]+50;

help[2]=help[0]+50;

help[3]=help[1];

help[4]=help[0]+50;

help[5]=help[1]+20;

help[6]=help[0];

help[7]=help[1]+20;

help[8]=help[0];

help[9]=help[1];

} void draw()

{

setbkcolor(RED);

setcolor(WHITE);

setfillstyle(SOLID_FILL,BROWN);

fillpoly(5,ext);

line(maxx-100,20,maxx-85,35);

line(maxx-85,20,maxx-100,35);

setcolor(LIGHTRED);

setfillstyle(SOLID_FILL,DARKGRAY);

fillpoly(5,play);

fillpoly(5,help); setcolor(WHITE);

settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);

outtextxy(play[0]+2,play[1]-3,"PLAY");

outtextxy(help[0]+4,help[1]-3,"HELP");

firstdraw();

drawp1();

drawp2();

setcolor(WHITE);

settextstyle(GOTHIC_FONT,HORIZ_DIR,10);

outtextxy(100,340,"Dixsa");

} void firstdraw()

{

int temp,i,j;

temp=getcolor();

setcolor(YELLOW);

for(i=0;i<25;i++)

{

setfillstyle(SOLID_FILL,DARKGRAY);

fillpoly(5,box[i]);

if(i==2 i==10 i==14 i==22)

{

setcolor(WHITE);

line(box[i][0],box[i][1],box[i][4],box[i][5]);

line(box[i][2],box[i][3],box[i][6],box[i][7]);

setcolor(YELLOW);

}

}

setcolor(temp);

} void drawp1()

{

int temp;

temp=getcolor();

setcolor(LIGHTCYAN);

setfillstyle(SOLID_FILL,LIGHTCYAN);

sector(box[p1[player1[0]]][0]+10,box[p1[player1[0]]][1]+20,0,360,5,5);

sector(box[p1[player1[1]]][0]+80,box[p1[player1[1]]][1]+50,0,360,5,5);

sector(box[p1[player1[2]]][0]+65,box[p1[player1[2]]][1]+58,0,360,5,5);

sector(box[p1[player1[3]]][0]+24,box[p1[player1[3]]][1]+8,0,360,5,5);

setcolor(temp);

} void drawp2()

{

int temp;

temp=getcolor();

setcolor(LIGHTGREEN);

setfillstyle(SOLID_FILL,LIGHTGREEN);

sector(box[p2[player2[0]]][0]+45,box[p2[player2[0]]][1]+15,0,360,5,5);

sector(box[p2[player2[1]]][0]+25,box[p2[player2[1]]][1]+33,0,360,5,5);

sector(box[p2[player2[2]]][0]+65,box[p2[player2[2]]][1]+33,0,360,5,5);

sector(box[p2[player2[3]]][0]+45,box[p2[player2[3]]][1]+50,0,360,5,5);

setcolor(temp); setcolor(WHITE);

settextstyle(7,HORIZ_DIR,3);

outtextxy(box[12][0]+8,box[12][1]+14,"Home");

} int finish()

{

if(player1[0]==24 && player1[1]==24 && player1[2]==24 && player1[3]==24)

{

hidemouseptr();

setcolor(BLUE);

settextstyle(0,HORIZ_DIR,4);

outtextxy(box[10][0]+8,box[10][1]+15,"Computer wins"); settextstyle(5,HORIZ_DIR,3);

setcolor(BLUE);

outtextxy(100,maxy-250,"Click any where to End....");

showmouseptr();

return 1;

}

if(player2[0]==24 && player2[1]==24 && player2[2]==24 && player2[3]==24)

{

hidemouseptr();

setcolor(BLUE);

settextstyle(0,HORIZ_DIR,6);

outtextxy(box[10][0]+50,box[10][1]+14,"You won"); settextstyle(5,HORIZ_DIR,3);

setcolor(BLUE);

outtextxy(100,maxy-250,"Click any where to End....");

showmouseptr();

return 1;

}

return 0;

} int generate()

{

int x;

randomize();

x=random(5);

if(x==0)

return 1;

if(x==1)

return 2;

if(x==2)

return 3;

if(x==3)

return 4;

return 8;

} int select(int random)

{

int i,j,k; for(i=0;i<4;i++)

if((player1[i]+random)==24)

return i; for(j=0;j<4;j++)

{

k=player1[j]+random;

if(k==4 k==8 k==12)

return j;

} for(j=0;j<4;j++)

{

if(!invalid_comp(j,random))

{

k=player1[j]+random;

for(i=0;i<4;i++)

if(p1[k]==p2[player2[i]])

return j;

}

} if(!invalid_comp(0,random))

{

k=player1[0];

i=0;

for(j=1;j<4;j++)

{

if(!invalid_comp(j,random) && player1[j]>k)

{

k=player1[j];

i=j;

}

}

return i;

} if(!invalid_comp(1,random))

{

k=player1[1];

i=1;

for(j=2;j<4;j++)

{

if(!invalid_comp(j,random) && player1[j]>k)

{

k=player1[j];

i=j;

}

}

return i;

} if(!invalid_comp(2,random))

{

k=player1[2];

i=2;

if(!invalid_comp(j,random) && player1[3]>k)

{

k=player1[3];

i=3;

}

return i;

} return 3;

} int invalid(int sel,int random)

{

int i,t=player2[sel]+random;

if(t>24)

return 1;

if(t!=0 && t!=4 && t!=8 && t!=12 && t!=24)

for(i=0;i<4;i++)

if(player2[i]==t)

return 1;

return 0;

} int invalid_comp(int sel,int random)

{

int i,t=player1[sel]+random;

if(t>24)

return 1;

if(t!=0 && t!=4 && t!=8 && t!=12 && t!=24)

for(i=0;i<4;i++)

if(player1[i]==t)

return 1;

return 0;

} void draw_cavde(int random)

{

int i,j,k,a[4],x=maxx*3/4+20,y=maxy*3/4+20;

for(i=maxx*3/4+1;i<maxx;i++)

for(j=maxy*3/4+1;j<maxy;j++)

putpixel(i,j,BLACK);

if(random==1)

{

a[0]=1;

a[1]=a[2]=a[3]=0;

}

else

if(random==2)

{

a[0]=a[3]=1;

a[1]=a[2]=0;

}

else

if(random==3)

{

a[1]=a[2]=a[3]=1;

a[0]=0;

}

else

if(random==4)

a[0]=a[1]=a[2]=a[3]=1;

else

a[0]=a[1]=a[2]=a[3]=0; for(i=0;i<4;i++)

{

if(a[i])

{

setcolor(LIGHTBLUE);

setfillstyle(SLASH_FILL,WHITE);

fillellipse(x,y,16,4);

for(j=3;j<10;j++)

ellipse(x,y,180,360,17,j);

line(x-16,y-1,x+16,y-1);

line(x-16,y,x+16,y);

}

else

{

setcolor(LIGHTBLUE);

setfillstyle(LTBKSLASH_FILL,WHITE);

fillellipse(x,y,16,4);

for(j=3;j<10;j++)

ellipse(x,y,0,180,15,j); }

if(i==0)

x+=60;

if(i==1)

y+=40;

if(i==2)

x-=60;

} for(i=0;i<3;i++)

{

sound(568);

delay(10000);

nosound();

delay(10000);

}

sound(568);

delay(10000);

nosound();

} int can_play(int mx,int my,int random)

{

int i,k;

if(mx>ext[0] && mx<ext[4] && my>ext[1] && my<ext[5])

exit(0);

if(mx>help[0] && mx<help[4] && my>help[1] && my<help[5])

show_help(random);

if(mx>play[0] && mx<play[4] && my>play[1] && my<play[5])

return 1;

return -1;

} int getpon(int mx,int my,int random)

{

int i,k;

if(mx>ext[0] && mx<ext[4] && my>ext[1] && my<ext[5])

exit(0);

if(mx>play[0] && mx<play[4] && my>play[1] && my<play[5])

draw_cavde(random);

if(mx>help[0] && mx<help[4] && my>help[1] && my<help[5])

show_help(random);

for(i=0;i<25;i++)

if(mx>box[i][0] && mx<box[i][4] && my>box[i][1] && my<box[i][5])

break;

if(i==25)

return -1;

for(k=0;k<4;k++)

if(i==p2[player2[k]])

if(!(invalid(k,random)))

return k;

else

{

hidemouseptr();

setcolor(WHITE);

settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);

outtextxy(ext[0]-50,100,"This");

outtextxy(ext[0]-50,130,"PAWN can't");

outtextxy(ext[0]-50,160,"be moved"); sleep(1); setcolor(BLACK);

settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);

outtextxy(ext[0]-50,100,"This");

outtextxy(ext[0]-50,130,"PAWN can't");

outtextxy(ext[0]-50,160,"be moved");

showmouseptr();

}

return -1;

} void introduce()

{

int i,j,c;

cleardevice();

setbkcolor(BLACK); setcolor(YELLOW);

settextstyle(5,HORIZ_DIR,2);

outtextxy(200,170,"By,");

settextstyle(7,HORIZ_DIR,2);

outtextxy(240,200,"Raghu S");

outtextxy(240,240,"Krishna Kumar M G"); settextstyle(7,HORIZ_DIR,2);

outtextxy(10,335,"Guide : Rajashekhar K advaith");

outtextxy(10,375,"Co-ordinator : Rajesh D S"); settextstyle(GOTHIC_FONT,HORIZ_DIR,10);

c=WHITE;

for(i=0;i<375;i++)

{

setcolor(c);

outtextxy(i,0,"Dixsa");

delay(5);

setcolor(BLACK);

outtextxy(i,0,"Dixsa");

}

for(i=375;i>0;i--)

{

setcolor(c);

outtextxy(i,0,"Dixsa");

delay(5);

setcolor(BLACK);

outtextxy(i,0,"Dixsa");

}

for(i=0;i<150;i++)

{

setcolor(c);

outtextxy(i,0,"Dixsa");

delay(5);

setcolor(BLACK);

outtextxy(i,0,"Dixsa");

}

setcolor(c);

outtextxy(150,0,"Dixsa"); settextstyle(5,HORIZ_DIR,2);

setcolor(WHITE);

outtextxy(50,maxy-40,"Click any where to continue....");

showmouseptr();

getmouseptr();

hidemouseptr();

cleardevice();

} void show_help(int random)

{

give_rules();

hidemouseptr();

cleardevice();

draw();

if(random!=0)

draw_cavde(random);

showmouseptr();

} void sample_draw()

{

int s1=130,s2=40,i,j; setcolor(WHITE);

for(i=0;i<=5;i++)

for(j=0;j<5;j++)

{

line(s1+20*i,s2,s1+20*i,s2+100);

line(s1,s2+20*i,s1+100,s2+20*i);

}

line(s1+20*3,s2,s1+20*2,s2+20);

line(s1+20*2,s2,s1+20*3,s2+20);

line(s1,s2+20*3,s1+20,s2+20*2);

line(s1+20,s2+20*3,s1,s2+20*2);

line(s1+20*2,s2+20*3,s1+20*3,s2+20*2);

line(s1+20*3,s2+20*3,s1+20*2,s2+20*2);

line(s1+20*4,s2+20*3,s1+20*5,s2+20*2);

line(s1+20*5,s2+20*3,s1+20*4,s2+20*2);

line(s1+20*3,s2+20*4,s1+20*2,s2+20*5);

line(s1+20*2,s2+20*4,s1+20*3,s2+20*5); setcolor(RED);

line(s1+50,s2+10,s1+10,s2+10);

line(s1+10,s2+10,s1+10,s2+90);

line(s1+10,s2+90,s1+90,s2+90);

line(s1+90,s2+90,s1+90,s2+10);

line(s1+90,s2+10,s1+70,s2+10);

line(s1+70,s2+10,s1+70,s2+70);

line(s1+70,s2+70,s1+30,s2+70);

line(s1+30,s2+70,s1+30,s2+30);

line(s1+30,s2+30,s1+50,s2+30);

line(s1+50,s2+30,s1+50,s2+50);

setcolor(WHITE); s1=340;

for(i=0;i<=5;i++)

for(j=0;j<5;j++)

{

line(s1+20*i,s2,s1+20*i,s2+100);

line(s1,s2+20*i,s1+100,s2+20*i);

}

line(s1+20*3,s2,s1+20*2,s2+20);

line(s1+20*2,s2,s1+20*3,s2+20);

line(s1,s2+20*3,s1+20,s2+20*2);

line(s1+20,s2+20*3,s1,s2+20*2);

line(s1+20*2,s2+20*3,s1+20*3,s2+20*2);

line(s1+20*3,s2+20*3,s1+20*2,s2+20*2);

line(s1+20*4,s2+20*3,s1+20*5,s2+20*2);

line(s1+20*5,s2+20*3,s1+20*4,s2+20*2);

line(s1+20*3,s2+20*4,s1+20*2,s2+20*5);

line(s1+20*2,s2+20*4,s1+20*3,s2+20*5); setcolor(RED);

line(s1+50,s2+90,s1+90,s2+90);

line(s1+90,s2+90,s1+90,s2+10);

line(s1+90,s2+10,s1+10,s2+10);

line(s1+10,s2+10,s1+10,s2+90);

line(s1+10,s2+90,s1+30,s2+90);

line(s1+30,s2+90,s1+30,s2+30);

line(s1+30,s2+30,s1+70,s2+30);

line(s1+70,s2+30,s1+70,s2+70);

line(s1+70,s2+70,s1+50,s2+70);

line(s1+50,s2+70,s1+50,s2+50);

setcolor(WHITE);

} void give_rules()

{

hidemouseptr();

cleardevice();

setbkcolor(DARKGRAY);

setcolor(WHITE);

settextstyle(4,HORIZ_DIR,4);

outtextxy(250,5,"Dixsa"); sample_draw(); settextstyle(7,0,2);

setcolor(WHITE);

outtextxy(75,140,"Path for SYSTEM Path for PLAYER"); settextstyle(7,0,1);

setcolor(YELLOW);

outtextxy(5,170,". USE ONLY LEFT CLICK IN MOUSE FOR OBJECT SELECTIONS");

outtextxy(5,200,". There are 4 pawns for a player");

outtextxy(5,220," and one can cut the pawn of other except at CROSSED boxes");

outtextxy(5,250,". The path of pawns movement is as shown in above figures");

outtextxy(5,280,". To start playing click on 'PLAY' for each movement");

outtextxy(5,310,". The value of movement is found as follows:");

outtextxy(5,330," . There are 4 DIXSA's appearing to give value bellow 'PLAY'");

outtextxy(5,350," . If all DIXSA's are showing Upper surface = 8");

outtextxy(5,370," . Otherwise that = The number of Lower surfaces");

outtextxy(5,400,". Click on the box in which the pawn to be moved");

outtextxy(5,430,". Can't place 2 pawns of same player together except in CROSSED");

outtextxy(5,450," boxes"); settextstyle(5,HORIZ_DIR,2);

setcolor(WHITE);

outtextxy(140,maxy-32,"click any where to continue....");

showmouseptr();

getmouseptr();

}

What are the advantages and disadvantages of polymorphism and inheritance?

Answer

the biggest advantage lies in creation of reusable code by programmers, you dont care about the specific objects used just like driving a car without knowing what plugs are in the engine. multiple forms of one object are called in the same way

Why use static data when you can use global data in the class in C plus plus?

Global data are used only as a last resort. It's highly recommended not use global data in your programs because sometimes it's really hard to avoid name clashing. And as result to track such problem down.

How do you represent assignment by bitwise XOR operator?

The bitwise XOR operator is ^, or shift 6. The bitwise XOR assignment operator is ^=.

Pascal program determine the age of 2 friends?

the age of 2 friends

determine if the age greater than 18 if not write the output statment you can vote

if younger than 18 print you should be in school

How do you make a flow chart which shows all the prime number from 1 to 1000?

We cannot show flowcharts in a text-only forum. However, here's the pseudo-code which will help you construct a flowchart. Note that % is the modulo operator (remainder after integer division):

  1. num := 1
  2. if (num < 2) then goto 9
  3. if (num % 2 = 0) and (num = 2) then goto 8 else goto 9
  4. div := 3
  5. if (num % div = 0) then goto 9
  6. div := div + 2
  7. if (div < sqrt (num)) then goto 5
  8. print num
  9. num := num + 1
  10. if (num <= 1000) then goto 2

Why do some programmers prefer to write a program from scratch rather than modify a program written by someone else?

Professional programmers would never write code from scratch if they could avoid it, but there may be legal reasons why an existing program cannot be modified. Amateur programmers and hobbyists. however, will often write programs from scratch purely to exercise their problem-solving abilities.

What is the primary advantage in file?

It stores data, even when the computer is switched off.

How do you write a c code for memory allocation algorithms?

#include<stdio.h>

typedef struct hole

{

int id,size,inf,ef,filled,pid,psize;

}hole;

typedef struct process

{

int id,size,comp;

}process;

hole h[50];

process p[50];

int m,n,intfrag,exfrag;

void output()

{

int i;

intfrag=exfrag=0;

printf("\n\n\nHole Process IF EF\n");

for(i=0;i<m;i++)

{

printf("\n%d %d %d %d",h[i].size,h[i].psize,h[i].inf,h[i].ef);

intfrag=intfrag+h[i].inf;

exfrag=exfrag+h[i].ef;

}

}

void final()

{

int i;

for(i=0;i<n;i++)

{

if(p[i].comp==0)

{

printf("There is no memory for the process of size %d\n",p[i].size);

}

}

}

void input()

{

int i,max,flag;

max=flag=0;

printf("\nEnter total no of holes:\n");

scanf("%d",&m);

for(i=0;i<m;i++)

{

h[i].id=i;

printf("\nEnter size of hole %d:\n",i+1);

scanf("%d",&h[i].size);

h[i].inf=0;

h[i].ef=h[i].size;

h[i].filled=0;

h[i].pid=0;

h[i].psize=0;

}

for(i=0;i<m;i++)

{

if(h[i].size<0)

{

printf("\nInvalid input as hole size is negative");

flag=1;

}

if(h[i].size>max)

{

max=h[i].size;

}

}

printf("\nEnter total no of processes:\n");

scanf("%d",&n);

for(i=0;i<n;i++)

{

p[i].id=i;

printf("\nEnter size of process %d:\n",i+1);

scanf("%d",&p[i].size);

p[i].comp=0;

}

for(i=0;i<n;i++)

{

if(p[i].size<0)

{

printf("\nInvalid input as process size is negative");

flag=1;

}

if(p[i].size>max)

{

printf("\nInvalid input as process size is greater than max size of hole\n");

flag=1;

}

}

if(flag==0)

{

output();

}

}

void first()

{

int i,j;

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

if(p[i].size<=h[j].size && p[i].comp==0 && h[j].filled==0)

{

p[i].comp=1;

h[j].filled=1;

h[j].psize=p[i].size;

h[j].id=p[i].id;

h[j].inf=h[j].size-p[i].size;

h[j].ef=0;

output();

}

}

}

printf("\n\n\nInternal Fragmentation:%d",intfrag);

printf("\n\n\nExternal Fragmentation:%d\n\n",exfrag);

final();

}

void best()

{

int min,i,j,sub,var;

for(i=0;i<n;i++)

{

min=999;

sub=0;

for(j=0;j<m;j++)

{

if(p[i].size<=h[j].size && p[i].comp==0 && h[j].filled==0)

{

sub=h[j].size-p[i].size;

if(min>sub)

{

min=sub;

var=j;

}

}

}

p[i].comp=1;

h[var].filled=1;

h[var].psize=p[i].size;

h[var].id=p[i].id;

h[var].inf=h[var].size-p[i].size;

h[var].ef=0;

output();

}

printf("\n\n\nInternal Fragmentation:%d",intfrag);

printf("\n\n\nExternal Fragmentation:%d\n\n",exfrag);

final();

}

void next()

{

int i,j,a;

a=j=0;

for(i=0;i<n;i++)

{

for(j=a;j<m;j++)

{

if(p[i].size<=h[j].size && p[i].comp==0 && h[j].filled==0)

{

p[i].comp=1;

h[j].filled=1;

h[j].psize=p[i].size;

h[j].id=p[i].id;

h[j].inf=h[j].size-p[i].size;

h[j].ef=0;

output();

a=(j+1)%m;

}

}

}

printf("\n\n\nInternal Fragmentation:%d",intfrag);

printf("\n\n\nExternal Fragmentation:%d\n\n",exfrag);

final();

}

void main()

{

int ch;

printf("\n\n\n**********MEMORY ALLOCATION**********\n\n");

printf("\n1.First Fit Algorithm\n2.Best Fit Algorithm\n3.Next Fit Algorithm");

printf("\nEnter your choice:\n");

scanf("%d",&ch);

switch(ch)

{

case 1: input();

first();

break;

case 2: input();

best();

break;

case 3: input();

next();

break;

}

}

Written by: Fabianski Benjamin

Advantages and disadvantages of rtos?

RTOS are well... realtime.
It means that it is possible to create processes with strict time constraints (like : never more than 5ms delay, the "never" is the important part).

The disadvantage is that it will try to meet these time constraints at all costs. Even if it means using less efficient algorithms and completely suspending less critical processes.

Because they are often designed for embedded systems, RTOS are usually simpler and smaller than non-RT desktop OSes.

Write a program parse using brute force technique of top down parsing?

#include<stdio.h>

#include<conio.h>

#include<iostream.h>

void main()

{

int a[30];

clrscr();

int min=10000,temp=0,i,lev,n,noofc,z;

printf("please enter how many number");

cin>>n;

for(i=0;i<n;i++)

a[i]=0;

cout<<"enter value of root";

cin>>a[0];

for(i=1;i<=n/2;i++)

{

cout<<"please enter no of child of parent with value"<<a[i-1]<<":";

cin>>noofc;

for(int j=1;j<=noofc;j++)

{z=(i)*2+j-2;

cout<<"please enter value of child";

cin>>a[z];

}

}

for(i=n-1;i>=n/2;i--)

{

temp=0;

for(int j=i+1;j>=1;j=j/2)

temp=temp+a[j-1];

if(temp<min)

min=temp;

cout<<"temp min is"<<temp<<"\n";

}

cout<<"min is"<<min;

getch();

}

How does two phase commit process work in distributed database?

Pretty much the same way it works in any type of architecture. If it's distributed it just means it can span multiple databases of different types.

Database changes required by a transaction are initially stored temporarily by each database. The transaction monitor then issues a "pre-commit" command to each database which requires an acknowledgement. If the monitor receives the appropriate response from each database, the monitor issues the "commit" command, which causes all databases to simultaneously make the transaction changes permanent.

Does the programmer need to write a single program that performs many independent activities?

He doesn't need to; a single program can perform a single task. However, if a task can be divided up into separate independent tasks we can use multi-threading to achieve it. Most graphical user interface (GUI) applications are multi-threaded insofar as one thread handles the message queue and dispatches messages to "worker threads" in order to carry out the required task. Tasks may share resources (which may require synchronisation), but are otherwise independent of each other and each can carry out their assigned activity just as if they were independent single-task programs.

What is a good site to learn flowcharts for beginners?

Draw a flowchart to find the sum of first 50 natural numbers.

How do you stop excessive pings to your server?

Block them at the router. Understand, however, that ICMP Echo Request/Reply (Ping) is a standard network troubleshooting tool, and that disabling it can compromise the ability to troubleshoot certain problems.