RSS    

 :

.5

5 . , , . .6.

.6


()

.12203-01 12 01-

2

렠 . -00 ____________ /. . /

Ҡ ____________ / . . /

2002

()

.12203-01 12 01-

.12203-01 12 01

22

2002


.

1 menu 27

2 cursor 28

3 float_input 31

4 n_input 32

5 about 33

6 task 34

7 help 34

8 input 35

9 decision 37

10 output 39

11 42

/*

.

) ; ) .

( 10),

.

. -06 ..

*/

#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

#include <math.h>

#include <string.h>

//

//------------------------------------------------------------------------------

void menu()

{

window(1,1,80,25);

textbackground(BLACK);

clrscr();

window(1,1,80,1);

textbackground(LIGHTGRAY);

clrscr();

gotoxy(1,1);

textcolor(RED);

cprintf("%s","H");

textcolor(BLACK);

cprintf("%s","elp");

gotoxy(9,1);

textcolor(RED);

cprintf("%s","I");

textcolor(BLACK);

cprintf("%s","nput");

gotoxy(18,1);

textcolor(RED);

cprintf("%s","D");

textcolor(BLACK);

cprintf("%s","ecision");

gotoxy(29,1);

textcolor(RED);

cprintf("%s","O");

textcolor(BLACK);

cprintf("%s","utput");

window(1,25,80,25);

textbackground(LIGHTGRAY);

clrscr();

cprintf("Alt+X - exit");

gotoxy(70,1);

textcolor(BLACK);

}

//------------------------------------------------------------------------------

//

//------------------------------------------------------------------------------

void cursor(int n)

{

if(n==1)

{

window(1,1,5,1);

textbackground(GREEN);

clrscr();

textcolor(RED);

cprintf("%s","H");

textcolor(BLACK);

cprintf("%s","elp");

window(5,1,5,1);

textbackground(LIGHTGRAY);

clrscr();

}

if(n==2)

{

window(9,1,14,1);

textbackground(GREEN);

clrscr();

textcolor(RED);

cprintf("%s","I");

textcolor(BLACK);

cprintf("%s","nput");

window(14,1,14,1);

textbackground(LIGHTGRAY);

clrscr();

}

if(n==3)

{

window(18,1,26,1);

textbackground(GREEN);

clrscr();

textcolor(RED);

cprintf("%s","D");

textcolor(BLACK);

cprintf("%s","ecision");

window(26,1,26,1);

textbackground(LIGHTGRAY);

clrscr();

}

if(n==4)

{

window(29,1,35,1);

textbackground(GREEN);

clrscr();

textcolor(RED);

cprintf("%s","O");

textcolor(BLACK);

cprintf("%s","utput");

window(35,1,35,1);

textbackground(LIGHTGRAY);

clrscr();

}

if(n==6)

{

window(3,3,8,3);

textbackground(GREEN);

clrscr();

textcolor(RED);

cprintf("%s","A");

textcolor(BLACK);

cprintf("%s","bout");

window(8,3,8,3);

textbackground(LIGHTGRAY);

clrscr();

}

if(n==7)

{

window(3,4,7,4);

textbackground(GREEN);

clrscr();

textcolor(RED);

cprintf("%s","T");

textcolor(BLACK);

cprintf("%s","ask");

window(7,4,7,4);

textbackground(LIGHTGRAY);

clrscr();

}

if(n==8)

{

window(10,3,18,3);

textbackground(GREEN);

clrscr();

textcolor(RED);

cprintf("%s","K");

textcolor(BLACK);

cprintf("%s","eyboard");

window(18,3,18,3);

textbackground(LIGHTGRAY);

clrscr();

}

if(n==9)

{

window(10,4,14,4);

textbackground(GREEN);

clrscr();

textcolor(RED);

cprintf("%s","F");

textcolor(BLACK);

cprintf("%s","ile");

window(14,4,14,4);

textbackground(LIGHTGRAY);

clrscr();

}

if(n==10)

{

window(30,3,37,3);

textbackground(GREEN);

clrscr();

textcolor(RED);

cprintf("%s","D");

textcolor(BLACK);

cprintf("%s","isplay");

window(37,3,37,3);

textbackground(LIGHTGRAY);

clrscr();

}

if(n==11)

{

window(30,4,34,4);

textbackground(GREEN);

clrscr();

textcolor(RED);

cprintf("%s","F");

textcolor(BLACK);

cprintf("%s","ile");

window(34,4,34,4);

textbackground(LIGHTGRAY);

clrscr();

}

}

