rohit35

code

Apr 2nd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.66 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<time.h>
  7. #define space "\t \t \t"
  8. typedef struct list{
  9. char name[100];
  10. int start_price;
  11. int volume;
  12. int market;
  13. }list_t;
  14. void userpage(char *users);
  15. char *int_char(int src);
  16. void *myThreadFun(void *id);
  17. void *myThreadFun(void *id)
  18. {
  19. FILE * fp_3;
  20. char ch,*str;
  21. time_t t,t_1;
  22. int v=20,random_1,random_2,idx,count=20;
  23. random_1 = random_2 =idx=0;
  24. fp_3=fopen("Prices_list.txt","w");
  25. while(v--)
  26. {
  27. while(count--)
  28. {
  29. srand((unsigned) time(&t));
  30. random_1=rand()%10;
  31. srand((unsigned) time(&t_1));
  32. random_2=rand()%10;
  33. if(random_1 == random_2)
  34. {
  35. if(random_1%2==0)
  36. str=int_char(random_1*random_2);
  37. else
  38. str=int_char(random_1*random_2*-1);
  39. }
  40. else
  41. {
  42. if(random_1%2==0)
  43. str=int_char(random_2);
  44. else
  45. str=int_char(random_2*-1);
  46. }
  47. while(str[idx]!='\0')
  48. {
  49. fputc(str[idx],fp_3);
  50. idx++;
  51. }
  52. fputc('#',fp_3);
  53. idx=0;
  54. }
  55. count=20;
  56. Sleep(5000);
  57. fputc('$',fp_3);
  58. }
  59. fclose(fp_3);
  60. }
  61. char *int_char(int src)
  62. {
  63. char r,*string=(char*)malloc(100*sizeof(char));
  64. int n=src,j=0,temp=0;
  65. if(src<0)
  66. {
  67. n=n*-1;
  68. temp=1;
  69. }
  70. while(n!=0)
  71. {
  72. r=n%10;
  73. string[j++]=(r+48);
  74. n/=10;
  75. }
  76. if(temp==1)
  77. {
  78. string[j++]=43;
  79. }
  80. string[j]='\0';
  81. strrev(string);
  82. return string;
  83. }
  84. void userpage(char *users)
  85. {
  86. int max=5,select=1,loop=1;
  87. pthread_t tid;
  88. pthread_create(&tid, NULL, myThreadFun, (void*)1);
  89. user_sec:
  90. while(loop)
  91. {
  92. if(select >6||select ==0)
  93. {
  94. select =1;
  95. }
  96. system("cls");
  97. system("color 04");
  98. printf(" Stock Guide\n\n");
  99. if(select ==1)
  100. {
  101. printf("-> portfolio\n");
  102. }
  103. else
  104. {
  105. printf(" Portfolio\n");
  106. }
  107. if(select == 2)
  108. {
  109. printf("-> watchlist\n");
  110. }
  111. else
  112. {
  113. printf(" watchlist\n");
  114. }
  115. if(select==3)
  116. {
  117. printf("-> stock list\n");
  118. }
  119. else
  120. {
  121. printf(" stock list\n");
  122. }
  123. if(select==4)
  124. {
  125. printf("-> account\n");
  126. }
  127. else
  128. {
  129. printf(" account\n");
  130. }
  131. if(select ==5)
  132. {
  133. printf("-> Transaction Histroy\n");
  134. }
  135. else
  136. {
  137. printf(" Transaction histroy\n");
  138. }
  139. if(select==6)
  140. {
  141. printf("-> EXIT\n");
  142. }
  143. else
  144. {
  145. printf(" EXIT\n");
  146. }
  147. printf("Use the Arrow key's to move and select\n");
  148. switch(_getch())
  149. {
  150. case 'H':
  151. select--;
  152. // goto user_sec;
  153. break;
  154. case 'P':
  155. select++;
  156. // goto user_sec;
  157. break;
  158. case 13:
  159. if(select!=6)
  160. {
  161. user_choice(select,users);;
  162. }
  163. else
  164. {
  165. loop=0;
  166. }
  167. break;
  168. }
  169.  
  170. }
  171. }
  172. void user_choice(int choice,char *Name)
  173. {
  174. if(choice==1)
  175. portfolio(Name);
  176. else if(choice==2)
  177. watch_list(Name);
  178. else if(choice==3)
  179. stock_list(Name);
  180. else if(choice==4)
  181. my_Account(Name);
  182. else if(choice==5)
  183. trans_sec(Name);
  184. }
  185. void trans_sec(char* Name)
  186. {
  187.  
  188. }
  189. void watch_list(char* Name)
  190. {
  191.  
  192. }
  193. void stock_list(char *Name)
  194. {
  195. system("cls");
  196. FILE*fp,*fp1;
  197. char x;
  198. list_t *collection=(list_t*)malloc(sizeof(list_t)*5);
  199. int i,arrow=0;
  200. if((fp1=fopen("COMPANY_DATA.txt","r"))==NULL)
  201. {
  202. fp1=fopen("COMPANY_DATA.txt","w");
  203. 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$";
  204. i=0;
  205. while(data[i]!='\0')
  206. {
  207. x=data[i];
  208. fputc(x,fp1);
  209. i++;
  210. }
  211. fclose(fp1);
  212. }
  213. fp=fopen("COMPANY_DATA.txt","r+");
  214. i=0;
  215. char all[10000];
  216. while((x = fgetc(fp)) != EOF)
  217. {
  218. all[i++] = x;
  219. }
  220. all[i] = '\0';
  221. int prev=4,page=0;
  222. while(1)
  223. {
  224. system("cls");
  225. inserting_the_data(collection,all,prev,page,i);
  226. prev=page;
  227. printf(" <<<<<<<<<<<<<<<<<<<Stock list>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n");
  228. printf("COMPANY_NAME ||STARTING_PRICE || VOLUME || MARKET ");
  229. printf("\n%s|%d|%d|%d",collection[0].name,collection[0].start_price,collection[0].volume,collection[0].market);if(arrow==0)printf("<-");
  230. printf("\n%s|%d|%d|%d",collection[1].name,collection[1].start_price,collection[1].volume,collection[1].market);if(arrow==1)printf("<-");
  231. printf("\n%s|%d|%d|%d",collection[2].name,collection[2].start_price,collection[2].volume,collection[2].market);if(arrow==2)printf("<-");
  232. printf("\n%s|%d|%d|%d",collection[3].name,collection[3].start_price,collection[3].volume,collection[3].market);if(arrow==3)printf("<-");
  233. printf("\n%s|%d|%d|%d",collection[4].name,collection[4].start_price,collection[4].volume,collection[4].market);if(arrow==4)printf("<-");
  234. x=_getch();
  235. switch(x)
  236. {
  237. case 72:arrow--;
  238. break;
  239. case 80:arrow++;
  240. break;
  241. case 75:page--;
  242. break;
  243. case 77:page++;
  244. break;
  245. case 13:view_stock(collection,arrow);
  246. }
  247. if(arrow>4 ||arrow<0)
  248. {arrow=0;}
  249. if(page>3 ||page<0)
  250. {page=0;
  251. arrow =0;}
  252. }
  253. }
  254. int calcu_eps(int capital,int shares)
  255. {
  256. int out_stan_shares=shares;
  257. return capital/out_stan_shares-14;
  258. }
  259. int calcu_pe(int price,int eps)
  260. {
  261. return eps/price;
  262. }
  263. int calcu_Div(int price)
  264. {
  265. int dividend_yield=7;
  266. return price/dividend_yield;
  267. }
  268. void view_stock(list_t*Data,int choice)
  269. {
  270. int EPS,PE,Dividend;
  271. EPS=calcu_eps(Data[choice].market,Data[choice].volume);
  272. PE=calcu_pe(Data[choice].start_price,EPS);
  273. Dividend=calcu_Div(Data[choice].start_price);
  274. system("cls");
  275. printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<View Stock>>>>>>>>>>>>>>>>>>>>>\n\n");
  276. printf("<<<<<<<<<<<<<<<<<<<<<<<<Company Details>>>>>>>>>>>>>>>>>>>>\n");
  277. printf("\t\t\t\t\tFundamentals Analysis\n");
  278. printf("Name:%s \t\t\t\t",Data[choice].name); printf("EPS:%d\n",EPS);
  279. printf("No.of.Shares:%d \t\t\t",Data[choice].volume); printf("PE :%d\n",PE);
  280. printf("Starting price:%d\t\t\t",Data[choice].start_price); printf("Dividend:%d\n",Dividend);
  281. printf("Market Capital:%d\n",Data[choice].market);
  282. _getch();
  283. }
  284. void inserting_the_data(list_t *collect,char*Data,int prev,int cur,int range)
  285. {
  286. int idx=0,position=0;
  287. if(cur==0 && prev!=cur)
  288. {
  289. insert(collect,Data,cur+1);
  290. }
  291. else if(cur==1 && prev!=cur)
  292. {
  293. position=cur*5;
  294. while(position--)
  295. {
  296. while(Data[idx]!='$')
  297. {idx++;}
  298. idx+=2;
  299. }
  300. insert(collect,Data,idx);
  301. }
  302. else if(cur==2 && prev!=cur)
  303. {
  304. position=10;
  305. while(position--)
  306. {
  307. while(Data[idx]!='$')
  308. {idx++;}
  309. idx+=2;
  310. }
  311. insert(collect,Data,idx);
  312. }
  313. else if(cur==3 && prev!=cur)
  314. {
  315. position=15;
  316. while(position--)
  317. {
  318. while(Data[idx]!='$')
  319. {idx++;}
  320. idx+=2;
  321. }
  322. insert(collect,Data,idx);
  323. }
  324. }
  325. void insert(list_t *collect,char *Data,int pos)
  326. {
  327. int count=5,idx=0,range=0;
  328. char temp[100]={0};
  329. while(range<count)
  330. {
  331. idx=0;
  332. while(Data[pos]!='#')
  333. {
  334. temp[idx++]=Data[pos];
  335. pos++;
  336. }
  337. temp[idx]='\0';
  338. pos++;
  339. strcpy(collect[range].name,temp);
  340. idx=0;
  341. while(Data[pos]!='#')
  342. {
  343. temp[idx]=Data[pos++];
  344. idx++;
  345. }
  346. temp[idx]='\0';
  347. collect[range].start_price=char_to_int(temp);
  348. idx=0;
  349. pos++;
  350. while(Data[pos]!='$')
  351. {
  352. temp[idx]=Data[pos++];
  353. idx++;
  354. }
  355. temp[idx]='\0';
  356. pos+=2;
  357. collect[range].volume=char_to_int(temp);
  358. collect[range].market=((collect[range].start_price)*(collect[range].volume))*2;
  359. range++;
  360. }
  361. }
  362. void my_Account(char *Name)
  363. {
  364. printf("My Account\n\n");
  365. printf("Name :%s\n",Name);
  366. printf("Starting Investment:50,000\n");
  367. // printf("Stock Value :%d",);
  368.  
  369. }
  370. void portfolio(char *Name)
  371. {
  372.  
  373. }
  374. int main()
  375. {
  376. printf("WELCOME\n");
  377. printf(" TO \n");
  378. printf(" HELIX \n");
  379. printf("Press any Key\n");
  380. _getch();
  381. Main_page();
  382. return 0;
  383. }
  384. int Main_page()
  385. {
  386. FILE *fp;
  387. char choice,x;
  388. char users[100];
  389. char username[100];
  390. char password[100];
  391. int i=0;
  392. main_sec:
  393. system("cls");
  394. while(1)
  395. {
  396. fflush(stdin);
  397. printf("Helix\n");
  398. printf("1)login\n");
  399. printf("2)signup\n");
  400. printf("3)exit");
  401. choice=_getch();
  402. if(choice== 49 || choice ==50 ||choice==51)
  403. break;
  404. else
  405. {
  406. printf("\nEnter valid choice\n");
  407. printf("press any key\n");
  408. _getch();
  409. system("cls");
  410. }
  411. }
  412. if(choice==49)
  413. {
  414. char x,*tempstr;
  415. char accountsDB[100];
  416. system("cls");
  417. printf("Login \n");
  418. printf("Username:");
  419. scanf("%s",username);
  420. printf("\n");
  421. i=0;
  422. while(username[i] != '\0')
  423. {
  424. users[i] = username[i];
  425. i++;
  426. }
  427. users[i] = '\0';
  428. i=0;
  429. printf("Password:");
  430. while ((x = _getch()) != '\r')
  431. {
  432. printf("*");
  433. password[i++] = x;
  434. }
  435. password[i] = '\0';
  436. i = 0;
  437. strcat(username, password);
  438. fp = fopen("PROJECT_DATA_FILE.txt","r");
  439. while((x = fgetc(fp)) != EOF)
  440. {
  441. accountsDB[i++] = x;
  442. }
  443. accountsDB[i] = '\0';
  444. fclose(fp);
  445. if(NULL == strstr(accountsDB, username))
  446. {
  447. printf("\n\n"space space"*Username or password is wrong");
  448. _getch();
  449. goto main_sec;
  450. }
  451. else
  452. {
  453. tempstr = strstr(accountsDB, username);
  454. }
  455. i=0;
  456. while(username[i]!='\0')
  457. {
  458. if(username[i]!=tempstr[i])
  459. break;
  460.  
  461. i++;
  462. }
  463. if(i==strlen(username))
  464. {
  465. userpage(users);
  466. goto main_sec;
  467. }
  468. else
  469. {
  470. printf("\n\n*Username or password is wrong");
  471. _getch();
  472. goto main_sec;
  473. }
  474. }
  475. if(choice ==50)
  476. {
  477. system("cls");
  478. printf("Signup\n");
  479. printf("Username:");
  480. scanf("%s",username);
  481. i=0;
  482. while((x = username[i]) != '\0')
  483. {
  484. if(x == '|' || x == '#' || x == '$')
  485. {
  486. printf("\n*Username must not contain special characters like |, #, $ etc.");
  487. _getch();
  488. goto main_sec;
  489. }
  490. i++;
  491. }
  492. char accountsDB[100];
  493. fp = fopen("PROJECT_DATA_FILE.txt","r");
  494. i = 0;
  495. while((x = fgetc(fp)) != EOF)
  496. {
  497. accountsDB[i++] = x;
  498. }
  499. fclose(fp);
  500. char temp_pass[100];
  501. if(NULL == strstr(accountsDB, username))
  502. {
  503. i=0;
  504. printf("Password:");
  505. while ((x = _getch()) != '\r')
  506. {
  507. printf("*");
  508. password[i++] = x;
  509. }
  510. password[i] = '\0';
  511. printf("\nRe-Enter password:");
  512. i = 0;
  513. while((x = _getch()) != '\r')
  514. {
  515. printf("*");
  516. temp_pass[i++] = x;
  517. }
  518. temp_pass[i]='\0';
  519. if(strcmp(temp_pass,password)==0)
  520. {
  521. i = 0;
  522. fp = fopen("PROJECT_DATA_FILE.txt","a");
  523. fputc('|',fp);
  524. while((x = username[i]) != '\0')
  525. {
  526. fputc(x,fp);
  527. i++;
  528. }
  529. i = 0;
  530. while((x = password[i]) != '\0')
  531. {
  532. fputc(x,fp);
  533. i++;
  534. }
  535. fputc('$', fp);
  536. fputc('1', fp);
  537. fputc('#', fp);
  538. fputc('1', fp);
  539. fclose(fp);
  540. printf("\n\nSign up successful");
  541. _getch();
  542. goto main_sec;
  543. }
  544. else
  545. {
  546. printf("\n\n*Passwords do not match, try again");
  547. _getch();
  548. goto main_sec;
  549. }
  550. }
  551. else
  552. {
  553. printf("\n*Username is already taken");
  554. _getch();
  555. goto main_sec;
  556. }
  557. }
  558. if(choice==51)
  559. {
  560. system("cls");
  561. printf("Exit\n\n");
  562. printf("Are You Sure Want to Exit\n");
  563. printf("Enter y/n\n");
  564. x=_getch();
  565. if(x=='n'||x=='N')
  566. goto main_sec;
  567. else
  568. {
  569. printf("Thank u for visiting\n");
  570. }
  571. }
  572. }
  573. int char_to_int(char*num)
  574. {
  575.  
  576. int length=strlen(num);
  577. int var=1;
  578. int i,c=0,temp;
  579. for(i=0; i<length; i++)
  580. {
  581. if(i==0 && num[i]==45 )
  582. {
  583. var=-1;
  584. }
  585. else
  586. {
  587. temp=(num[i]-48);
  588. c=c*10+temp;
  589. }
  590. }
  591. c=c*var;
  592. return c;
  593. }
Add Comment
Please, Sign In to add comment