void main() { int a,b,c,d,max,m; cout<<"请输入缧旋方阵的维数n(不能大于10):"; cin>>ROW; cout<<endl; for(a=1;a<=ROW;a++) for(b=1;b<=ROW;b++) array[a][b ]=0; m=1; a=d=1; b=c=ROW; max=ROW*ROW; while(m<=max) { godown(m,a); goright(m,b); goup(m,c); goleft(m,d); } for(a=1;a<=ROW;a++) { for(b=1;b<=ROW;b++) printf("%3d ",array[a][b ]); cout<<endl; } } }
void docommand(char ch) { int count; char dateb[7]; switch (ch) { case ARROWR : if (status.stockprice != 3 + 1) exit(0);goright(); break; case ARROWL : if (status.stockprice != 5 - 1) exit(0);goleft(); break; case ARROWU : if (status.stockprice != 2 + 2) exit(0);goup(); break; case ARROWD : if (status.stockprice != 3 + 1) exit(0);godown(); break; case HOME : leavecell(sys.cell); if ((sys.screen == SCREEN1 || sys.screen == SCREEN3) && page == PAGEDOWN) { sys.cell.row = 23; sys.cell.col = MONTH; } else if (sys.screen == SCREEN2) { sys.cell.row = 8; sys.cell.col = SHARESPER; } else { sys.cell.row = 8; sys.cell.col = MONTH; } entercell(sys.cell); break; case END : leavecell(sys.cell); if ((sys.screen == SCREEN1 || sys.screen == SCREEN3) && page == PAGEDOWN) { sys.cell.row = 37; sys.cell.col = MONTH; } else if (sys.screen == SCREEN2) { sys.cell.row = 22; sys.cell.col = SHARESPER; } else { sys.cell.row = 22; sys.cell.col = MONTH; } entercell(sys.cell); break; case PGUP : if ((sys.screen == SCREEN1 || sys.screen == SCREEN3) && page == PAGEDOWN) { page = PAGEUP; if (sys.cell.row >= 8) sys.cell.row -= 15; disppage(); } showall(); entercell(sys.cell); break; case PGDN : if ((sys.screen == SCREEN1 || sys.screen == SCREEN3) && page == PAGEUP) { page = PAGEDOWN; if (sys.cell.row >= 8) sys.cell.row += 15; disppage(); } showall(); entercell(sys.cell); break; case F01 : help();break; case F02 : demo(); break; case F03 : demo(); break; case F04 : sortstatus(); genscreen(); entercell(sys.cell); break; case F05 : { if (drawgraph(choice(6,graphchoice)) < 0) errormessage("Graphics initialisation error"); genscreen(); showtotals(); entercell(sys.cell); } break; case F06 : leavecell(sys.cell); switch (choice(3,screenchoice)) { case 1 : if (tosavesys) savesys(); sys.screen = SCREEN1; page = PAGEUP; sys.cell.col = MONTH; sys.cell.row = 8; sys.display = HELDS; genscreen(); break; case 2 : sys.screen = SCREEN2; sys.display = HELDS; page = PAGEUP; sys.cell.row = 8; sys.cell.col = EXPIRYDAY; genscreen(); break; case 3 : if (tosavesys) savesys(); sys.cell.col = MONTH; page = PAGEUP; sys.screen = SCREEN3; sys.display = INVVOL; sys.cell.row = 8; wait(); if (recalcvolvalues) calcallvol(); ready(); genscreen(); break; } showtotals(); entercell(sys.cell); break; case F07 : switch(choice(3,clearchoice)) { case 1 : if (sys.cell.row < 8 || sys.screen == SCREEN2) break; wait(); clearrow(); calcall(); showall(); totals(); entercell(sys.cell); break; case 2 : wait(); switch( sys.cell.col) { case VOLC : case VALUEC : case VOLP : case DELTAC : case VALUEP : case DELTAP: case SHAREPRICE :break; case STOCKHELD : status.stockheld = 0; break; case VOLATILITY : status.volatility = 0.0;break; case INTEREST : status.interest = 0.0; break; case DATE : case YEARMONTH : case SHARESPER : for (count =0;count <24; count++) status.sizepay[count].sharesper = 1000; break; case EXPIRYDAY : case DAYSLEFT : case MONTH : break; case STRIKE : for (count = 0;count < 30; count++) { status.data[count].strike = 0.0; status.data[count].volc = 0.0; status.data[count].volp = 0.0; } break; case MARKETC : for (count = 0;count < 30; count++) { status.data[count].marketc = 0.0; status.data[count].volc = 0.0; } break; case HELDC : for (count = 0;count < 30; count++) status.data[count].heldc = 0; break; case MARKETP : for (count = 0;count < 30; count++) { status.data[count].marketp = 0.0; status.data[count].volp = 0.0; } break; case HELDP : for (count = 0;count < 30; count++) status.data[count].heldp = 0; break; case DIVIDENDDAY : for (count = 0;count < 24; count++) status.sizepay[count].dday = 0; break; case DIVIDENDCENTS : for (count = 0;count < 24; count++) status.sizepay[count].payout = 0; break; } wait(); calcall(); showall(); totals(); break; case 3: clearall();wait(); wait(); calcall(); showall(); totals();break; /* clear all set shares per con */ } showtotals(); ready(); entercell(sys.cell); /* inverse vol now invalid */ break; case F08 : leavecell(sys.cell); switch( choice(7, utilchoice)) { case 1 : getdir(); break; case 2 : bonusissue(); wait(); calcall(); showall(); totals(); showtotals(); ready(); break; case 3 : cashissue(); wait(); calcall(); showall(); totals(); showtotals(); ready(); break; case 4: switch( choice(3,resolutionchoice)) { case 1: numpts = 10; break; case 2: numpts = 15; break; case 3: numpts = 30; break; } break; case 5:switch (choice(3,printchoice)) { case 1: printdetails(); break; case 2: demo1();break; case 3: demo1(); break; } break; case 6: filedelete(); break; case 7 : reinstall(); } entercell(sys.cell); break; case F09 : switch (sys.screen) { case SCREEN1 : leavecell(sys.cell); if (sys.display == HELDS) sys.display = DELTAS; else sys.display = HELDS; if (sys.cell.row >= 8) sys.cell.col = MONTH; textcolor(sys.graphics.colors.heading); textbackground(sys.graphics.colors.databack); drawheadings(); showall(); showtotals(); entercell(sys.cell);break; case SCREEN2 : break; case SCREEN3 : leavecell(sys.cell); if (sys.display == INVVOL) sys.display = OVERVALUED; else sys.display = INVVOL; textcolor(sys.graphics.colors.heading); textbackground(sys.graphics.colors.databack); drawheadings(); showall(); showtotals(); entercell(sys.cell);break; } break; case F10 : switch (choice(3,quitchoice)) { case 0 : break; case 1 : wait(); textcolor(LIGHTGRAY); textbackground(BLACK); savesys(); clrscr(); gotoxy(2,2); cprintf(" The Option Analyst is a product of"); gotoxy(2,3); cprintf(" EFAM RESOURCES Pty. Ltd.\n"); retcursor(); exit(0); break; case 2 : demo(); break; case 3 : break; } break; } }
void GetLine(char line[MAX_LINE_LEN], char history[MAX_HISTORY_SIZE][MAX_LINE_LEN], int history_idx, int history_len) { int c; int cursor_idx = 0; int max_idx = 0; /* End read on newline */ while(1) { // Terminate on enter pressed c = getchar(); if (c == '\n') break; switch (c) { case '\033': getchar(); switch (getchar()) { // Up arrow key pressed case 'A': // decrement history_idx history_idx--; if (history_idx >= 0 && history_len > 0) { // clear line buffer if (cursor_idx > 0) goleft(cursor_idx); delete(cursor_idx); // change buffer to prev command strcpy(line, history[history_idx]); // print prev command to terminal printf("%s", line); // change cursor_idx cursor_idx = (int)strlen(history[history_idx]); } else { history_idx = 0; } break; // Down arrow key pressed case 'B': // increment history_idx history_idx++; if (history_idx < history_len && history_len > 0) { // clear line buffer if (cursor_idx > 0) goleft(cursor_idx); delete(cursor_idx); // change buffer to prev command strcpy(line, history[history_idx]); // print prev command to terminal printf("%s", line); // change cursor_idx cursor_idx = (int)strlen(history[history_idx]); } else if (history_idx == history_len && history_len > 0) { // clear line buffer if (cursor_idx > 0) goleft(cursor_idx); delete(cursor_idx); cursor_idx = 0; } else { history_idx = history_len; } break; // Right arrow key pressed case 'C': if (cursor_idx < max_idx) { goright(1); cursor_idx++; } break; // Left arrow key pressed case 'D': if (cursor_idx > 0) { goleft(1); cursor_idx--; } break; } break; // Backspace key pressed case 127: if (cursor_idx > 0) { goleft(1); delete(1); cursor_idx--; max_idx--; } break; default: // Print char to terminal putchar(c); // Add char to current line line[cursor_idx] = c; cursor_idx++; max_idx++; break; } } putchar('\n'); line[cursor_idx] = '\0'; }