//------------------------------------------------------------------------------

//

//------------------------------------------------------------------------------

int n_input(int max)

{

char ch;

char str[100];

int i=0;

do

{

ch = (char)getch();

if (i==0)

{

if ((ch>'0')&&(ch<='9'))

{

str[i++]=ch;

putch(ch);

}

}

else

{

if ((ch>='0')&&(ch<='9'))

{

str[i++]=ch;

putch(ch);

}

}

if((ch=='\r')&&(i==0)) // ENTER

{

ch='x';

printf(" \b"); //backspace

}

if ((ch=='\b')&&(i>0)) // BACKSPACE

{

i--;

printf("\b \b");

}

if(i==(max+1)) // max

{

i--;

printf("\b \b");

}

}

while (ch!='\r');

str[i]='\0';

for (int j=i;j>0;j--)

printf("\b \b");

printf("%d",atoi(str));

return atoi(str); //

}

//------------------------------------------------------------------------------

//

//------------------------------------------------------------------------------

double float_input()

{

const max=6; //

int i=0; //

char ch,buffer[max];

bool flp=0; // "."

bool fle=0; // ""

do

{

ch = (char)getch();

if ((ch=='-')&&((i==0)||(buffer[i-1]=='e'))) // "-"

{ //

buffer[i++]=ch; // ""

putch(ch);

}

if ((ch>='0')&&(ch<='9')) //

{

buffer[i++]=ch;

putch(ch);

}

if (((ch=='.')||(ch==','))&&(flp==0)) //

{ //

buffer[i++]='.';

putch('.');

flp=1;

}

if ((ch=='e' || ch=='E') && i>0 && fle==0)

{ // ""

buffer[i++]='e';

putch('e');

fle=1;

}

if ((ch=='\b')&&(i>0)) //

{ //

i--; //BACKSPACE

cprintf("\b \b");

if (buffer[i]=='.') flp=0;

if (buffer[i]=='E') fle=0;

}

if ((ch=='\r')&&(i==0)) ch='\0';

if(i==(max+1))

{

i--;

cprintf("\b \b");

}

} while (ch!='\r');

buffer[i]='\0'; //""

for (int j=i;j>0;j--)

cprintf("\b \b");

cprintf("%2.2e",strtod(buffer,0));

return strtod(buffer,0); // .

}

//------------------------------------------------------------------------------

//

//------------------------------------------------------------------------------

void about()

{

char ch;

window(25,8,59,18);

textbackground(BLACK);

clrscr();

window(24,7,58,17);

textbackground(LIGHTGRAY);

textcolor(BLACK);

clrscr();

cprintf("\n\r ⪠ ண 襭 ");

cprintf("\n\r ⥬ ");

cprintf("\n\n\r 1.0 2007.");

cprintf("\n\n\r 믮 㤥 . -06");

cprintf("\n\r ..");

cprintf("\n\n\r த <Enter>");

do

{

ch=(char)getch();

}

while(ch!=13); // ENTER

}

//------------------------------------------------------------------------------

//

//------------------------------------------------------------------------------

void task()

{

char ch;

window(21,6,62,20);

textbackground(BLACK);

clrscr();

window(20,5,61,19);

textbackground(LIGHTGRAY);

textcolor(BLACK);

clrscr();

cprintf("\n\n\n\r ண 襭 ⥬");

cprintf("\n\r . ⮤: ");

cprintf("\n\r ) 権; ). ।ᬮ-");

cprintf("\n\r ᫠ ( 10), -");

cprintf("\n\r 樥 ᢮ ");

cprintf("\n\r 童.");

cprintf("\n\n\n\n\n\r த <Enter>");

do

{

ch=(char)getch();

}

while(ch!=13); // ENTER

}

