Guest User

graph

a guest
May 1st, 2018
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 54.22 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. char st_price[100];
  41. int selling_price;
  42. int percentage;//profit or loss gain
  43. char buy_time[40];
  44. char sell_time[40];
  45. char market[100];
  46. int pos;
  47. int active;
  48. char order_shares[100];
  49. int sell_cash;//recieved from shares
  50. int buy_cash;//given for shares;
  51. struct record*next;//next pointer to create new record;
  52. } record;
  53. typedef struct database
  54. {
  55. user_details* data;
  56. char name[100];
  57. struct database*next;
  58. } database;
  59. void *storage;
  60. int array[20]= {0};
  61. void graph(int value);
  62. int calculating_stock_value(user_details*file);
  63. void check_null();
  64. void printf_date(char*source);
  65. void insert_record_1(user_details*file,record *r1);
  66. void remove_record(user_details*file,int cur_pos);
  67. void insert_record(user_details*file,record *r1,record *r2);
  68. void sell_section(user_details*file,int cur_pos);
  69. void status();
  70. char *calculating_time();
  71. int check_quantity_available(char *requested,char *available);
  72. void updating_funds(user_details*file,int cmp_num,int shares);
  73. int check_funds(char *quantity,int number,long long int cash);
  74. int check_quantity(char *quantity);
  75. void buy_section(int cmp_num,user_details* file);
  76. void updating_point();
  77. void signup_page();
  78. void storing_data(user_details*cur_file);
  79. char *percent_int_char(int src);
  80. int* whole_data(int st_price,int page,int *length);
  81. void fun_graph(int *data,int len,int st_price);
  82. void graph_coordinates(int *prev_data,int len,int st_price);
  83. void view_stock(cmp_data*Data,user_details*file,int pos);
  84. void graph_section(char *name,char* shares,char* st_price,int page,int current);
  85. void *myThreadFun(void *id);
  86. char *int_char(int src);
  87. void login_page();
  88. void adding_to_watch_list(cmp_data*Data,int pos,user_details*file);
  89. void trans_sec(user_details*file);
  90. int char_to_int(char*num);
  91. void user_choice(int choice,user_details *file);
  92. void userpage(char *username);
  93. void welcome_page(char *username);
  94. int Main_page();
  95. void insert_into_record(cmp_data*collect,char *Data,int pos);
  96. void arrow_fun(int exp,int act);
  97. void printf_sec(char *data);
  98. void printf_name(char *name);
  99. int calcu_eps(char* capital,char* shares);
  100. int calcu_pe(char*price,int eps);
  101. int calcu_Div(char* price);
  102. COORD coord= {0,0};
  103. void gotoxy(int x,int y)
  104. {
  105. coord.X=x;
  106. coord.Y=y;
  107. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
  108. }
  109. user_details* create_user_info(char *username)
  110. {
  111. user_details *rcd=(user_details*)malloc(1*sizeof(user_details));
  112. strcpy(rcd->username,username);
  113. account_details *poin=(account_details*)malloc(1*sizeof(account_details));
  114. strcpy(poin->name,username);
  115. poin->investement=500000;
  116. poin->available_cash=500000;
  117. poin->stock_value=0;
  118. poin->total_transaction=0;
  119. rcd->account=poin;
  120. rcd->portfolio=NULL;
  121. rcd->trans_his=NULL;
  122. rcd->watch_list=NULL;
  123. return rcd;
  124. }
  125. user_details* checking_user_details(char *username)
  126. {
  127. if(storage==NULL)
  128. {
  129. storage=malloc(sizeof(database));
  130. storage=(database*)malloc(sizeof(database));
  131. database*cur=(database*)storage;
  132. cur->next=NULL;
  133. strcpy(cur->name,username);
  134. cur->data=create_user_info(username);
  135. return cur->data;
  136. }
  137. database*temp=(database*)storage;
  138. while(temp!=NULL && (strcmp(temp->name,username)!=0))
  139. {
  140. temp=temp->next;
  141. }
  142. if(temp!=NULL)
  143. return temp->data;
  144. else
  145. {
  146. temp=(database*)storage;
  147. while(temp->next!=NULL)
  148. {
  149. temp=temp->next;
  150. }
  151. database*cur_1=(database*)malloc(sizeof(database));
  152. cur_1->next=NULL;
  153. strcpy(cur_1->name,username);
  154. cur_1->data=create_user_info(username);
  155. temp->next=cur_1;
  156. return cur_1->data;
  157. }
  158. }
  159. void *myThreadFun(void *id)
  160. {
  161. FILE * fp_3=fopen("Prices_list.txt","a+");
  162. char *str;
  163. time_t t;
  164. int random_1,idx,count=20;
  165. random_1 =idx=0;
  166. while(count--)
  167. {
  168. srand((unsigned) time(&t));
  169. random_1=rand()%10;
  170. Sleep(1000);
  171. if(random_1 == count)
  172. {
  173. if(random_1%2==0)
  174. str=int_char(random_1*2);
  175. else
  176. str=int_char(random_1*2*-1);
  177. }
  178. else
  179. {
  180. if(random_1%2!=0)
  181. str=int_char(random_1);
  182. else
  183. str=int_char(random_1*-1);
  184. }
  185. while(str[idx]!='\0')
  186. {
  187. fputc(str[idx],fp_3);
  188. idx++;
  189. }
  190. if(idx==0)
  191. {
  192. fputc('0',fp_3);
  193. }
  194. fputc('#',fp_3);
  195. idx=0;
  196. }
  197. fputc('$',fp_3);
  198. up_price++;
  199. fclose(fp_3);
  200. }
  201. int main()
  202. {
  203. printf("\n\n\n\n\n");
  204. printf(space "\tWELCOME\n");
  205. printf(space "\t TO \n");
  206. printf(space "\t HELIX \n");
  207. printf(space"\tPress any Key\n");
  208. _getch();
  209. pthread_t t;
  210. pthread_create(&t, NULL, myThreadFun, (void*)1);
  211. Main_page();
  212. return 0;
  213. }
  214. void login_page()
  215. {
  216. FILE *fp;
  217. updating_point();
  218. char x,*tempstr;
  219. char accountsDB[100],username[100],password[100],users[100];
  220. system("cls");
  221. printf("\n\n\n\n");
  222. printf(space space "<<<<<<<<<<<<<<Login>>>>>>>>>>>> \n\n");
  223. 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);
  224. printf("\n"space "\t\tUsername : %c %c\n",179,179);
  225. 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);
  226. gotoxy(52,10);
  227. scanf("%s",username);
  228. printf("\n");
  229. int idx=0;
  230. while(username[idx] != '\0')
  231. {
  232. users[idx] = username[idx];
  233. idx++;
  234. }
  235. users[idx] = '\0';
  236. idx=0;
  237. 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);
  238. printf("\n"space "\t\tPassword : %c %c\n",179,179);
  239. 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);
  240. gotoxy(52,16);
  241. while ((x = _getch()) != '\r')
  242. {
  243. printf("*");
  244. password[idx++] = x;
  245. }
  246. password[idx] = '\0';
  247. idx = 0;
  248. strcat(username, password);
  249. fp = fopen("PROJECT_DATA_FILE.txt","r");
  250. while((x = fgetc(fp)) != EOF)
  251. {
  252. accountsDB[idx++] = x;
  253. }
  254. accountsDB[idx] = '\0';
  255. fclose(fp);
  256. if(NULL == strstr(accountsDB, username))
  257. {
  258. printf("\n\n"space"*Username or password is wrong\n");
  259. goto end_login;
  260. }
  261. else
  262. {
  263. tempstr = strstr(accountsDB, username);
  264. }
  265. idx=0;
  266. while(username[idx]!='\0')
  267. {
  268. if(username[idx]!=tempstr[idx])
  269. break;
  270. idx++;
  271. }
  272. if(idx==strlen(username))
  273. {
  274. userpage(users);
  275. goto end_login;
  276. }
  277. else
  278. {
  279. printf("\n\n"space"*Username or password is wrong\n");
  280. end_login:
  281. printf(space "\n"space"press any key\n");
  282. _getch();
  283. }
  284. }
  285. void userpage(char *username)
  286. {
  287. welcome_page(username);
  288. user_details *file=checking_user_details(username);
  289. int select=1,loop=1;
  290. user_sec:
  291. system("color 03");
  292. while(loop)
  293. {
  294. updating_point();
  295. if(select>7 ||select==0)
  296. {
  297. select =1;
  298. }
  299. system("cls");
  300. printf("\n\n\n\n");
  301. printf(space "<<<HELIX GUIDE>>>\n");
  302. arrow_fun(1,select);
  303. printf("HELP\n");
  304. arrow_fun(2,select);
  305. printf("PORTFOLIO\n");
  306. arrow_fun(3,select);
  307. printf("WATCH LIST\n");
  308. arrow_fun(4,select);
  309. printf("STOCK LIST\n");
  310. arrow_fun(5,select);
  311. printf("ACCOUNT\n");
  312. arrow_fun(6,select);
  313. printf("TRANSACTION HISTROY\n");
  314. arrow_fun(7,select);
  315. printf("EXIT\n");
  316. printf(space"Use the Arrow key's to move and select\n");
  317. switch(_getch())
  318. {
  319. case 'H':
  320. select--;
  321. break;
  322. case 'P':
  323. select++;
  324. break;
  325. case 13:
  326. if(select!=7)
  327. {
  328. user_choice(select,file);
  329. }
  330. else
  331. {
  332. storing_data(file);
  333. loop=0;
  334. }
  335. break;
  336. }
  337. }
  338. }
  339. void storing_data(user_details*file)
  340. {
  341. database*cur=(database*)storage;
  342. while(cur!=NULL)
  343. {
  344. cur=cur->next;
  345. }
  346. _getch();
  347. cur=(database*)storage;
  348. while(strcmp(cur->name,file->username)!=0)
  349. {
  350. cur=cur->next;
  351. }
  352. cur->data=file;
  353. FILE *fp;
  354. fp=fopen("Prices_list.txt","w");
  355. fclose(fp);
  356. }
  357. void Help_sec(char *Name)
  358. {
  359. printf("\n");
  360. system("cls");
  361. updating_point();
  362. printf(space"<<<<<<<<<<<<<<<<Help_sec>>>>>>>>>>>>>>>>>>>>>>\n\n");
  363. printf("->Helix is an virtual Trading app\n");
  364. printf("->Which is based on Equity share's\n");
  365. printf(" <<<<Company Details>>>>>\n");
  366. printf("->Company Name=XYZ\n");
  367. printf("->Volume=No of shares available\n");
  368. printf("->Starting price=Starting price of each share\n");
  369. printf("->Market Capital=Total turn over capital of the company\n");
  370. printf(" <<<<<Fundamental Details>>>>>>\n");
  371. printf("->EPS=Earning per share\n");
  372. printf("->It is used to determine company stock Condition\n");
  373. printf("->Its supply and Demand in the market\n");
  374. printf("->if eps<=26 then its is consider at under value share\n");
  375. printf("->if eps >26 then it is consider at over value share\n");
  376. printf("->PE ratio=Price Earnings\n");
  377. printf("->It is used to determine company financial condition\n");
  378. printf("->If its below 14 it is consider as good\n");
  379. printf("->Dividend=Payed by the comapny\n");
  380. printf("->To those who hold there company share for long term \n");
  381. printf("->Min range =1 year to max=unlimited as long the company exists in the market\n");
  382. printf("->Graph section \n");
  383. printf("->It is used to show the company Finanial condition\n");
  384. printf("->Its previous performance ,also used to calculate the technical analysis\n");
  385. printf(space"Press any key\n");
  386. _getch();
  387. }
  388. void portfolio(user_details *file)
  389. {
  390. system("cls");
  391. printf("\n\n\n");
  392. printf(space"<<<<<<<<<<<<<<<<<<portfolio>>>>>>>>>>>>>>>>>>>\n\n");
  393. if(file->portfolio==NULL)
  394. {
  395. printf(space " COMPANY_NAME || Shares || Cur_price || Buy_priced \n\n" );
  396. printf(space " NULL || NULL || NULL || NULL \n");
  397. }
  398. else
  399. {
  400. char x='0';
  401. int loop=1,arrow=0,total=1,time=0;
  402. while(loop)
  403. {
  404. system("cls");
  405. updating_point();
  406. printf(space " COMPANY_NAME || Shares || Cur_price || Buy_priced \n\n" );
  407. record *cur=(record*)file->portfolio;
  408. while(cur!=NULL)
  409. {
  410. arrow_fun(time,arrow);
  411. printf_name(cur->cmp_name);
  412. printf_sec(int_char(cur->no_of_share));
  413. printf(" %d ",array[cur->pos]);
  414. printf_sec(int_char(cur->buy_price));
  415. printf("\n");
  416. cur=cur->next;
  417. time++;
  418. }
  419. total=time;
  420. time=0;
  421. arrow_fun(total,arrow);
  422. printf("Go back\n");
  423. printf(space"Use the arrow keys");
  424. printf("Press Enter for selling\n");
  425. x=_getch();
  426. switch(x)
  427. {
  428. case 'H':
  429. arrow--;
  430. break;
  431. case 'P':
  432. arrow++;
  433. break;
  434. case 13:
  435. if(arrow==total)
  436. loop=0;
  437. else
  438. {
  439. cur=(record*)file->portfolio;
  440. while(cur!=NULL && arrow!=0)
  441. {
  442. cur=cur->next;
  443. arrow--;
  444. }
  445. sell_section(file,cur->pos);
  446. loop=0;
  447. }
  448. break;
  449. }
  450. if(arrow<0 ||arrow>total)
  451. {
  452. arrow=0;
  453. }
  454. }
  455. }
  456. printf(space "Press any key\n");
  457. _getch();
  458. }
  459. void sell_section(user_details*file,int cur_pos)
  460. {
  461. system("cls");
  462. record*set=(record*)file->portfolio;
  463. while(set->pos!=cur_pos)
  464. {
  465. set=set->next;
  466. }
  467. char quantity[100];
  468. int idx=0,index=0;
  469. set_up:
  470. if(idx==0)
  471. {
  472. record *r1=(record*)malloc(sizeof(record));
  473. record *r2=(record*)malloc(sizeof(record));
  474. printf(space"<<<<<<<<<<<<<<<<<Sell option>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n");
  475. printf(space"COMPANY NAME:%s\n",set->cmp_name);
  476. printf(space"Shares:%s\n",int_char(set->no_of_share));
  477. printf(space"Cur_price:%d\n",array[set->pos]);
  478. printf(space"Enter the sell quantity :");
  479. scanf("%s",quantity);
  480. if(check_quantity(quantity)==0)
  481. {
  482. idx++;
  483. goto set_up;
  484. }
  485. if(check_quantity_available(quantity,int_char(set->no_of_share))==0)
  486. {
  487. idx++;
  488. goto set_up;
  489. }
  490. if(set->active==1)
  491. {
  492. memcpy((void*)r1,(void*)set,sizeof(record));
  493. r1->next=NULL;
  494. r1->sell_cash=0;
  495. set->active=0;
  496. memcpy((void*)r2,(void*)set,sizeof(record));
  497. r2->next=NULL;
  498. r2->selling_price=array[r2->pos];
  499. r2->percentage=(r2->selling_price-r2->buy_price)*r2->no_of_share;
  500. set->percentage=r2->percentage;
  501. strcpy(r2->sell_time,calculating_time());
  502. r2->sell_cash=char_to_int(quantity)*array[r2->pos];
  503. r2->no_of_share-=char_to_int(quantity);
  504. strcpy(r2->order_shares,quantity);
  505. insert_record(file,r1,r2);
  506. }
  507. else
  508. {
  509. memcpy((void*)r1,(void*)set,sizeof(record));
  510. r1->next=NULL;
  511. r1->selling_price=array[r1->pos];
  512. r1->percentage=(r1->selling_price-r1->buy_price)*r1->no_of_share;
  513. strcpy(r1->sell_time,calculating_time());
  514. r1->sell_cash=char_to_int(quantity)*array[r1->pos];
  515. r1->no_of_share-=char_to_int(quantity);
  516. strcpy(r1->order_shares,quantity);
  517. set->percentage=r1->percentage;
  518. r2->sell_cash=0;
  519. insert_record_1(file,r1);
  520. }
  521. if(set->no_of_share==char_to_int(quantity))
  522. {
  523. remove_record(file,set->pos);
  524. }
  525. else
  526. {
  527. set->no_of_share-=char_to_int(quantity);
  528. }
  529. account_details *acc=file->account;
  530. acc->available_cash=acc->available_cash+r1->sell_cash+r2->sell_cash;
  531. acc->total_transaction++;
  532. printf(space "Your Selling order is succesfull\n");
  533. printf(space "Your account balance is =%d\n",acc->available_cash);
  534. printf(space "profit or loss gained is=%d\n",set->percentage);
  535. FILE *fp;
  536. fp=fopen("COMPANY_DATA.txt","r");
  537. char data[1000],x,org_quantity[100];
  538. while((x = fgetc(fp)) != EOF)
  539. {
  540. data[index++] = x;
  541. }
  542. data[index]='\0';
  543. fclose(fp);
  544. index=0;
  545. int pos=0,start_pos=0,last_pos=0;
  546. while(pos<set->pos && data[index]!='\0')
  547. {
  548. if(data[index]=='$')
  549. {
  550. pos++;
  551. }
  552. index++;
  553. }
  554. pos=0;
  555. while(pos<=1)
  556. {
  557. if(data[index]=='#')
  558. {
  559. pos++;
  560. }
  561. index++;
  562. }
  563. pos=0;
  564. start_pos=index;
  565. while(data[index]!='$')
  566. {
  567. org_quantity[pos]=data[index++];
  568. pos++;
  569. }
  570. last_pos=index;
  571. fp=fopen("COMPANY_DATA.txt","w");
  572. index=0;
  573. while(index<start_pos)
  574. {
  575. x=data[index++];
  576. fputc(x,fp);
  577. }
  578. index=0;
  579. char *s=int_char(char_to_int(org_quantity)+char_to_int(quantity));
  580. while(s[index]!='\0')
  581. {
  582. x=s[index++];
  583. fputc(x,fp);
  584. }
  585. index=last_pos;
  586. while(data[index]!='\0')
  587. {
  588. x=data[index++];
  589. fputc(x,fp);
  590. }
  591. fclose(fp);
  592. }
  593. else
  594. {
  595. printf(space "press any key\n");
  596. _getch();
  597. }
  598. }
  599. void insert_record_1(user_details*file,record*r1)
  600. {
  601. record*cur=(record*)file->trans_his;
  602. while(cur->next!=NULL)
  603. {
  604. cur=cur->next;
  605. }
  606. cur->next=r1;
  607. }
  608. void remove_record(user_details*file,int cur_pos)
  609. {
  610. record *current=(record*)file->portfolio;
  611. record*cur_2=current;
  612. if(current->pos==cur_pos)
  613. {
  614. file->portfolio=current->next;
  615. }
  616. else
  617. {
  618. while(current->pos!=cur_pos)
  619. {
  620. current=current->next;
  621. }
  622. while(cur_2->next!=current)
  623. {
  624. cur_2->next=current->next;
  625. }
  626. }
  627. }
  628. void insert_record(user_details*file,record *r1,record *r2)
  629. {
  630. if(file->trans_his==NULL)
  631. {
  632. file->trans_his=malloc(sizeof(record));
  633. file->trans_his=r1;
  634. r1->next=r2;
  635. }
  636. else
  637. {
  638. record *cur=(record*)file->trans_his;
  639. while(cur->next!=NULL)
  640. {
  641. cur=cur->next;
  642. }
  643. cur->next=r1;
  644. cur=cur->next;
  645. cur->next=r2;
  646. }
  647. }
  648. void status()
  649. {
  650. printf(space"Will be added Soon\n");
  651. printf(space"Press any key\n");
  652. _getch();
  653. }
  654. void watch_list(user_details *file)
  655. {
  656. system("cls");
  657. printf("\n\n\n\n");
  658. printf(space"<<<<<<<<<<<<<<<<<<Watch List>>>>>>>>>>>>>>>>>>>\n\n");
  659. printf("COMPANY NAME || START_PRICE || VOLUME || CUR_PRICE || MARKET CAPITAL\n\n");
  660. if(file->watch_list==NULL)
  661. {
  662. printf(" NULL || NULL || NULL || NULL || NULL ||\n");
  663. printf(space"Press any Key\n");
  664. _getch();
  665. }
  666. else
  667. {
  668. char x='0';
  669. record*cur;
  670. int loop=1,arrow=0,total=0,time=0;
  671. while(loop)
  672. {
  673. fflush(stdin);
  674. updating_point();
  675. cur=(record*)file->watch_list;
  676. system("cls");
  677. printf("COMPANY NAME || START_PRICE || VOLUME || CUR_PRICE || MARKET CAPITAL\n\n");
  678. while(cur!=NULL)
  679. {
  680. arrow_fun(time,arrow);
  681. printf_name(cur->cmp_name);
  682. printf_sec(cur->st_price);
  683. printf_sec(int_char(cur->no_of_share));
  684. printf(" %d ",array[cur->pos]);
  685. printf_sec(cur->market);
  686. printf("\n");
  687. cur=cur->next;
  688. time++;
  689. }
  690. total=time;
  691. time=0;
  692. arrow_fun(total,arrow);
  693. printf(space"Go Back\n");
  694. printf(space"Use the arrow keys \n");
  695. printf(space"Press enter to view the company details\n");
  696. x=_getch();
  697. switch(x)
  698. {
  699. case 'H':
  700. arrow--;
  701. break;
  702. case 'P':
  703. arrow++;
  704. break;
  705. case 13:
  706. if(arrow==total)
  707. {
  708. loop=0;
  709. }
  710. else
  711. {
  712. cmp_data*Data=(cmp_data*)malloc(sizeof(cmp_data));
  713. int var=arrow;
  714. cur=(record*)file->watch_list;
  715. while(var--)
  716. {
  717. cur=cur->next;
  718. }
  719. strcpy(Data->market,cur->market);
  720. strcpy(Data->name,cur->cmp_name);
  721. strcpy(Data->start_price,cur->st_price);
  722. strcpy(Data->volume,int_char(cur->no_of_share));
  723. view_stock(Data,file,cur->pos);
  724. }
  725. break;
  726. }
  727. if(arrow<0 || arrow>total)
  728. {
  729. arrow=total;
  730. }
  731. }
  732. }
  733. }
  734. void inserting_the_data(cmp_data *collect,char*Data,int prev,int cur)
  735. {
  736. int idx=0,position=0;
  737. if(cur==0 && prev!=cur)
  738. {
  739. insert_into_record(collect,Data,cur+1);
  740. }
  741. else if(cur==1 && prev!=cur)
  742. {
  743. position=cur*5;
  744. while(position--)
  745. {
  746. while(Data[idx]!='$')
  747. {
  748. idx++;
  749. }
  750. idx+=2;
  751. }
  752. insert_into_record(collect,Data,idx);
  753. }
  754. else if(cur==2 && prev!=cur)
  755. {
  756. position=10;
  757. while(position--)
  758. {
  759. while(Data[idx]!='$')
  760. {
  761. idx++;
  762. }
  763. idx+=2;
  764. }
  765. insert_into_record(collect,Data,idx);
  766. }
  767. else if(cur==3 && prev!=cur)
  768. {
  769. position=15;
  770. while(position--)
  771. {
  772. while(Data[idx]!='$')
  773. {
  774. idx++;
  775. }
  776. idx+=2;
  777. }
  778. insert_into_record(collect,Data,idx);
  779. }
  780. }
  781. void insert_into_record(cmp_data *collect,char *Data,int pos)
  782. {
  783. int count=5,idx=0,range=0;
  784. char temp[100]= {0};
  785. while(range<count)
  786. {
  787. idx=0;
  788. while(Data[pos]!='#')
  789. {
  790. temp[idx++]=Data[pos];
  791. pos++;
  792. }
  793. temp[idx]='\0';
  794. pos++;
  795. strcpy(collect[range].name,temp);
  796. idx=0;
  797. temp[100]= {0};
  798. while(Data[pos]!='#')
  799. {
  800. temp[idx]=Data[pos++];
  801. idx++;
  802. }
  803. temp[idx]='\0';
  804. strcpy(collect[range].start_price,temp);
  805. idx=0;
  806. temp[100]= {0};
  807. pos++;
  808. while(Data[pos]!='$')
  809. {
  810. temp[idx]=Data[pos++];
  811. idx++;
  812. }
  813. temp[idx]='\0';
  814. pos+=2;
  815. strcpy(collect[range].volume,temp);
  816. temp[100]= {0};
  817. char *str=int_char((char_to_int(collect[range].start_price))*(char_to_int(collect[range].volume))*2);
  818. strcpy(collect[range].market,str);
  819. range++;
  820. }
  821. }
  822. void stock_list(user_details *file)
  823. {
  824. system("cls");
  825. FILE*fp=fopen("COMPANY_DATA.txt","r+");
  826. char x,cmp_details[1000];
  827. cmp_data *page_list =(cmp_data*)malloc(sizeof(cmp_data)*5);
  828. int idx=0,arrow=0;
  829. while((x = fgetc(fp)) != EOF)
  830. {
  831. cmp_details[idx++] = x;
  832. }
  833. cmp_details[idx] = '\0';
  834. int prev_page=4,cur_page=0,loop=1;
  835. while(loop)
  836. {
  837. system("cls");
  838. system("color f3");
  839. updating_point();
  840. inserting_the_data(page_list,cmp_details,prev_page,cur_page);
  841. prev_page=cur_page;
  842. printf("\n\n <<<<<<<<<<<<<<<<<<<<<<<<<<<<Stock List>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
  843. printf(space"Company Name ||Starting || Cur_price || Volume || MARKET \n");
  844. arrow_fun(0,arrow);
  845. printf_name(page_list[0].name);
  846. printf_sec(page_list[0].start_price);
  847. printf("%d ",array[(5*cur_page)+0]);
  848. printf_sec(page_list[0].volume);
  849. printf_sec(page_list[0].market);
  850. printf("\n");
  851. arrow_fun(1,arrow);
  852. printf_name(page_list[1].name);
  853. printf_sec(page_list[1].start_price);
  854. printf("%d ",array[(5*cur_page)+1]);
  855. printf_sec(page_list[1].volume);
  856. printf_sec(page_list[1].market);
  857. printf("\n");
  858. arrow_fun(2,arrow);
  859. printf_name(page_list[2].name);
  860. printf_sec(page_list[2].start_price);
  861. printf("%d ",array[(5*cur_page)+2]);
  862. printf_sec(page_list[2].volume);
  863. printf_sec(page_list[2].market);
  864. printf("\n");
  865. arrow_fun(3,arrow);
  866. printf_name(page_list[3].name);
  867. printf_sec(page_list[3].start_price);
  868. printf("%d ",array[(5*cur_page)+3]);
  869. printf_sec(page_list[3].volume);
  870. printf_sec(page_list[3].market);
  871. printf("\n");
  872. arrow_fun(4,arrow);
  873. printf_name(page_list[4].name);
  874. printf_sec(page_list[4].start_price);
  875. printf("%d ",array[(5*cur_page)+4]);
  876. printf_sec(page_list[4].volume);
  877. printf_sec(page_list[4].market);
  878. printf("\n");
  879. arrow_fun(5,arrow);
  880. printf("BACK\n");
  881. printf(space "use the arrow keys to turn pages and for selecting stock\n");
  882. printf(space "press enter for selecting\n");
  883. printf("\n\n\n"space space"Page:%d\n",cur_page);
  884. x=_getch();
  885. switch(x)
  886. {
  887. case 72:
  888. arrow--;
  889. break;
  890. case 80:
  891. arrow++;
  892. break;
  893. case 75:
  894. cur_page--;
  895. break;
  896. case 77:
  897. cur_page++;
  898. break;
  899. case 13:
  900. if(arrow==5)
  901. loop=0;
  902. else
  903. {
  904. cmp_data* cur=(cmp_data*)malloc(sizeof(cmp_data)*1);
  905. strcpy(cur->name,page_list[arrow].name);
  906. strcpy(cur->market,page_list[arrow].market);
  907. strcpy(cur->start_price,page_list[arrow].start_price);
  908. strcpy(cur->volume,page_list[arrow].volume);
  909. view_stock(cur,file,(cur_page*5)+arrow);
  910. }
  911. }
  912. if(arrow>5 ||arrow<0)
  913. {
  914. arrow=0;
  915. }
  916. if(cur_page>3 ||cur_page<0)
  917. {
  918. cur_page=0;
  919. arrow =0;
  920. }
  921. }
  922. }
  923. int calcu_eps(char* capital,char* shares)
  924. {
  925. int out_stan_shares=char_to_int(shares);
  926. return char_to_int(capital)/out_stan_shares-14;
  927. }
  928. int calcu_pe(char*price,int eps)
  929. {
  930. return eps/char_to_int(price);
  931. }
  932. int calcu_Div(char* price)
  933. {
  934. int dividend_yield=7;
  935. return char_to_int(price)/dividend_yield;
  936. }
  937. void updating_point()
  938. {
  939. char Data[1000],x,max[3];
  940. int i,pos=0,in=0,count=0,idx=0;
  941. FILE *fp1,*fp;
  942. if((fp1=fopen("COMPANY_DATA.txt","r"))==NULL)
  943. {
  944. fp1=fopen("COMPANY_DATA.txt","w");
  945. char data[]="|venkys#40#500000$|satin#30#2500000$|ultratech#45#2000000$|polaris#57#250000$|Aditya vision#60#700000$|Mrf#85#1000000$|page#55#350000$|Ashok leyland#54#100000$|Tata#50#750000$|jio#40#100000$|kakatiya Cement#43#750000$|Coasboard Ind#47#500000$|Electrotham ind#61#210000$|Eichers#77#1000000$|Rana Sugar#53#500000$|Alkai Metals#49#450000$|Amazon#61#8500000$|JustDial#69#7200000$|Adobe#77#900000$|infoys#55#6500000$";
  946. i=0;
  947. while(data[i]!='\0')
  948. {
  949. x=data[i];
  950. fputc(x,fp1);
  951. i++;
  952. }
  953. fclose(fp1);
  954. }
  955. if(ind_pos==0)
  956. {
  957. int new_arr[20]= {40,30,45,57,60,85,55,54,50,40,43,47,61,77,53,49,61,69,77,55};
  958. for(idx=0; idx<20; idx++)
  959. {
  960. array[idx]=new_arr[idx];
  961. }
  962. }
  963. if(ind_pos<up_price)
  964. {
  965. fp=fopen("Prices_list.txt","a+");
  966. idx= pos=in=count =0;
  967. x='k';
  968. while(count<ind_pos)
  969. {
  970. x=fgetc(fp);
  971. if(x=='$')
  972. {
  973. count++;
  974. }
  975. }
  976. count=0;
  977. if(ind_pos!=0)
  978. {
  979. x='k';
  980. }
  981. while(x!='$')
  982. {
  983. x=fgetc(fp);
  984. Data[idx]=x;
  985. idx++;
  986. }
  987. Data[idx]='\0';
  988. while(in<idx)
  989. {
  990. while(Data[in]!='#' && Data[in]!='$')
  991. {
  992. max[pos++]=Data[in];
  993. in++;
  994. }
  995. if(Data[in]=='$')
  996. {
  997. in++;
  998. }
  999. else
  1000. {
  1001. if(pos==0)
  1002. {
  1003. max[pos++]='0';
  1004. }
  1005. max[pos]='\0';
  1006. pos=0;
  1007. array[count]+=char_to_int(max);
  1008. count++;
  1009. }
  1010. in++;
  1011. }
  1012. ind_pos++;
  1013. up_price=ind_pos;
  1014. pthread_t tid_2;
  1015. pthread_create(&tid_2, NULL, myThreadFun, (void*)1);
  1016. }
  1017. check_null();
  1018. }
  1019. void check_null()
  1020. {
  1021. int idx;
  1022. for(idx=0; idx<20; idx++)
  1023. {
  1024. if(array[idx]<0)
  1025. array[idx]=0;
  1026. }
  1027. }
  1028. void view_stock(cmp_data*Data,user_details *file,int pos)
  1029. {
  1030. char x;
  1031. int EPS,PE,Dividend,choice=0,loop=1;
  1032. EPS=calcu_eps(Data->market,Data->volume);
  1033. PE=calcu_pe(Data->start_price,EPS);
  1034. Dividend=calcu_Div(Data->start_price);
  1035. while(loop)
  1036. {
  1037. system("cls");
  1038. updating_point();
  1039. system("color 04");
  1040. printf("\n\n");
  1041. printf(space"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<View Stock>>>>>>>>>>>>>>>>>>>>>\n\n");
  1042. printf(space"<<<<<<<<<<<<<<<<<<<<<<<<Company Details>>>>>>>>>>>>>>>>>>>>\n");
  1043. printf(space"\t\t\t\t\tFundamentals Analysis\n");
  1044. printf(space"Name:%s \t\t\t\t",Data->name);
  1045. printf(space"EPS:%d\n",EPS);
  1046. printf(space"No.of.Shares:%s \t\t\t",Data->volume);
  1047. printf(space"PE :%d\n",PE);
  1048. printf(space"Starting price:%s\t\t\t",Data->start_price);
  1049. printf(space"Dividend:%d\n",Dividend);
  1050. printf(space"Market Capital:%s\n",Data->market);
  1051. printf(space"Current Price:%d\n",array[pos]);
  1052. printf(space"\n\n\n"space);
  1053. arrow_fun(0,choice);
  1054. printf("View current graph\n"space);
  1055. arrow_fun(1,choice);
  1056. printf("Buy Option\n"space);
  1057. arrow_fun(2,choice);
  1058. printf("Add to / Remove from watch list\n\n"space);
  1059. arrow_fun(3,choice);
  1060. printf("Go back\n");
  1061. x= _getch();
  1062. switch(x)
  1063. {
  1064. case 'H':
  1065. choice--;
  1066. break;
  1067. case 'P':
  1068. choice++;
  1069. break;
  1070. case 13:
  1071. if(choice==3)
  1072. loop=0;
  1073. else if(choice==0)
  1074. {
  1075. updating_point();
  1076. graph_section(Data->name,Data->volume,Data->start_price,pos/5,pos%5);
  1077. }
  1078. else if(choice==1)
  1079. {
  1080. updating_point();
  1081. buy_section(pos,file);
  1082. }
  1083. else if(choice==2)
  1084. {
  1085. updating_point();
  1086. adding_to_watch_list(Data,pos,file);
  1087. }
  1088. }
  1089. if(choice<0 ||choice>3)
  1090. {
  1091. choice=3;
  1092. }
  1093. }
  1094. }
  1095. void adding_to_watch_list(cmp_data*Data,int pos,user_details*file)
  1096. {
  1097. int temp=0;
  1098. record *check=(record*)file->watch_list;
  1099. while(check!=NULL)
  1100. {
  1101. if(strcmp(check->cmp_name,Data->name)==0)
  1102. {
  1103. temp=1;
  1104. break;
  1105. }
  1106. check=check->next;
  1107. }
  1108. check=(record*)file->watch_list;
  1109. if(temp==1)
  1110. {
  1111. if(strcmp(check->cmp_name,Data->name)==0)
  1112. {
  1113. file->watch_list=check->next;
  1114. }
  1115. else
  1116. {
  1117. while(strcmp(check->cmp_name,Data->name)!=0)
  1118. {
  1119. check=check->next;
  1120. }
  1121. record*prev=(record*)file->watch_list;
  1122. while(prev->next!=check)
  1123. {
  1124. prev=prev->next;
  1125. }
  1126. if(check->next==NULL)
  1127. {
  1128. prev->next=NULL;
  1129. }
  1130. else
  1131. {
  1132. prev->next=check->next;
  1133. }
  1134. }
  1135. gotoxy(40,11);
  1136. printf(space"Removed from Watch list\n");
  1137. }
  1138. else
  1139. {
  1140. record*rd=(record*)malloc(sizeof(record));
  1141. rd->pos=pos;
  1142. strcpy(rd->cmp_name,Data->name);
  1143. strcpy(rd->market,Data->market);
  1144. rd->no_of_share=char_to_int(Data->volume);
  1145. strcpy(rd->st_price,Data->start_price);
  1146. if(file->watch_list==NULL)
  1147. {
  1148. file->watch_list=malloc(sizeof(record));
  1149. file->watch_list=rd;
  1150. }
  1151. else
  1152. {
  1153. record*cur=(record*)file->watch_list;
  1154. while(cur->next!=NULL)
  1155. {
  1156. cur=cur->next;
  1157. }
  1158. cur->next=rd;
  1159. }
  1160. gotoxy(40,11);
  1161. printf(space "ADDED\n");
  1162. }
  1163. _getch();
  1164. }
  1165. void buy_section(int cmp_num,user_details*file)
  1166. {
  1167. int flag=0;
  1168. system("cls");
  1169. set_up:
  1170. if(flag==0)
  1171. {
  1172. FILE *fp;
  1173. fp=fopen("COMPANY_DATA.txt","r");
  1174. char data[1000],x;
  1175. int idx=0,pos=0,cur_pos=0,last_pos=0;
  1176. while((x = fgetc(fp)) != EOF)
  1177. {
  1178. data[idx++] = x;
  1179. }
  1180. data[idx]='\0';
  1181. fclose(fp);
  1182. idx=0;
  1183. while(pos<cmp_num && data[idx]!='\0')
  1184. {
  1185. if(data[idx]=='$')
  1186. {
  1187. pos++;
  1188. }
  1189. idx++;
  1190. }
  1191. pos=0;
  1192. cur_pos=idx;
  1193. char temp_data[100],cmp_name[100],shares[100];
  1194. idx++;
  1195. while(data[idx]!='$')
  1196. {
  1197. temp_data[pos]=data[idx++];
  1198. pos++;
  1199. }
  1200. last_pos=idx;
  1201. temp_data[pos]='\0';
  1202. idx=pos=0;
  1203. while(temp_data[idx]!='#')
  1204. {
  1205. cmp_name[idx]=temp_data[idx];
  1206. idx++;
  1207. }
  1208. cmp_name[idx++]='\0';
  1209. char str_pric[100];
  1210. while(temp_data[idx]!='#')
  1211. {
  1212. str_pric[pos++]=temp_data[idx++];
  1213. }
  1214. str_pric[pos]='\0';
  1215. pos=0;
  1216. idx++;
  1217. while(temp_data[idx]!='\0')
  1218. {
  1219. shares[pos]=temp_data[idx++];
  1220. pos++;
  1221. }
  1222. shares[pos]='\0';
  1223. account_details *sec;
  1224. char quantity[100];
  1225. sec=file->account;
  1226. updating_point();
  1227. system("cls");
  1228. printf(space "<<<<<<<<<<<<<<<<<<<Buy Section>>>>>>>>>>>>>>>>>>>\n\n");
  1229. printf(space "Compaany Name:%s\n",cmp_name);
  1230. printf(space "Company Shares:%s\n",shares);
  1231. printf(space "Current Price:%d\n",array[cmp_num]);
  1232. printf(space "Available Funds :%d\n",sec->available_cash);
  1233. printf(space "Buy Quantity:");
  1234. scanf("%s",quantity);
  1235. if(check_quantity(quantity)==0)
  1236. {
  1237. flag++;
  1238. goto set_up;
  1239. }
  1240. if(check_quantity_available(quantity,shares)==0)
  1241. {
  1242. flag++;
  1243. goto set_up;
  1244. }
  1245. if(check_funds(quantity,cmp_num,sec->available_cash)==0)
  1246. {
  1247. flag++;
  1248. goto set_up;
  1249. }
  1250. record *set=(record*)malloc(1*sizeof(record));
  1251. set->buy_price=array[cmp_num];
  1252. strcpy(set->cmp_name,cmp_name);
  1253. set->no_of_share=char_to_int(quantity);
  1254. strcpy(set->order_shares,quantity);
  1255. strcpy(set->volume,shares);
  1256. set->buy_cash=char_to_int(quantity)*array[cmp_num];
  1257. set->next=NULL;
  1258. set->active=1;
  1259. set->pos=cmp_num;
  1260. strcpy(set->buy_time,calculating_time());
  1261. strcpy(set->st_price,str_pric);
  1262. if(file->portfolio==NULL)
  1263. {
  1264. file->portfolio=malloc(sizeof(record));
  1265. file->portfolio=set;
  1266. }
  1267. else
  1268. {
  1269. record *list=(record*)file->portfolio;
  1270. while(list->next!=NULL)
  1271. {
  1272. list=list->next;
  1273. }
  1274. list->next=set;
  1275. }
  1276. updating_funds(file,cmp_num,char_to_int(quantity));
  1277. flag=1;
  1278. idx=0;
  1279. printf(space"Current cash %d\n",sec->available_cash);
  1280. fp=fopen("Company_data.txt","w");
  1281. while(idx<cur_pos)
  1282. {
  1283. x=data[idx];
  1284. fputc(x,fp);
  1285. idx++;
  1286. }
  1287. idx=0;
  1288. fputc('|',fp);
  1289. while(cmp_name[idx]!='\0')
  1290. {
  1291. x=cmp_name[idx++];
  1292. fputc(x,fp);
  1293. }
  1294. idx=0;
  1295. fputc('#',fp);
  1296. while(str_pric[idx]!='\0')
  1297. {
  1298. x=str_pric[idx++];
  1299. fputc(x,fp);
  1300. }
  1301. idx=0;
  1302. fputc('#',fp);
  1303. char *new_quantity=int_char(char_to_int(shares)-char_to_int(quantity));
  1304. while(new_quantity[idx]!='\0')
  1305. {
  1306. x=new_quantity[idx++];
  1307. fputc(x,fp);
  1308. }
  1309. idx=last_pos;
  1310. while(data[idx]!='\0')
  1311. {
  1312. x=data[idx++];
  1313. fputc(x,fp);
  1314. }
  1315. fclose(fp);
  1316. account_details*cur=file->account;
  1317. cur->total_transaction++;
  1318. printf(space "Your Order is Succesfully Placed\n");
  1319. _getch();
  1320. }
  1321. else
  1322. {
  1323. printf(space"Press any Key\n");
  1324. _getch();
  1325. }
  1326. }
  1327. char *calculating_time()
  1328. {
  1329. char *cur_time;
  1330. int len=0;
  1331. while(len!=25)
  1332. {
  1333. time_t t;
  1334. time(&t);
  1335. cur_time=ctime(&t);
  1336. len=strlen(cur_time);
  1337. }
  1338. return cur_time;
  1339. }
  1340. int check_quantity_available(char *requested,char *available)
  1341. {
  1342. if(char_to_int(requested)<=char_to_int(available))
  1343. return 1;
  1344. else
  1345. {
  1346. printf(space "Requested quantity Not available\n");
  1347. return 0;
  1348. }
  1349. }
  1350. void updating_funds(user_details*file,int cmp_num,int shares)
  1351. {
  1352. account_details*sec=file->account;
  1353. long long int cur=sec->available_cash;
  1354. cur-=(array[cmp_num]*shares);
  1355. sec->available_cash=cur;
  1356. }
  1357. int check_funds(char *quantity,int number,long long int cash)
  1358. {
  1359. long long int shares=char_to_int(quantity);
  1360. if(shares*array[number]<cash)
  1361. return 1;
  1362. else
  1363. return 0;
  1364. }
  1365. int check_quantity(char *quantity)
  1366. {
  1367. int idx=0;
  1368. while(quantity[idx]!='\0')
  1369. {
  1370. if(quantity[idx]>47 && quantity[idx]<58)
  1371. {
  1372. idx++;
  1373. }
  1374. else
  1375. {
  1376. printf(space "Enter only Numbers\n");
  1377. return 0;
  1378. }
  1379. }
  1380. return 1;
  1381. }
  1382.  
  1383. int* whole_data(int st_price,int page,int CURRENT,int *length)
  1384. {
  1385. FILE *fp;
  1386. char x='k',Data[10000],max_array[3];
  1387. fp=fopen("Prices_list.txt","a+");
  1388. int pos=0,index=0,new_arr[1000],price=0,var=(5*page)+CURRENT,value=0;
  1389. while(value<ind_pos)
  1390. {
  1391. index=0;
  1392. while(x!='$')
  1393. {
  1394. x=fgetc(fp);
  1395. Data[index]=x;
  1396. index++;
  1397. }
  1398. Data[index]='\0';
  1399. int cur=0,low=0;
  1400. while(cur!=var && low<index)
  1401. {
  1402. if(Data[low]=='#')
  1403. {
  1404. cur++;
  1405. }
  1406. low++;
  1407. }
  1408. cur=0;
  1409. while(Data[low]!='#')
  1410. {
  1411. max_array[cur++]=Data[low];
  1412. low++;
  1413. }
  1414. max_array[cur]='\0';
  1415. int v;
  1416. v=char_to_int(max_array);
  1417. new_arr[value]=v;
  1418. value++;
  1419. pos++;
  1420. x='k';
  1421. }
  1422. int *r=&value;
  1423. *length=*r;
  1424. return new_arr;
  1425. }
  1426. void graph_section(char *name,char* shares,char* st_price,int page,int CURRENT)
  1427. {
  1428. system("cls");
  1429. int len,*data;
  1430. printf("1");
  1431. data=whole_data(char_to_int(st_price),page,CURRENT,&len);
  1432. printf("2");
  1433. int gd = DETECT,gm;
  1434. initgraph(&gd, &gm, "C:\\TC\\BGI");
  1435. setcolor(YELLOW);
  1436. settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
  1437. setcolor(WHITE);
  1438. outtextxy(275,0,"Graph Section");
  1439. outtextxy(50,20,"Name :");
  1440. outtextxy(120,20,name);
  1441. outtextxy(50,40,"Shares :");
  1442. outtextxy(120,40,shares);
  1443. outtextxy(450,40,"Cur_price :");
  1444. outtextxy(545,40,int_char(array[(5*page)+CURRENT]));
  1445. line(0,60,639,60);
  1446. if(len==0)
  1447. {
  1448. outtextxy(10,430-char_to_int(st_price),st_price);
  1449. line(10,430,10,430-char_to_int(st_price));
  1450. }
  1451. else
  1452. {
  1453. fun_graph(data,len,char_to_int(st_price));
  1454. }
  1455. line(0,430,639,430);
  1456. outtextxy(150,440,"Press any Key");
  1457. _getch();
  1458. closegraph();
  1459. }
  1460. void fun_graph(int *data,int len,int st_price)
  1461. {
  1462. graph_coordinates(data,len,st_price);
  1463. printf("1.5");
  1464. int add=0;
  1465. if(len<2)
  1466. {
  1467. add=2;
  1468. }
  1469. int dist =600/(len+add);
  1470. int idx=0,range=len+1;
  1471. char *str=int_char(st_price);
  1472. int x1=10,x2=10,y1=430,y2=430-st_price;
  1473. while(idx<range)
  1474. {
  1475. outtextxy(x2,y2,str);
  1476. line(x1,y1,x2,y2);
  1477. x1=x2;
  1478. y1=y2;
  1479. x2=x2+dist;
  1480. y2=430-data[idx]-10;
  1481. str=int_char(data[idx]);
  1482. idx++;
  1483. }
  1484. }
  1485. void graph_coordinates(int *prev_data,int len,int st_price)
  1486. {
  1487. int idx,cur=st_price;
  1488. int *data=(int*)malloc(len*sizeof(int));
  1489. for(idx=0; idx<len; idx++)
  1490. {
  1491. data[idx]=prev_data[idx];
  1492. cur+=data[idx];
  1493. data[idx]=cur;
  1494. if(data[idx]<0)
  1495. {
  1496. data[idx]=0;
  1497. cur=0;
  1498. }
  1499. }
  1500. cur=0;
  1501. int pos=0,diff=0;
  1502. for(idx=0; idx<len; idx++)
  1503. {
  1504. if(data[idx]>360)
  1505. {
  1506. cur=data[idx]-360+2;
  1507. pos=idx;
  1508. data[idx]-=cur;
  1509. while(pos--)
  1510. {
  1511. diff=data[pos+1]-data[pos];
  1512. if(diff>=cur)
  1513. {
  1514. pos=0;
  1515. }
  1516. else
  1517. {
  1518. data[pos]-=cur;
  1519. }
  1520. }
  1521. }
  1522. }
  1523. for(idx=0; idx<len; idx++)
  1524. {
  1525. prev_data[idx]=data[idx];
  1526. }
  1527. printf("1.9");
  1528. }
  1529. void printf_sec(char *data)
  1530. {
  1531. int len=strlen(data);
  1532. printf("%s",data);
  1533. if(len<12)
  1534. {
  1535. while(len<12)
  1536. {
  1537. printf(" ");
  1538. len++;
  1539. }
  1540. }
  1541. }
  1542. void printf_name(char *name)
  1543. {
  1544. int len=strlen(name);
  1545. printf("%s",name);
  1546. if(len<25)
  1547. {
  1548. while(len<25)
  1549. {
  1550. printf(" ");
  1551. len++;
  1552. }
  1553. }
  1554. }
  1555. void my_Account(user_details *file)
  1556. {
  1557. system("cls");
  1558. printf("\n\n\n\n");
  1559. updating_point();
  1560. printf(space"<<<<<<<<<<<<<<<<<<My Account>>>>>>>>>>>>>>>>>>>\n\n");
  1561. account_details*cur=file->account;
  1562. int stock_value=calculating_stock_value(file);
  1563. printf("NAME:");
  1564. printf_name(file->username);
  1565. printf("\nStarting Investment:%d\n",cur->investement);
  1566. printf("balance =%d\n",cur->available_cash);
  1567. printf("Stock Value:%d\n",stock_value);
  1568. printf("Total Transactions=%d\n",cur->total_transaction);
  1569. printf("Total Value=%d\n",stock_value+cur->available_cash);
  1570. if((cur->available_cash+stock_value)>cur->investement)
  1571. printf("PROFIT\n");
  1572. else
  1573. printf("LOSS\n");
  1574. printf("press enter to see the graph\n");
  1575. printf("press any other key to go back\n");
  1576. if(_getch()==13)
  1577. {
  1578. graph(stock_value);
  1579. }
  1580. _getch();
  1581. }
  1582. void graph(int value)
  1583. {
  1584. int angle=0;
  1585. if(value<500000 && value!=0)
  1586. {
  1587. if(value<5000)
  1588. {
  1589. angle=3.6;
  1590. }
  1591. else
  1592. {
  1593. angle=3.6*value/5000;
  1594. }
  1595. int gd=DETECT,gm,midx,midy;
  1596. initgraph(&gd,&gm,"C:\\TC\\BGI");
  1597. setcolor(BLUE);
  1598. rectangle(0,40,639,450);
  1599. settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
  1600. setcolor(WHITE);
  1601. outtextxy(275,10,"PIE_CHART");
  1602. midx=getmaxx()/2;
  1603. midy=getmaxy()/2;
  1604. setfillstyle(4,YELLOW);
  1605. pieslice(midx,midy,0,angle,100);
  1606. setcolor(YELLOW);
  1607. outtextxy(midx+100,midy-30,percent_int_char(value/5000));
  1608. outtextxy(midx+100,midy-05,"stock _value");
  1609. setfillstyle(6,BLUE);
  1610. pieslice(midx,midy,angle,360,100);
  1611. setcolor(BLUE);
  1612. outtextxy(midx-10,340,percent_int_char(100-value/5000));
  1613. outtextxy(midx+10,360,"CASH");
  1614. outtextxy(midx+200,midy-25,"Press any key");
  1615. }
  1616. else
  1617. {
  1618. int gd=DETECT,gm,midx,midy;
  1619. initgraph(&gd,&gm,"C:\\TC\\BGI");
  1620. setcolor(BLUE);
  1621. rectangle(0,40,639,450);
  1622. settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
  1623. setcolor(WHITE);
  1624. outtextxy(275,10,"PIE_CHART");
  1625. midx=getmaxx()/2;
  1626. midy=getmaxy()/2;
  1627. setfillstyle(4,BLUE);
  1628. pieslice(midx,midy,0,360,100);
  1629. setcolor(BLUE);
  1630. outtextxy(midx+100,midy-30,"100%");
  1631. outtextxy(midx+100,midy-05,"cash");
  1632. outtextxy(midx+200,midy-25,"Press any key");
  1633. }
  1634. _getch();
  1635. closegraph();
  1636. }
  1637. char *percent_int_char(int src)
  1638. {
  1639. char r,*string=(char*)malloc(100*sizeof(char));
  1640. int n=src,j=0,temp=0;
  1641. if(src<0)
  1642. {
  1643. n=n*-1;
  1644. temp=1;
  1645. }
  1646. string[j++]='%';
  1647. if(n==0)
  1648. {
  1649. string[j++]='0';
  1650. }
  1651. while(n!=0)
  1652. {
  1653. r=n%10;
  1654. string[j++]=(r+48);
  1655. n/=10;
  1656. }
  1657. if(temp==1)
  1658. {
  1659. string[j++]=45;
  1660. }
  1661. string[j]='\0';
  1662. strrev(string);
  1663. return string;
  1664. }
  1665. int calculating_stock_value(user_details*file)
  1666. {
  1667. int money=0;
  1668. record*data=(record*)file->portfolio;
  1669. while(data!=NULL)
  1670. {
  1671. money +=data->no_of_share*array[data->pos];
  1672. data=data->next;
  1673. }
  1674. return money;
  1675. }
  1676. void user_choice(int choice,user_details* file)
  1677. {
  1678. if(choice==1)
  1679. Help_sec(file->username);
  1680. else if(choice==2)
  1681. portfolio(file);
  1682. else if(choice==3)
  1683. watch_list(file);
  1684. else if(choice==4)
  1685. stock_list(file);
  1686. else if(choice==5)
  1687. my_Account(file);
  1688. else if(choice==6)
  1689. trans_sec(file);
  1690. }
  1691. void arrow_fun(int exp,int act)
  1692. {
  1693. if(exp==act)
  1694. printf(space"->");
  1695. else
  1696. printf(space" ");
  1697. }
  1698. void welcome_page(char *username)
  1699. {
  1700. system("color f9");
  1701. system("cls");
  1702. printf("\n\n\n\n\n\n");
  1703. printf(space"<<<<<<<<<<<<<<<<<<<<<Welcome Page>>>>>>>>>>>>>>>>>>>>>>\n\n");
  1704. printf(space "Welcome to HELIX %s\n",username);
  1705. printf("\n");
  1706. printf(space "If you are new to HELIX \n");
  1707. printf(space" Go to the Help Section First\n");
  1708. printf(space"Other's wise carry on\n");
  1709. printf(space"Press any key\n");
  1710. _getch();
  1711. system("cls");
  1712. }
  1713. int Main_page()
  1714. {
  1715. FILE *fp;
  1716. char choice,x;
  1717. char users[100];
  1718. char username[100];
  1719. char password[100];
  1720. int i=0;
  1721. main_sec:
  1722. while(1)
  1723. {
  1724. fflush(stdin);
  1725. system("cls");
  1726. printf("\n\n\n\n\n");
  1727. printf(space "Helix\n");
  1728. printf(space"1)login\n");
  1729. printf(space"2)signup\n");
  1730. printf(space"3)exit\n");
  1731. printf(space"Enter Your choice\n");
  1732. printf(space);
  1733. choice=_getch();
  1734. if(choice== 49 || choice ==50 ||choice==51)
  1735. break;
  1736. else
  1737. {
  1738. printf("\n"space"Enter valid choice\n");
  1739. printf(space"press any key\n");
  1740. _getch();
  1741. system("cls");
  1742. }
  1743. }
  1744. if(choice==49)
  1745. {
  1746. login_page();
  1747. goto main_sec;
  1748. }
  1749. if(choice ==50)
  1750. {
  1751. signup_page();
  1752. goto main_sec;
  1753. }
  1754. if(choice==51)
  1755. {
  1756. system("cls");
  1757. printf(space"Exit\n\n");
  1758. printf(space"Are You Sure Want to Exit\n");
  1759. printf(space"Enter y/n\n");
  1760. x=_getch();
  1761. if(x=='n'||x=='N')
  1762. goto main_sec;
  1763. else
  1764. {
  1765. printf("\n"space"Thank u for visiting\n");
  1766. }
  1767. }
  1768. }
  1769. void signup_page()
  1770. {
  1771. FILE *fp;
  1772. int i;
  1773. char x,username[100],password[100];
  1774. system("cls");
  1775. printf("\n\n\n\n\n");
  1776. printf(space "\t<<<<<<<<<<<<<<<<<<<Signup>>>>>>>>>>>>>>>>\n\n");
  1777. 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);
  1778. printf("\n"space "\t\tUsername : %c %c\n",179,179);
  1779. 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);
  1780. gotoxy(52,11);
  1781. scanf("%s",username);
  1782. i=0;
  1783. while((x = username[i]) != '\0')
  1784. {
  1785. if(x == '|' || x == '#' || x == '$')
  1786. {
  1787. printf("\n*Username must not contain special characters like |, #, $ etc.");
  1788. _getch();
  1789. goto signup_end;
  1790. }
  1791. i++;
  1792. }
  1793. char accountsDB[100];
  1794. fp = fopen("PROJECT_DATA_FILE.txt","r");
  1795. i = 0;
  1796. while((x = fgetc(fp)) != EOF)
  1797. {
  1798. accountsDB[i++] = x;
  1799. }
  1800. fclose(fp);
  1801. char temp_pass[100];
  1802. if(NULL == strstr(accountsDB, username))
  1803. {
  1804. i=0;
  1805. 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);
  1806. printf("\n"space "\t\tPassword : %c %c\n",179,179);
  1807. 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);
  1808. gotoxy(52,14);
  1809. while ((x = _getch()) != '\r')
  1810. {
  1811. printf("*");
  1812. password[i++] = x;
  1813. }
  1814. password[i] = '\0';
  1815. 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);
  1816. printf("\n"space "\t\tPassword : %c %c\n",179,179);
  1817. 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);
  1818. gotoxy(52,16);
  1819. i = 0;
  1820. while((x = _getch()) != '\r')
  1821. {
  1822. printf("*");
  1823. temp_pass[i++] = x;
  1824. }
  1825. temp_pass[i]='\0';
  1826. if(strcmp(temp_pass,password)==0)
  1827. {
  1828. i = 0;
  1829. fp = fopen("PROJECT_DATA_FILE.txt","a");
  1830. fputc('|',fp);
  1831. while((x = username[i]) != '\0')
  1832. {
  1833. fputc(x,fp);
  1834. i++;
  1835. }
  1836. i = 0;
  1837. while((x = password[i]) != '\0')
  1838. {
  1839. fputc(x,fp);
  1840. i++;
  1841. }
  1842. fputc('$', fp);
  1843. fputc('1', fp);
  1844. fputc('#', fp);
  1845. fputc('1', fp);
  1846. fclose(fp);
  1847. printf("\n\n"space space "Sign up successful\n");
  1848. goto signup_end;
  1849. }
  1850. else
  1851. {
  1852. printf("\n\n"space space"*Passwords do not match, try again\n");
  1853. goto signup_end;
  1854. }
  1855. }
  1856. else
  1857. {
  1858. printf(space "\n"space"*Username is already taken\n");
  1859. signup_end:
  1860. printf(space "press any key\n");
  1861. _getch();
  1862. }
  1863. }
  1864. int char_to_int(char*num)
  1865. {
  1866. int length=strlen(num);
  1867. int var=1;
  1868. int i,c=0,temp;
  1869. for(i=0; i<length; i++)
  1870. {
  1871. if(i==0 && num[i]==45 )
  1872. {
  1873. var=-1;
  1874. }
  1875. else
  1876. {
  1877. temp=(num[i]-48);
  1878. c=c*10+temp;
  1879. }
  1880. }
  1881. c=c*var;
  1882. return c;
  1883. }
  1884. char *int_char(int src)
  1885. {
  1886. char r,*string=(char*)malloc(100*sizeof(char));
  1887. int n=src,j=0,temp=0;
  1888. if(src<0)
  1889. {
  1890. n=n*-1;
  1891. temp=1;
  1892. }
  1893. if(n==0)
  1894. {
  1895. string[j++]='0';
  1896. }
  1897. while(n!=0)
  1898. {
  1899. r=n%10;
  1900. string[j++]=(r+48);
  1901. n/=10;
  1902. }
  1903. if(temp==1)
  1904. {
  1905. string[j++]=45;
  1906. }
  1907. string[j]='\0';
  1908. strrev(string);
  1909. return string;
  1910. }
  1911. void trans_sec(user_details* file)
  1912. {
  1913. system("cls");
  1914. printf("\n\n\n\n");
  1915. printf("<<<<<<<<<<<<<<<<<<Transaction Histroy>>>>>>>>>>>>>>>>>>>\n\n");
  1916. printf(" COMPANY_NAME || OPTION || SHARE || PRICE || TIME || PERCENTAGE \n");
  1917. record*cur=(record*)file->trans_his;
  1918. if(file->trans_his==NULL)
  1919. {
  1920. printf(" NULL || NULL || NULL || NULL || NULL || NULL \n");
  1921. }
  1922. else
  1923. {
  1924. while(cur!=NULL)
  1925. {
  1926. updating_point();
  1927. if(cur->active==1)
  1928. {
  1929. printf_name(cur->cmp_name);
  1930. printf("|| BUY ||");
  1931. printf_sec(int_char(cur->no_of_share));
  1932. printf("||");
  1933. printf_sec(int_char(cur->buy_price));
  1934. printf("||");
  1935. printf_date(cur->buy_time);
  1936. printf("|| NULL \n");
  1937. }
  1938. else
  1939. {
  1940. printf_name(cur->cmp_name);
  1941. printf("|| SELL ||");
  1942. printf_sec(cur->order_shares);
  1943. printf(" ||");
  1944. printf_sec(int_char(cur->selling_price));
  1945. printf("||");
  1946. printf_date(cur->sell_time);
  1947. printf("||");
  1948. printf_sec(int_char(cur->percentage));
  1949. printf("\n");
  1950. }
  1951. cur=cur->next;
  1952. }
  1953. }
  1954. printf(space"Press any key\n");
  1955. _getch();
  1956. }
  1957. void printf_date(char*source)
  1958. {
  1959. int idx=3;
  1960. while(idx<10)
  1961. {
  1962. printf("%c",source[idx]);
  1963. idx++;
  1964. }
  1965. }
Add Comment
Please, Sign In to add comment