rohit35

proj

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