//------------------------------------------------------------------------------

// help

//------------------------------------------------------------------------------

void help()

{

char ans;

int h_num=1;

do

{

menu(); //

window(3,4,12,5);

textbackground(BLACK);

clrscr();

window(2,3,11,4);

textbackground(LIGHTGRAY);

clrscr();

textcolor(RED);

cprintf("%s"," A");

textcolor(BLACK);

cprintf("%s","bout");

textcolor(RED);

cprintf("%s","\n\r T");

textcolor(BLACK);

cprintf("%s","ask");

cursor(h_num+5);

ans=(char)getch();

if(ans==80) {if(h_num!=2) h_num++;} // " "

if(ans==72) {if(h_num!=1) h_num--;} // " "

}

while((ans!=27)&&(ans!='a')&&(ans!='A')&&(ans!='t')&&(ans!='T')&&(ans!=13));

if((ans=='t')||(ans=='T')||((h_num==2)&&(ans==13)))

{

window(2,3,14,6);

textbackground(BLACK);

clrscr();

task(); //

}

if((ans=='a')||(ans=='A')||((h_num==1)&&(ans==13)))

{

window(2,3,14,6);

textbackground(BLACK);

clrscr();

about(); //

}

}

//------------------------------------------------------------------------------

//

//------------------------------------------------------------------------------

void input(double **&A,double *&B,int &n)

{

char ch;

window(8,3,20,6);

textbackground(BLACK);

clrscr();

window(15,6,64,18);

textbackground(LIGHTGRAY);

clrscr();

textcolor(BLACK);

cprintf("%s","\n\n\r ᫮ (1..10)");

window(48,8,51,8);

textbackground(BLACK);

textcolor(LIGHTGRAY);

clrscr();

bool fl=false;

do // 10

{

n=n_input(2); //

if((n<=10)&&(n>=1)) fl=true;

else clrscr();

}

while(fl!=true);

A=(double**)malloc(n*n*sizeof(double)); //

B=(double*)malloc(n*sizeof(double));

window(15,10,64,10);

textbackground(LIGHTGRAY);

clrscr();

textcolor(BLACK);

cprintf("%s","\r 樥⮢");

window(15,11,64,11);

textbackground(LIGHTGRAY);

clrscr();

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

{

A[i]=(double*)malloc(n*sizeof(double));

for(int j=0;j<n;j++)

{

clrscr();

cprintf("\r A[%d][%d]=",i+1,j+1);

A[i][j]=float_input(); //

}

}

window(15,13,64,13);

textbackground(LIGHTGRAY);

clrscr();

cprintf("%s","\n\n\r ᢮ 童");

window(15,14,64,14);

textbackground(LIGHTGRAY);

clrscr();

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

{

clrscr();

cprintf("\r B[%d]=",i+1);

B[i]=float_input(); //

}

window(15,17,64,17);

textbackground(LIGHTGRAY);

clrscr();

cprintf("%s","\r த <Enter>");

do

{ch=(char)getch();}

while(ch!=13); // ENTER

}

//------------------------------------------------------------------------------

//

//------------------------------------------------------------------------------

void decision(double **&A,double *&B,double *&X,int &n,int &s)

