Guest User

code

a guest
Apr 13th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.63 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<windows.h>
  3. #include<pthread.h>
  4. #include<conio.h>
  5. #include<string.h>
  6. #include<graphics.h>
  7. #include<time.h>
  8. #define space "\t \t \t"
  9. static int up_price=0;
  10. static int ind_pos=0;
  11. typedef struct cmp_data
  12. {
  13. char name[100];
  14. char start_price[100];
  15. char volume[100];
  16. char market[100];
  17. } cmp_data;
  18. typedef struct account_details
  19. {
  20. char name[100];
  21. int investement;
  22. int available_cash;
  23. int stock_value;
  24. int total_transaction;
  25. } account_details;
  26. typedef struct user_details
  27. {
  28. char username[100];
  29. void *portfolio;
  30. void *watch_list;
  31. account_details *account;
  32. void *trans_his;
  33. } user_details;
  34. typedef struct record
  35. {
  36. char cmp_name[100];
  37. int no_of_share;//buyed
  38. char volume[100];//no of shares total present.
  39. int buy_price;
  40. int pos;
  41. int selling_price;
  42. int percentage;//profit or loss gain
  43. char market_capital[100];
  44. char buy_time[40];
  45. char sell_time[40];
  46. int cash;//recived or given for shares;
  47. struct record*next;//next pointer to create new record;
  48. } record;
  49. int array[20]= {0};
  50. void status();
  51. int check_quantity_available(char *requested,char *available);
  52. void updating_funds(user_details*file,int cmp_num,int shares);
  53. int check_funds(char *quantity,int number,long long int cash);
  54. int check_quantity(char *quantity);
  55. void buy_section(int cmp_num,user_details* file);
  56. void updating_point();
  57. void signup_page();
  58. int* whole_data(int st_price,int page,int CURRENT,int *length);
  59. void fun_graph(int *data,int len,int st_price);
  60. void graph_coordinates(int *prev_data,int len,int st_price);
  61. void view_stock(cmp_data*Data,int current,int page,user_details*file);
  62. void graph_section(char *name,char* shares,char* st_price,int page,int CURRENT);
  63. void *myThreadFun(void *id);
  64. char *int_char(int src);
  65. void login_page();
  66. int char_to_int(char*num);
  67. void user_choice(int choice,char *Name,user_details *file);
  68. void userpage(char *username);
  69. void welcome_page(char *username);
  70. int Main_page();
  71. void insert_into_record(cmp_data*collect,char *Data,int pos);
  72. void arrow_fun(int exp,int act);
  73. void printf_sec(char *data);
  74. void printf_name(char *name);
  75. int calcu_eps(char* capital,char* shares);
  76. int calcu_pe(char*price,int eps);
  77. int calcu_Div(char* price);
  78. COORD coord= {0,0};
  79. void gotoxy(int x,int y)
  80. {
  81. coord.X=x;
  82. coord.Y=y;
  83. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
  84. }
  85. user_details* create_user_info(char *username)
  86. {
  87. user_details *rcd=(user_details*)malloc(1*sizeof(user_details));
  88. strcpy(rcd->username,username);
  89. account_details *poin=(account_details*)malloc(1*sizeof(account_details));
  90. strcpy(poin->name,username);
  91. printf("Name:%s\n",poin->name);
  92. _getch();
  93. poin->investement=500000;
  94. poin->available_cash=500000;
  95. poin->stock_value=0;
  96. poin->total_transaction=0;
  97. rcd->account=poin;
  98. rcd->portfolio=NULL;
  99. rcd->trans_his=NULL;
  100. rcd->watch_list=NULL;
  101. return rcd;
  102. }
  103. user_details* checking_user_details(char *username)
  104. {
  105. FILE *FP,*FP_1,*FP_2;
  106. if((FP=fopen("User_Details.txt","r"))==NULL)
  107. {
  108. FP_1=fopen("User_Details.txt","w");
  109. user_details *rcd=create_user_info(username);
  110. fwrite(rcd,sizeof( *rcd),1,FP_1);
  111. return rcd;
  112. }
  113. /* user_details demo;
  114. while(fread(&demo,sizeof(user_details),1,FP))
  115. {
  116. if(strcmp(demo.username,username)==0)
  117. return demo;
  118. }*/
  119. FP_1=fopen("User_Details.txt","a");
  120. user_details *rcd;
  121. rcd=create_user_info(username);
  122. fwrite(rcd,sizeof(*rcd),1,FP_1);
  123. return rcd;
  124. }
  125. void *myThreadFun(void *id)
  126. {
  127. FILE * fp_3=fopen("Prices_list.txt","a+");
  128. char *str;
  129. time_t t;
  130. int random_1,idx,count=20;
  131. random_1 =idx=0;
  132. while(count--)
  133. {
  134. srand((unsigned) time(&t));
  135. random_1=rand()%10;
  136. Sleep(1000);
  137. if(random_1 == count)
  138. {
  139. if(random_1%2==0)
  140. str=int_char(random_1*2);
  141. else
  142. str=int_char(random_1*2*-1);
  143. }
  144. else
  145. {
  146. if(random_1%2!=0)
  147. str=int_char(random_1);
  148. else
  149. str=int_char(random_1*-1);
  150. }
  151. while(str[idx]!='\0')
  152. {
  153. fputc(str[idx],fp_3);
  154. idx++;
  155. }
  156. if(idx==0)
  157. {
  158. fputc('0',fp_3);
  159. }
  160. fputc('#',fp_3);
  161. idx=0;
  162. }
  163. fputc('$',fp_3);
  164. up_price++;
  165. printf("\n\n");
  166. printf(space space space"Press any key");
  167. fclose(fp_3);
  168. }
  169. int main()
  170. {
  171. printf("\n\n\n\n\n");
  172. printf(space "\tWELCOME\n");
  173. printf(space "\t TO \n");
  174. printf(space "\t HELIX \n");
  175. printf(space"\tPress any Key\n");
  176. _getch();
  177. Main_page();
  178. return 0;
  179. }
  180. void login_page()
  181. {
  182. FILE *fp;
  183. updating_point();
  184. char x,*tempstr;
  185. char accountsDB[100],username[100],password[100],users[100];
  186. system("cls");
  187. printf("\n\n\n\n");
  188. printf(space space "<<<<<<<<<<<<<<Login>>>>>>>>>>>> \n\n");
  189. printf("\n\n\n"space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 218, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 191);
  190. printf("\n"space "\t\tUsername : %c %c\n",179,179);
  191. printf(""space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 192, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 217);
  192. gotoxy(52,10);
  193. scanf("%s",username);
  194. printf("\n");
  195. int idx=0;
  196. while(username[idx] != '\0')
  197. {
  198. users[idx] = username[idx];
  199. idx++;
  200. }
  201. users[idx] = '\0';
  202. idx=0;
  203. printf("\n\n\n"space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 218, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 191);
  204. printf("\n"space "\t\tPassword : %c %c\n",179,179);
  205. printf(""space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 192, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 217);
  206. gotoxy(52,16);
  207. while ((x = _getch()) != '\r')
  208. {
  209. printf("*");
  210. password[idx++] = x;
  211. }
  212. password[idx] = '\0';
  213. idx = 0;
  214. strcat(username, password);
  215. fp = fopen("PROJECT_DATA_FILE.txt","r");
  216. while((x = fgetc(fp)) != EOF)
  217. {
  218. accountsDB[idx++] = x;
  219. }
  220. accountsDB[idx] = '\0';
  221. fclose(fp);
  222. if(NULL == strstr(accountsDB, username))
  223. {
  224. printf("\n\n"space"*Username or password is wrong\n");
  225. goto end_login;
  226. }
  227. else
  228. {
  229. tempstr = strstr(accountsDB, username);
  230. }
  231. idx=0;
  232. while(username[idx]!='\0')
  233. {
  234. if(username[idx]!=tempstr[idx])
  235. break;
  236. idx++;
  237. }
  238. if(idx==strlen(username))
  239. {
  240. userpage(users);
  241. goto end_login;
  242. }
  243. else
  244. {
  245. printf("\n\n"space"*Username or password is wrong\n");
  246. end_login:
  247. printf(space "\n"space"press any key\n");
  248. _getch();
  249. }
  250. }
  251. void userpage(char *username)
  252. {
  253. welcome_page(username);
  254. user_details *file=checking_user_details(username);
  255. int select=1,loop=1;
  256. user_sec:
  257. system("color 03");
  258. while(loop)
  259. {
  260. updating_point();
  261. if(select>7 ||select==0)
  262. {
  263. select =1;
  264. }
  265. system("cls");
  266. printf("\n\n\n\n");
  267. printf(space "<<<HELIX GUIDE>>>\n");
  268. arrow_fun(1,select);
  269. printf("HELP\n");
  270. arrow_fun(2,select);
  271. printf("PORTFOLIO\n");
  272. arrow_fun(3,select);
  273. printf("WATCH LIST\n");
  274. arrow_fun(4,select);
  275. printf("STOCK LIST\n");
  276. arrow_fun(5,select);
  277. printf("ACCOUNT\n");
  278. arrow_fun(6,select);
  279. printf("TRANSACTION HISTROY\n");
  280. arrow_fun(7,select);
  281. printf("EXIT\n");
  282. printf(space"Use the Arrow key's to move and select\n");
  283. switch(_getch())
  284. {
  285. case 'H':
  286. select--;
  287. break;
  288. case 'P':
  289. select++;
  290. break;
  291. case 13:
  292. if(select!=7)
  293. {
  294. user_choice(select,username,file);
  295. }
  296. else
  297. {
  298. loop=0;
  299. }
  300. break;
  301. }
  302. }
  303. }
  304. void Help_sec(char *Name)
  305. {
  306. updating_point();
  307. printf("\n");
  308. system("cls");
  309. printf(space"<<<<<<<<<<<<<<<<Help_sec>>>>>>>>>>>>>>>>>>>>>>\n\n");
  310. printf("->Helix is an virtual Trading app\n");
  311. printf("->Which is based on Equity share's\n");
  312. printf(" <<<<Company Details>>>>>\n");
  313. printf("->Company Name=XYZ\n");
  314. printf("->Volume=No of shares available\n");
  315. printf("->Starting price=Starting price of each share\n");
  316. printf("->Market Capital=Total turn over capital of the company\n");
  317. printf(" <<<<<Fundamental Details>>>>>>\n");
  318. printf("->EPS=Earning per share\n");
  319. printf("->It is used to determine company stock Condition\n");
  320. printf("->Its supply and Demand in the market\n");
  321. printf("->if eps<=26 then its is consider at under value share\n");
  322. printf("->if eps >26 then it is consider at over value share\n");
  323. printf("->PE ratio=Price Earnings\n");
  324. printf("->It is used to determine company financial condition\n");
  325. printf("->If its below 14 it is consider as good\n");
  326. printf("->Dividend=Payed by the comapny\n");
  327. printf("->To those who hold there company share for long term \n");
  328. printf("->Min range =1 year to max=unlimited as long the company exists in the market\n");
  329. printf("->Graph section \n");
  330. printf("->It is used to show the company Finanial condition\n");
  331. printf("->Its previous performance ,also used to calculate the technical analysis\n");
  332. printf(space"Press any key\n");
  333. _getch();
  334. }
  335. void portfolio(char *Name,user_details *file)
  336. {
  337. system("cls");
  338. printf("\n\n\n");
  339. printf(space"<<<<<<<<<<<<<<<<<<portfolio>>>>>>>>>>>>>>>>>>>\n\n");
  340. if(file->portfolio==NULL)
  341. {
  342. printf(space " COMPANY_NAME || Shares || Cur_price || Buy_priced \n\n" );
  343. printf(space " NULL || NULL || NULL || NULL \n");
  344. }
  345. else
  346. {
  347. char x;
  348. int loop=1,arrow=0,total=1,time=0;
  349. while(loop)
  350. {
  351. system("cls");
  352. printf(space " COMPANY_NAME || Shares || Cur_price || Buy_priced \n\n" );
  353. record *cur=(record*)file->portfolio;
  354. while(cur!=NULL)
  355. {
  356. arrow_fun(time,arrow);
  357. printf_name(cur->cmp_name);
  358. printf_sec(int_char(cur->no_of_share));
  359. printf(" %d ",array[cur->pos]);
  360. printf_sec(int_char(cur->buy_price));
  361. printf("\n");
  362. cur=cur->next;
  363. time++;
  364. }
  365. total=time+1;
  366. time=0;
  367. arrow_fun(total,arrow);
  368. printf("Go back\n");
  369. printf(space"Use the arrow keys\n");
  370. fflush(stdin);
  371. x=_getch();
  372. switch(x)
  373. {
  374. case 72:
  375. printf("dec\n");
  376. arrow--;
  377. break;
  378. case 80:
  379. printf("inc\n");
  380. arrow++;
  381. break;
  382. case 13:
  383. loop=0;
  384. break;
  385. }
  386. printf("arrow =%d",arrow);
  387. _getch();
  388. }
  389. }
  390. printf(space "Press any key\n");
  391. _getch();
  392. }
  393. void status()
  394. {
  395. printf(space"Will be added Soon\n");
  396. printf(space"Press any key\n");
  397. _getch();
  398. }
  399. void watch_list(char *Name,user_details *file)
  400. {
  401. system("cls");
  402. printf("\n\n\n\n");
  403. printf(space"<<<<<<<<<<<<<<<<<<Watch List>>>>>>>>>>>>>>>>>>>\n\n");
  404. status();
  405. }
  406. void inserting_the_data(cmp_data *collect,char*Data,int prev,int cur)
  407. {
  408. int idx=0,position=0;
  409. if(cur==0 && prev!=cur)
  410. {
  411. insert_into_record(collect,Data,cur+1);
  412. }
  413. else if(cur==1 && prev!=cur)
  414. {
  415. position=cur*5;
  416. while(position--)
  417. {
  418. while(Data[idx]!='$')
  419. {
  420. idx++;
  421. }
  422. idx+=2;
  423. }
  424. insert_into_record(collect,Data,idx);
  425. }
  426. else if(cur==2 && prev!=cur)
  427. {
  428. position=10;
  429. while(position--)
  430. {
  431. while(Data[idx]!='$')
  432. {
  433. idx++;
  434. }
  435. idx+=2;
  436. }
  437. insert_into_record(collect,Data,idx);
  438. }
  439. else if(cur==3 && prev!=cur)
  440. {
  441. position=15;
  442. while(position--)
  443. {
  444. while(Data[idx]!='$')
  445. {
  446. idx++;
  447. }
  448. idx+=2;
  449. }
  450. insert_into_record(collect,Data,idx);
  451. }
  452.  
  453. }
  454. void insert_into_record(cmp_data *collect,char *Data,int pos)
  455. {
  456. int count=5,idx=0,range=0;
  457. char temp[100]= {0};
  458. while(range<count)
  459. {
  460. idx=0;
  461. while(Data[pos]!='#')
  462. {
  463. temp[idx++]=Data[pos];
  464. pos++;
  465. }
  466. temp[idx]='\0';
  467. pos++;
  468. strcpy(collect[range].name,temp);
  469. idx=0;
  470. temp[100]= {0};
  471. while(Data[pos]!='#')
  472. {
  473. temp[idx]=Data[pos++];
  474. idx++;
  475. }
  476. temp[idx]='\0';
  477. strcpy(collect[range].start_price,temp);
  478. idx=0;
  479. temp[100]= {0};
  480. pos++;
  481. while(Data[pos]!='$')
  482. {
  483. temp[idx]=Data[pos++];
  484. idx++;
  485. }
  486. temp[idx]='\0';
  487. pos+=2;
  488. strcpy(collect[range].volume,temp);
  489. temp[100]= {0};
  490. char *str=int_char((char_to_int(collect[range].start_price))*(char_to_int(collect[range].volume))*2);
  491. strcpy(collect[range].market,str);
  492. range++;
  493. }
  494. }
  495. void stock_list(char *Name,user_details *file)
  496. {
  497. system("cls");
  498. FILE*fp=fopen("COMPANY_DATA.txt","r+");
  499. char x,cmp_details[1000];
  500. cmp_data *page_list =(cmp_data*)malloc(sizeof(cmp_data)*5);
  501. int idx=0,arrow=0;
  502. while((x = fgetc(fp)) != EOF)
  503. {
  504. cmp_details[idx++] = x;
  505. }
  506. cmp_details[idx] = '\0';
  507. int prev_page=4,cur_page=0,loop=1;
  508. while(loop)
  509. {
  510. system("cls");
  511. system("color f3");
  512. inserting_the_data(page_list,cmp_details,prev_page,cur_page);
  513. prev_page=cur_page;
  514. printf("\n\n <<<<<<<<<<<<<<<<<<<<<<<<<<<<Stock List>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
  515. printf(space"Company Name ||Starting price || Cur_price || Volume || MARKET \n");
  516. arrow_fun(0,arrow);
  517. printf_name(page_list[0].name);
  518. printf_sec(page_list[0].start_price);
  519. printf("%d ",array[(5*cur_page)+0]);
  520. printf_sec(page_list[0].volume);
  521. printf_sec(page_list[0].market);
  522. printf("\n");
  523. arrow_fun(1,arrow);
  524. printf_name(page_list[1].name);
  525. printf_sec(page_list[1].start_price);
  526. printf("%d ",array[(5*cur_page)+1]);
  527. printf_sec(page_list[1].volume);
  528. printf_sec(page_list[1].market);
  529. printf("\n");
  530. arrow_fun(2,arrow);
  531. printf_name(page_list[2].name);
  532. printf_sec(page_list[2].start_price);
  533. printf("%d ",array[(5*cur_page)+2]);
  534. printf_sec(page_list[2].volume);
  535. printf_sec(page_list[2].market);
  536. printf("\n");
  537. arrow_fun(3,arrow);
  538. printf_name(page_list[3].name);
  539. printf_sec(page_list[3].start_price);
  540. printf("%d ",array[(5*cur_page)+3]);
  541. printf_sec(page_list[3].volume);
  542. printf_sec(page_list[3].market);
  543. printf("\n");
  544. arrow_fun(4,arrow);
  545. printf_name(page_list[4].name);
  546. printf_sec(page_list[4].start_price);
  547. printf("%d ",array[(5*cur_page)+4]);
  548. printf_sec(page_list[4].volume);
  549. printf_sec(page_list[4].market);
  550. printf("\n");
  551. arrow_fun(5,arrow);
  552. printf("BACK\n");
  553. printf(space "use the arrow keys to turn pages and for selecting stock\n");
  554. printf(space "press enter for selecting\n");
  555. printf("\n\n\n"space space"Page:%d\n",cur_page);
  556. x=_getch();
  557. switch(x)
  558. {
  559. case 72:
  560. arrow--;
  561. break;
  562. case 80:
  563. arrow++;
  564. break;
  565. case 75:
  566. cur_page--;
  567. break;
  568. case 77:
  569. cur_page++;
  570. break;
  571. case 13:
  572. if(arrow==5)
  573. loop=0;
  574. else
  575. view_stock(page_list,arrow,cur_page,file);
  576. }
  577. if(arrow>5 ||arrow<0)
  578. {
  579. arrow=0;
  580. }
  581. if(cur_page>3 ||cur_page<0)
  582. {
  583. cur_page=0;
  584. arrow =0;
  585. }
  586. }
  587. }
  588. int calcu_eps(char* capital,char* shares)
  589. {
  590. int out_stan_shares=char_to_int(shares);
  591. return char_to_int(capital)/out_stan_shares-14;
  592. }
  593. int calcu_pe(char*price,int eps)
  594. {
  595. return eps/char_to_int(price);
  596. }
  597. int calcu_Div(char* price)
  598. {
  599. int dividend_yield=7;
  600. return char_to_int(price)/dividend_yield;
  601. }
  602. void updating_point()
  603. {
  604. char Data[1000],x,max[3];
  605. int i,pos=0,in=0,count=0,idx=0;
  606. FILE *fp1,*fp;
  607. if((fp1=fopen("COMPANY_DATA.txt","r"))==NULL)
  608. {
  609. fp1=fopen("COMPANY_DATA.txt","w");
  610. char data[]="|venkys#20#500000$|satin#10#2500000$|ultratech#15#2000000$|polaris#17#250000$|Aditya vision#20#700000$|Mrf#35#1000000$|page#25#350000$|Ashok leyland#45#100000$|Tata#15#750000$|jio#40#100000$|kakatiya Cement#33#750000$|Coasboard Industries#27#500000$|Electrotham industries#21#210000$|Eichers#77#1000000$|Rana Sugar#13#500000$|Alkai Metals#39#450000$|Amazon#61#8500000$|JustDial#69#7200000$|Adobe#77#900000$|infoys#55#6500000$";
  611. i=0;
  612. while(data[i]!='\0')
  613. {
  614. x=data[i];
  615. fputc(x,fp1);
  616. i++;
  617. }
  618. fclose(fp1);
  619.  
  620. }
  621. if(ind_pos==0)
  622. {
  623. int new_arr[20]= {20,10,15,17,20,35,25,45,15,40,33,27,21,77,13,39,61,69,77,55};
  624. for(idx=0; idx<20; idx++)
  625. {
  626. array[idx]=new_arr[idx];
  627. }
  628. }
  629. if(ind_pos<up_price)
  630. {
  631. fp=fopen("Prices_list.txt","a+");
  632. idx= pos=in=count =0;
  633. x='k';
  634. while(count<ind_pos)
  635. {
  636. x=fgetc(fp);
  637. if(x=='$')
  638. {
  639. count++;
  640. }
  641. }
  642. count=0;
  643. if(ind_pos!=0)
  644. {
  645. x='k';
  646. }
  647. while(x!='$')
  648. {
  649. x=fgetc(fp);
  650. Data[idx]=x;
  651. idx++;
  652. }
  653. Data[idx]='\0';
  654. while(in<idx)
  655. {
  656. in++;
  657. while(Data[in]!='#' && Data[in]!='$')
  658. {
  659. max[pos++]=Data[in];
  660. in++;
  661. }
  662. if(Data[in]=='$')
  663. {
  664. in++;
  665. }
  666. else
  667. {
  668. if(pos==0)
  669. {
  670. max[pos++]='0';
  671. }
  672. max[pos]='\0';
  673. pos=0;
  674. array[count]+=char_to_int(max);
  675. count++;
  676. }
  677. }
  678. ind_pos++;
  679. pthread_t tid_2;
  680. pthread_create(&tid_2, NULL, myThreadFun, (void*)1);
  681. }
  682. }
  683. void view_stock(cmp_data*Data,int current,int page,user_details *file)
  684. {
  685. char x;
  686. int EPS,PE,Dividend,choice=0,loop=1;
  687. EPS=calcu_eps(Data[current].market,Data[current].volume);
  688. PE=calcu_pe(Data[current].start_price,EPS);
  689. Dividend=calcu_Div(Data[current].start_price);
  690. while(loop)
  691. {
  692. system("cls");
  693. system("color 04");
  694. updating_point();
  695. printf("\n\n");
  696. printf(space"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<View Stock>>>>>>>>>>>>>>>>>>>>>\n\n");
  697. printf(space"<<<<<<<<<<<<<<<<<<<<<<<<Company Details>>>>>>>>>>>>>>>>>>>>\n");
  698. printf(space"\t\t\t\t\tFundamentals Analysis\n");
  699. printf(space"Name:%s \t\t\t\t",Data[current].name);
  700. printf(space"EPS:%d\n",EPS);
  701. printf(space"No.of.Shares:%s \t\t\t",Data[current].volume);
  702. printf(space"PE :%d\n",PE);
  703. printf(space"Starting price:%s\t\t\t",Data[current].start_price);
  704. printf(space"Dividend:%d\n",Dividend);
  705. printf(space"Market Capital:%s\n",Data[current].market);
  706. printf(space"Current Price:%d\n",array[(5*page)+current]);
  707. printf(space"\n\n\n"space);
  708. arrow_fun(0,choice);
  709. printf("View current graph\n"space);
  710. arrow_fun(1,choice);
  711. printf("Buy Option\n");
  712. arrow_fun(2,choice);
  713. printf("Go back\n");
  714. x= _getch();
  715. switch(x)
  716. {
  717. case 'H':
  718. choice--;
  719. break;
  720. case 'P':
  721. choice++;
  722. break;
  723. case 13:
  724. if(choice==2)
  725. loop=0;
  726. else if(choice==0)
  727. {
  728. graph_section(Data[current].name,Data[current].volume,Data[current].start_price,page,current);
  729. }
  730. else if(choice==1)
  731. {
  732. buy_section((page*5)+current,file);
  733. }
  734. }
  735. if(choice<0 ||choice>2)
  736. {
  737. choice=2;
  738. }
  739. }
  740. }
  741. void buy_section(int cmp_num,user_details*file)
  742. {
  743.  
  744. int flag=0;
  745. system("cls");
  746. set_up:
  747. if(flag==0)
  748. {
  749. FILE *fp;
  750. fp=fopen("COMPANY_DATA.txt","r");
  751. char data[1000],x;
  752. int idx=0,pos=0,cur_pos=0,last_pos=0;
  753. while((x = fgetc(fp)) != EOF)
  754. {
  755. data[idx++] = x;
  756. }
  757. data[idx]='\0';
  758. fclose(fp);
  759. idx=0;
  760. while(pos<cmp_num && data[idx]!='\0')
  761. {
  762. if(data[idx]=='$')
  763. {
  764. pos++;
  765. }
  766. idx++;
  767. }
  768. pos=0;
  769. cur_pos=idx;
  770. char temp_data[100],cmp_name[100],shares[100];
  771. idx++;
  772. while(data[idx]!='$')
  773. {
  774. temp_data[pos]=data[idx++];
  775. pos++;
  776. }
  777. last_pos=idx;
  778. temp_data[pos]='\0';
  779. idx=pos=0;
  780. while(temp_data[idx]!='#')
  781. {
  782. cmp_name[idx]=temp_data[idx];
  783. idx++;
  784. }
  785. cmp_name[idx++]='\0';
  786. char str_pric[100];
  787. while(temp_data[idx]!='#')
  788. {
  789. str_pric[pos++]=temp_data[idx++];
  790. }
  791. str_pric[pos]='\0';
  792. pos=0;
  793. idx++;
  794. while(temp_data[idx]!='\0')
  795. {
  796. shares[pos]=temp_data[idx++];
  797. pos++;
  798. }
  799. shares[pos]='\0';
  800. account_details *sec;
  801. char quantity[100];
  802. sec=file->account;
  803. system("cls");
  804. printf(space "<<<<<<<<<<<<<<<<<<<Buy Section>>>>>>>>>>>>>>>>>>>\n\n");
  805. printf(space "Compaany Name:%s\n",cmp_name);
  806. printf(space "Company Shares:%s\n",shares);
  807. printf(space "Current Price:%d\n",array[cmp_num]);
  808. printf(space "Available Funds :%d\n",sec->available_cash);
  809. printf(space "Buy Quantity:");
  810. scanf("%s",quantity);
  811. if(check_quantity(quantity)==0)
  812. {
  813. flag++;
  814. goto set_up;
  815. }
  816. if(check_quantity_available(quantity,shares)==0)
  817. {
  818. flag++;
  819. goto set_up;
  820. }
  821. if(check_funds(quantity,cmp_num,sec->available_cash)==0)
  822. {
  823. flag++;
  824. goto set_up;
  825. }
  826. char *s;
  827. int len=0;
  828. while(len!=25)
  829. {
  830. time_t t;
  831. time(&t);
  832. s=ctime(&t);
  833. len=strlen(s);
  834. }
  835. record *set=(record*)malloc(1*sizeof(record));
  836. set->buy_price=array[cmp_num];
  837. strcpy(set->cmp_name,cmp_name);
  838. set->no_of_share=char_to_int(quantity);
  839. strcpy(set->volume,shares);
  840. set->cash=char_to_int(quantity)*array[cmp_num];
  841. set->next=NULL;
  842. set->pos=cmp_num;
  843. strcpy(set->buy_time,s);
  844. if(file->portfolio==NULL)
  845. {
  846. file->portfolio=malloc(sizeof(record));
  847. file->portfolio=set;
  848. printf(space"first\n");
  849. }
  850. else
  851. {
  852. record *list=(record*)file->portfolio;
  853. while(list->next!=NULL)
  854. {
  855. list=list->next;
  856. }
  857. list->next=set;
  858. printf(space "Inserted\n");
  859. }
  860. updating_funds(file,cmp_num,char_to_int(quantity));
  861. flag=1;
  862. idx=0;
  863. printf(space"Current cash %d\n",sec->available_cash);
  864. fp=fopen("Company_data.txt","w");
  865. while(idx<cur_pos)
  866. {
  867. x=data[idx];
  868. fputc(x,fp);
  869. idx++;
  870. }
  871. idx=0;
  872. fputc('|',fp);
  873. while(cmp_name[idx]!='\0')
  874. {
  875. x=cmp_name[idx++];
  876. fputc(x,fp);
  877. }
  878. idx=0;
  879. fputc('#',fp);
  880. while(str_pric[idx]!='\0')
  881. {
  882. x=str_pric[idx++];
  883. fputc(x,fp);
  884. }
  885. idx=0;
  886. fputc('#',fp);
  887. char *new_quantity=int_char(char_to_int(shares)-char_to_int(quantity));
  888. while(new_quantity[idx]!='\0')
  889. {
  890. x=new_quantity[idx++];
  891. fputc(x,fp);
  892. }
  893. idx=last_pos;
  894. while(data[idx]!='\0')
  895. {
  896. x=data[idx++];
  897. fputc(x,fp);
  898. }
  899. fclose(fp);
  900. printf(space "Your Order is Succesfully Placed\n");
  901. _getch();
  902. }
  903. else
  904. {
  905. printf(space"Press any Key\n");
  906. _getch();
  907. }
  908. }
  909. int check_quantity_available(char *requested,char *available)
  910. {
  911. if(char_to_int(requested)<=char_to_int(available))
  912. return 1;
  913. else
  914. {
  915. printf(space "Requested quantity Not available\n");
  916. return 0;
  917. }
  918. }
  919. void updating_funds(user_details*file,int cmp_num,int shares)
  920. {
  921. account_details*sec=file->account;
  922. long long int cur=sec->available_cash;
  923. cur=cur-(array[cmp_num]*shares);
  924. sec->available_cash=cur;
  925. }
  926. int check_funds(char *quantity,int number,long long int cash)
  927. {
  928. long long int shares=char_to_int(quantity);
  929. if((shares*array[number])<cash)
  930. return 1;
  931. else
  932. return 0;
  933. }
  934. int check_quantity(char *quantity)
  935. {
  936. int idx=0;
  937. while(quantity[idx]!='\0')
  938. {
  939. if(quantity[idx]>47 && quantity[idx]<58)
  940. {
  941. idx++;
  942. }
  943. else
  944. {
  945. printf(space "Enter only Numbers\n");
  946. return 0;
  947. }
  948. }
  949. return 1;
  950. }
  951. int* whole_data(int st_price,int page,int CURRENT,int *length)
  952. {
  953. FILE *fp;
  954. char x='k',Data[10000],max_array[3];
  955. fp=fopen("Prices_list.txt","a+");
  956. int pos=0,index=0,new_arr[1000],price=0,var=(5*page)+CURRENT,value=0;
  957. while(value<ind_pos)
  958. {
  959. index=0;
  960. while(x!='$')
  961. {
  962. x=fgetc(fp);
  963. Data[index]=x;
  964. index++;
  965. }
  966. Data[index]='\0';
  967. int cur=0,low=0;
  968. while(cur!=var && low<index)
  969. {
  970. if(Data[low]=='#')
  971. {
  972. cur++;
  973. }
  974. low++;
  975. }
  976. cur=0;
  977. while(Data[low]!='#')
  978. {
  979. max_array[cur++]=Data[low];
  980. low++;
  981. }
  982. max_array[cur]='\0';
  983. int v;
  984. v=char_to_int(max_array);
  985. new_arr[value]=v;
  986. value++;
  987. pos++;
  988. x='k';
  989. }
  990. int *r=&value;
  991. *length=*r;
  992. return new_arr;
  993. }
  994. void graph_section(char *name,char* shares,char* st_price,int page,int CURRENT)
  995. {
  996. system("cls");
  997. int len,*data;
  998. data=whole_data(char_to_int(st_price),page,CURRENT,&len);
  999. int gd = DETECT,gm;
  1000. initgraph(&gd, &gm, "C:\\TC\\BGI");
  1001. setcolor(YELLOW);
  1002. settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
  1003. setcolor(WHITE);
  1004. outtextxy(275,0,"Graph Section");
  1005. outtextxy(50,20,"Name :");
  1006. outtextxy(120,20,name);
  1007. outtextxy(50,40,"Shares :");
  1008. outtextxy(120,40,shares);
  1009. outtextxy(450,40,"Cur_price :");
  1010. outtextxy(545,40,int_char(array[(5*page)+CURRENT]));
  1011. line(0,60,639,60);
  1012. if(len==0)
  1013. {
  1014. outtextxy(10,430-char_to_int(st_price),st_price);
  1015. line(10,430,10,430-char_to_int(st_price));
  1016. }
  1017. else
  1018. {
  1019. fun_graph(data,len,char_to_int(st_price));
  1020. }
  1021. line(0,430,639,430);
  1022. outtextxy(150,440,"Press any Key");
  1023. _getch();
  1024. closegraph();
  1025. }
  1026. void fun_graph(int *data,int len,int st_price)
  1027. {
  1028. graph_coordinates(data,len,st_price);
  1029. int add=0;
  1030. if(len<2)
  1031. {
  1032. add=2;
  1033. }
  1034. int dist =600/(len+add);
  1035. int idx=0,range=len+1;
  1036. char *str=int_char(st_price);
  1037. int x1=10,x2=10,y1=430,y2=430-st_price;
  1038. while(idx<range)
  1039. {
  1040. outtextxy(x2,y2,str);
  1041. line(x1,y1,x2,y2);
  1042. x1=x2;
  1043. y1=y2;
  1044. x2=x2+dist;
  1045. y2=430-data[idx]-10;
  1046. str=int_char(data[idx]);
  1047. idx++;
  1048. }
  1049. }
  1050. void graph_coordinates(int *prev_data,int len,int st_price)
  1051. {
  1052. int idx,cur=st_price;
  1053. int *data=(int*)malloc(len*sizeof(int));
  1054. for(idx=0; idx<len; idx++)
  1055. {
  1056. data[idx]=prev_data[idx];
  1057. cur+=data[idx];
  1058. data[idx]=cur;
  1059. if(data[idx]<0)
  1060. {
  1061. data[idx]=0;
  1062. cur=0;
  1063. }
  1064. }
  1065. cur=0;
  1066. int pos=0,diff=0;
  1067. for(idx=0; idx<len; idx++)
  1068. {
  1069. if(data[idx]>360)
  1070. {
  1071. cur=data[idx]-360+2;
  1072. pos=idx;
  1073. data[idx]-=cur;
  1074. while(pos--)
  1075. {
  1076. diff=data[pos+1]-data[pos];
  1077. if(diff>=cur)
  1078. {
  1079. pos=0;
  1080. }
  1081. else
  1082. {
  1083. data[pos]-=cur;
  1084. }
  1085. }
  1086. }
  1087. }
  1088. for(idx=0; idx<len; idx++)
  1089. {
  1090. prev_data[idx]=data[idx];
  1091. }
  1092. }
  1093. void printf_sec(char *data)
  1094. {
  1095. int len=strlen(data);
  1096. printf("%s",data);
  1097. if(len<12)
  1098. {
  1099. while(len<12)
  1100. {
  1101. printf(" ");
  1102. len++;
  1103. }
  1104. }
  1105. }
  1106. void printf_name(char *name)
  1107. {
  1108. int len=strlen(name);
  1109. printf("%s",name);
  1110. if(len<25)
  1111. {
  1112. while(len<25)
  1113. {
  1114. printf(" ");
  1115. len++;
  1116. }
  1117. }
  1118. }
  1119. void my_Account(char *Name,user_details *file)
  1120. {
  1121. system("cls");
  1122. printf("\n\n\n\n");
  1123. printf(space"<<<<<<<<<<<<<<<<<<My Account>>>>>>>>>>>>>>>>>>>\n\n");
  1124. status();
  1125. }
  1126. void trans_sec(char *Name,user_details* file)
  1127. {
  1128. system("cls");
  1129. printf("\n\n\n\n");
  1130. printf(space"<<<<<<<<<<<<<<<<<<Transaction Histroy>>>>>>>>>>>>>>>>>>>\n\n");
  1131. status();
  1132. }
  1133. void user_choice(int choice,char *Name,user_details* file)
  1134. {
  1135. if(choice==1)
  1136. Help_sec(Name);
  1137. else if(choice==2)
  1138. portfolio(Name,file);
  1139. else if(choice==3)
  1140. watch_list(Name,file);
  1141. else if(choice==4)
  1142. stock_list(Name,file);
  1143. else if(choice==5)
  1144. my_Account(Name,file);
  1145. else if(choice==6)
  1146. trans_sec(Name,file);
  1147. }
  1148. void arrow_fun(int exp,int act)
  1149. {
  1150.  
  1151. if(exp==act)
  1152. printf(space"->");
  1153. else
  1154. printf(space" ");
  1155. }
  1156. void welcome_page(char *username)
  1157. {
  1158. system("color f9");
  1159. system("cls");
  1160. printf("\n\n\n\n\n\n");
  1161. printf(space"<<<<<<<<<<<<<<<<<<<<<Welcome Page>>>>>>>>>>>>>>>>>>>>>>\n\n");
  1162. printf(space "Welcome to HELIX %s\n",username);
  1163. printf("\n");
  1164. printf(space "If you are new to HELIX \n");
  1165. printf(space" Go to the Help Section First\n");
  1166. printf(space"Other's wise carry on\n");
  1167. printf(space"Press any key\n");
  1168. _getch();
  1169. system("cls");
  1170. }
  1171. int Main_page()
  1172. {
  1173. FILE *fp;
  1174. char choice,x;
  1175. char users[100];
  1176. char username[100];
  1177. char password[100];
  1178. int i=0;
  1179. main_sec:
  1180. while(1)
  1181. {
  1182. fflush(stdin);
  1183. system("cls");
  1184. printf("\n\n\n\n\n");
  1185. printf(space "Helix\n");
  1186. printf(space"1)login\n");
  1187. printf(space"2)signup\n");
  1188. printf(space"3)exit\n");
  1189. printf(space"Enter Your choice\n");
  1190. printf(space);
  1191. choice=_getch();
  1192. if(choice== 49 || choice ==50 ||choice==51)
  1193. break;
  1194. else
  1195. {
  1196. printf("\n"space"Enter valid choice\n");
  1197. printf(space"press any key\n");
  1198. _getch();
  1199. system("cls");
  1200. }
  1201. }
  1202. if(choice==49)
  1203. {
  1204. login_page();
  1205. goto main_sec;
  1206. }
  1207. if(choice ==50)
  1208. {
  1209. signup_page();
  1210. goto main_sec;
  1211. }
  1212. if(choice==51)
  1213. {
  1214. system("cls");
  1215. printf(space"Exit\n\n");
  1216. printf(space"Are You Sure Want to Exit\n");
  1217. printf(space"Enter y/n\n");
  1218. x=_getch();
  1219. if(x=='n'||x=='N')
  1220. goto main_sec;
  1221. else
  1222. {
  1223. printf("\n"space"Thank u for visiting\n");
  1224. }
  1225. }
  1226. }
  1227. void signup_page()
  1228. {
  1229. FILE *fp;
  1230. int i;
  1231. char x,username[100],password[100];
  1232. system("cls");
  1233. printf("\n\n\n\n\n");
  1234. printf(space "\t<<<<<<<<<<<<<<<<<<<Signup>>>>>>>>>>>>>>>>\n\n");
  1235.  
  1236. printf("\n\n\n"space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 218, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 191);
  1237. printf("\n"space "\t\tUsername : %c %c\n",179,179);
  1238. printf(""space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 192, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 217);
  1239. gotoxy(52,11);
  1240. scanf("%s",username);
  1241. i=0;
  1242. while((x = username[i]) != '\0')
  1243. {
  1244. if(x == '|' || x == '#' || x == '$')
  1245. {
  1246. printf("\n*Username must not contain special characters like |, #, $ etc.");
  1247. _getch();
  1248. goto signup_end;
  1249. }
  1250. i++;
  1251. }
  1252. char accountsDB[100];
  1253. fp = fopen("PROJECT_DATA_FILE.txt","r");
  1254. i = 0;
  1255. while((x = fgetc(fp)) != EOF)
  1256. {
  1257. accountsDB[i++] = x;
  1258. }
  1259. fclose(fp);
  1260. char temp_pass[100];
  1261. if(NULL == strstr(accountsDB, username))
  1262. {
  1263. i=0;
  1264. printf("\n"space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 218, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 191);
  1265. printf("\n"space "\t\tPassword : %c %c\n",179,179);
  1266. printf(""space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 192, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 217);
  1267. gotoxy(52,14);
  1268. while ((x = _getch()) != '\r')
  1269. {
  1270. printf("*");
  1271. password[i++] = x;
  1272. }
  1273. password[i] = '\0';
  1274. printf("\n"space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 218, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 191);
  1275. printf("\n"space "\t\tPassword : %c %c\n",179,179);
  1276. printf(""space space" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 192, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 217);
  1277. gotoxy(52,16);
  1278. i = 0;
  1279. while((x = _getch()) != '\r')
  1280. {
  1281. printf("*");
  1282. temp_pass[i++] = x;
  1283. }
  1284. temp_pass[i]='\0';
  1285. if(strcmp(temp_pass,password)==0)
  1286. {
  1287. i = 0;
  1288. fp = fopen("PROJECT_DATA_FILE.txt","a");
  1289. fputc('|',fp);
  1290. while((x = username[i]) != '\0')
  1291. {
  1292. fputc(x,fp);
  1293. i++;
  1294. }
  1295. i = 0;
  1296. while((x = password[i]) != '\0')
  1297. {
  1298. fputc(x,fp);
  1299. i++;
  1300. }
  1301. fputc('$', fp);
  1302. fputc('1', fp);
  1303. fputc('#', fp);
  1304. fputc('1', fp);
  1305. fclose(fp);
  1306. printf("\n\n"space space "Sign up successful\n");
  1307. goto signup_end;
  1308. }
  1309. else
  1310. {
  1311. printf("\n\n"space space"*Passwords do not match, try again\n");
  1312. goto signup_end;
  1313. }
  1314. }
  1315. else
  1316. {
  1317. printf(space "\n"space"*Username is already taken\n");
  1318. signup_end:
  1319. printf(space "press any key\n");
  1320. _getch();
  1321. }
  1322. }
  1323. int char_to_int(char*num)
  1324. {
  1325. int length=strlen(num);
  1326. int i,temp,var=1;
  1327. long long int c=0;
  1328. for(i=0; i<length; i++)
  1329. {
  1330. if(i==0 && num[i]==45 )
  1331. {
  1332. var=-1;
  1333. }
  1334. else
  1335. {
  1336. temp=(num[i]-48);
  1337. c=c*10+temp;
  1338. }
  1339. }
  1340. c=c*var;
  1341. return c;
  1342. }
  1343. char *int_char(int src)
  1344. {
  1345. char r,*string=(char*)malloc(100*sizeof(char));
  1346. int n=src,j=0,temp=0;
  1347. if(src<0)
  1348. {
  1349. n=n*-1;
  1350. temp=1;
  1351. }
  1352. if(n==0)
  1353. {
  1354. string[j++]='0';
  1355. }
  1356. while(n!=0)
  1357. {
  1358. r=n%10;
  1359. string[j++]=(r+48);
  1360. n/=10;
  1361. }
  1362. if(temp==1)
  1363. {
  1364. string[j++]=45;
  1365. }
  1366. string[j]='\0';
  1367. strrev(string);
  1368. return string;
  1369. }
Add Comment
Please, Sign In to add comment