{

char ch,ans;

int k;

double *Z; //

X=(double*)malloc(n*sizeof(double)); //

Z=(double*)malloc(n*sizeof(double)); //

for(int i=0;i<n;i++) Z[i]=1;

window(23,7,57,16);

textbackground(LIGHTGRAY);

textcolor(BLACK);

clrscr();

cprintf("\n\r 롨 ⮤ 襭: ");

cprintf("\n\r 1-⮤ 権");

cprintf("\n\r 2-⮤ ");

do

{ans=(char)getch();}

while((ans!='1')&&(ans!='2'));

if(ans=='1') //

{

s=0;

do

{

k=0;

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

{

X[i]=B[i]*(-1);

for(int j=0;j<n;j++)

{X[i]=X[i]+(double)A[i][j]*Z[j];}

if(A[i][i]!=0)

{

if(fabs((double)X[i]/A[i][i])>=0.0001) k=1; //

X[i]=Z[i]-(double)X[i]/A[i][i]; // ->k=0->

}

}

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

Z[i]=X[i];

s++; // ++

if(s==100) k=0; // > 100->

}

while(k!=0);

}

if(ans=='2') //

{

s=0;

do

{

k=0;

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

{

X[i]=B[i]*(-1);

for(int j=0;j<n;j++)

{

if(A[i][j]!=0)

X[i]=X[i]+(double)A[i][j]*Z[j];

}

if(A[i][i]!=0)

{

if(fabs((double)X[i]/A[i][i])>=0.001) k=1; //

X[i]=Z[i]-(double)X[i]/A[i][i];

Z[i]=X[i];

}

}

s++;

if(s==100) k=0; // 100

} // ->

while(k!=0);

}

cprintf("\n\n\r 祭");

cprintf("%s","\n\n\n\r த <Enter>");

do

{ch=(char)getch();}

while(ch!=13);

}

//------------------------------------------------------------------------------

//

//------------------------------------------------------------------------------

void output(double **&A,double *&B,double *&X,int &n,int &s)

{

char ch_out;

int xx=5,yy=5; //

float temp; //

window(1,25,80,25);

textbackground(LIGHTGRAY);

clrscr();

cprintf("Alt+X - exit Arrows - scrolling");

gotoxy(70,1);

textcolor(BLACK);

window(3,3,78,23);

textbackground(LIGHTGRAY);

textcolor(BLACK);

clrscr();

if(s!=100) //

{

window(3,4,66,4);

textbackground(LIGHTGRAY);

clrscr();

cprintf("\r ⥬ :"); //

window(3,12,66,12);

textbackground(LIGHTGRAY);

clrscr();

cprintf("\r 襭"); //

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

{

if(i==0)

{

window(3,13,30,19);

textbackground(LIGHTGRAY);

clrscr();

}

if(i==5) // >5->

{

window(32,13,70,19);

textbackground(LIGHTGRAY);

clrscr();

}

cprintf("\n\r X(%d)=%.4f",i+1,X[i]); //

}

window(3,20,66,20);

textbackground(LIGHTGRAY);

clrscr();

cprintf("\n\n\r ᫮ 権: %d",s); //

} //if...

else cprintf("\n\n ⥬ 襭");

window(14,22,66,22);

textbackground(LIGHTGRAY);

clrscr();

cprintf("\n\n\r த <Enter>");

if(s!=100) // , .. <100

{

window(4,5,77,10); // ()

textbackground(LIGHTGRAY); //

textcolor(BLACK);

clrscr();

if(n<=5) // 5

{

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

{

cprintf("\n\r ");

for(int j=0;j<=n;j++)

{

if(j==n) cprintf("=%.2f",B[i]); //

else

{

if(j<n)

{

if(A[i][j]>0) cprintf(" + %.2fX(%d)",A[i][j],j+1);

else

{

temp=A[i][j]*(-1); //

cprintf(" - %.2fX(%d)",temp,j+1);

}

}

}

}

} //for(i<n)...

} //if(n<=5)...

else // 5

{

window(4,6,72,10); // ()

textbackground(BLUE); //

textcolor(WHITE);

do

{

clrscr();

for(int i=xx-5;i<xx;i++)

{

cprintf("\n\r ");

for(int j=yy-5;j<=yy;j++)

{

if(j==n) cprintf(" = %.2f",B[i]); //

else

{

if(j<n)

{

if(A[i][j]>0) cprintf(" + %.2fX(%d)",A[i][j],j+1);

else

{

temp=A[i][j]*(-1);

cprintf(" - %.2fX(%d)",temp,j+1);

}

}

}

}

}

ch_out=(char)getch();

if((ch_out==80)&&(xx!=n)) xx++; // " "

if((ch_out==72)&&(xx!=5)) xx--; // " "

if((ch_out==77)&&(yy!=n)) yy++; // " "

if((ch_out==75)&&(yy!=5)) yy--; // " "

}

while(ch_out!=27); // ESC

//

window(4,6,77,10); // ()

textbackground(LIGHTGRAY); //

textcolor(BLACK);

clrscr(); //

for(int i=xx-5;i<xx;i++)

{

cprintf("\n\r ");

for(int j=yy-5;j<=yy;j++)

{

if(j==n) cprintf(" = %.2f",B[i]); //

else

{

if(j<n)

{

if(A[i][j]>0) cprintf(" + %.2fX(%d)",A[i][j],j+1);

else

{

temp=A[i][j]*(-1);

cprintf(" - %.2fX(%d)",temp,j+1);

}

}

}

}

}

window(22,22,53,22);

textbackground(BLUE);

textcolor(WHITE);

clrscr();

cprintf("\r த <Enter>"); //

} //else(n<=5)...

}

do // ENTER

{ch_out=(char)getch();}

while(ch_out!=13);

}

//------------------------------------------------------------------------------

//==============================================================================

main()

{

int n, //

m_num=1,

s; //

char ch,ch2;

bool inpflag=false,decflag=false; //

double *X, //

**A, //

*B; //

_setcursortype(_NOCURSOR); //

do

{

menu();

cursor(m_num);

ch=(char)getch();

if((ch=='h')||(ch=='H')||((ch==13)&&(m_num==1))) help();

if((ch=='i')||(ch=='I')||((ch==13)&&(m_num==2)))

{input(A,B,n);inpflag=true;}

if(((ch=='o')||(ch=='O')||((ch==13)&&(m_num==4)))&&(inpflag==false)&&(decflag==false))

{

window(28,9,55,14);

textbackground(BLACK);

clrscr();

window(27,8,54,13);

textbackground(LIGHTGRAY);

textcolor(BLACK);

clrscr();

cprintf("\r\n ");

cprintf("\r\n 祭 襭!");

cprintf("\n\n\r 室 Esc");

do

{ch2=(char)getch();}

while(ch2!=27);

}

if(((ch=='o')||(ch=='O')||((ch==13)&&(m_num==4)))&&(inpflag==true)&&(decflag==false))

{

window(28,9,55,14);

textbackground(BLACK);

clrscr();

window(27,8,54,13);

textbackground(LIGHTGRAY);

textcolor(BLACK);

clrscr();

cprintf("\r\n 祭 襭!");

cprintf("\n\n\n\r 室 Esc");

do

{ch2=(char)getch();}

while(ch2!=27);

}

if(((ch=='o')||(ch=='O')||((ch==13)&&(m_num==4)))&&(inpflag==true)&&(decflag==true))

{output(A,B,X,n,s);decflag=false;}

if(((ch=='d')||(ch=='D')||((ch==13)&&(m_num==3)))&&(inpflag==true))

{decision(A,B,X,n,s);decflag=true;}

if(((ch=='d')||(ch=='D')||((ch==13)&&(m_num==3)))&&(inpflag==false))

{

window(28,9,55,14);

textbackground(BLACK);

clrscr();

window(27,8,54,13);

textbackground(LIGHTGRAY);

textcolor(BLACK);

clrscr();

cprintf("\r\n !");

cprintf("\n\n\n\r 室 Esc");

do

{ch2=(char)getch();}

while(ch2!=27);

}

if(ch==77) {if(m_num!=4) m_num++;} // " "

if(ch==75) {if(m_num!=1) m_num--;} //" "

}

while(ch!=45); // ALT+X

}

//==============================================================================


()

1. , .. : []/.. . -.: , 1990.- 544.

2. , .. : []/ .. - .: , 1998. - 600 .


: 1, 2


:

Twitter Facebook

                 

© 2010.