Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<windows.h>
- #include<pthread.h>
- #include<conio.h>
- #include<string.h>
- #include<time.h>
- #define space "\t \t \t"
- typedef struct list{
- char name[100];
- int start_price;
- int volume;
- int market;
- }list_t;
- void userpage(char *users);
- char *int_char(int src);
- void *myThreadFun(void *id);
- void *myThreadFun(void *id)
- {
- FILE * fp_3;
- char ch,*str;
- time_t t,t_1;
- int v=20,random_1,random_2,idx,count=20;
- random_1 = random_2 =idx=0;
- fp_3=fopen("Prices_list.txt","w");
- while(v--)
- {
- while(count--)
- {
- srand((unsigned) time(&t));
- random_1=rand()%10;
- srand((unsigned) time(&t_1));
- random_2=rand()%10;
- if(random_1 == random_2)
- {
- if(random_1%2==0)
- str=int_char(random_1*random_2);
- else
- str=int_char(random_1*random_2*-1);
- }
- else
- {
- if(random_1%2==0)
- str=int_char(random_2);
- else
- str=int_char(random_2*-1);
- }
- while(str[idx]!='\0')
- {
- fputc(str[idx],fp_3);
- idx++;
- }
- fputc('#',fp_3);
- idx=0;
- }
- count=20;
- Sleep(5000);
- fputc('$',fp_3);
- }
- fclose(fp_3);
- }
- char *int_char(int src)
- {
- char r,*string=(char*)malloc(100*sizeof(char));
- int n=src,j=0,temp=0;
- if(src<0)
- {
- n=n*-1;
- temp=1;
- }
- while(n!=0)
- {
- r=n%10;
- string[j++]=(r+48);
- n/=10;
- }
- if(temp==1)
- {
- string[j++]=43;
- }
- string[j]='\0';
- strrev(string);
- return string;
- }
- void userpage(char *users)
- {
- int max=5,select=1,loop=1;
- pthread_t tid;
- pthread_create(&tid, NULL, myThreadFun, (void*)1);
- user_sec:
- while(loop)
- {
- if(select >6||select ==0)
- {
- select =1;
- }
- system("cls");
- system("color 04");
- printf(" Stock Guide\n\n");
- if(select ==1)
- {
- printf("-> portfolio\n");
- }
- else
- {
- printf(" Portfolio\n");
- }
- if(select == 2)
- {
- printf("-> watchlist\n");
- }
- else
- {
- printf(" watchlist\n");
- }
- if(select==3)
- {
- printf("-> stock list\n");
- }
- else
- {
- printf(" stock list\n");
- }
- if(select==4)
- {
- printf("-> account\n");
- }
- else
- {
- printf(" account\n");
- }
- if(select ==5)
- {
- printf("-> Transaction Histroy\n");
- }
- else
- {
- printf(" Transaction histroy\n");
- }
- if(select==6)
- {
- printf("-> EXIT\n");
- }
- else
- {
- printf(" EXIT\n");
- }
- printf("Use the Arrow key's to move and select\n");
- switch(_getch())
- {
- case 'H':
- select--;
- // goto user_sec;
- break;
- case 'P':
- select++;
- // goto user_sec;
- break;
- case 13:
- if(select!=6)
- {
- user_choice(select,users);;
- }
- else
- {
- loop=0;
- }
- break;
- }
- }
- }
- void user_choice(int choice,char *Name)
- {
- if(choice==1)
- portfolio(Name);
- else if(choice==2)
- watch_list(Name);
- else if(choice==3)
- stock_list(Name);
- else if(choice==4)
- my_Account(Name);
- else if(choice==5)
- trans_sec(Name);
- }
- void trans_sec(char* Name)
- {
- }
- void watch_list(char* Name)
- {
- }
- void stock_list(char *Name)
- {
- system("cls");
- FILE*fp,*fp1;
- char x;
- list_t *collection=(list_t*)malloc(sizeof(list_t)*5);
- int i,arrow=0;
- if((fp1=fopen("COMPANY_DATA.txt","r"))==NULL)
- {
- fp1=fopen("COMPANY_DATA.txt","w");
- 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$";
- i=0;
- while(data[i]!='\0')
- {
- x=data[i];
- fputc(x,fp1);
- i++;
- }
- fclose(fp1);
- }
- fp=fopen("COMPANY_DATA.txt","r+");
- i=0;
- char all[10000];
- while((x = fgetc(fp)) != EOF)
- {
- all[i++] = x;
- }
- all[i] = '\0';
- int prev=4,page=0;
- while(1)
- {
- system("cls");
- inserting_the_data(collection,all,prev,page,i);
- prev=page;
- printf(" <<<<<<<<<<<<<<<<<<<Stock list>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n");
- printf("COMPANY_NAME ||STARTING_PRICE || VOLUME || MARKET ");
- printf("\n%s|%d|%d|%d",collection[0].name,collection[0].start_price,collection[0].volume,collection[0].market);if(arrow==0)printf("<-");
- printf("\n%s|%d|%d|%d",collection[1].name,collection[1].start_price,collection[1].volume,collection[1].market);if(arrow==1)printf("<-");
- printf("\n%s|%d|%d|%d",collection[2].name,collection[2].start_price,collection[2].volume,collection[2].market);if(arrow==2)printf("<-");
- printf("\n%s|%d|%d|%d",collection[3].name,collection[3].start_price,collection[3].volume,collection[3].market);if(arrow==3)printf("<-");
- printf("\n%s|%d|%d|%d",collection[4].name,collection[4].start_price,collection[4].volume,collection[4].market);if(arrow==4)printf("<-");
- x=_getch();
- switch(x)
- {
- case 72:arrow--;
- break;
- case 80:arrow++;
- break;
- case 75:page--;
- break;
- case 77:page++;
- break;
- case 13:view_stock(collection,arrow);
- }
- if(arrow>4 ||arrow<0)
- {arrow=0;}
- if(page>3 ||page<0)
- {page=0;
- arrow =0;}
- }
- }
- int calcu_eps(int capital,int shares)
- {
- int out_stan_shares=shares;
- return capital/out_stan_shares-14;
- }
- int calcu_pe(int price,int eps)
- {
- return eps/price;
- }
- int calcu_Div(int price)
- {
- int dividend_yield=7;
- return price/dividend_yield;
- }
- void view_stock(list_t*Data,int choice)
- {
- int EPS,PE,Dividend;
- EPS=calcu_eps(Data[choice].market,Data[choice].volume);
- PE=calcu_pe(Data[choice].start_price,EPS);
- Dividend=calcu_Div(Data[choice].start_price);
- system("cls");
- printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<View Stock>>>>>>>>>>>>>>>>>>>>>\n\n");
- printf("<<<<<<<<<<<<<<<<<<<<<<<<Company Details>>>>>>>>>>>>>>>>>>>>\n");
- printf("\t\t\t\t\tFundamentals Analysis\n");
- printf("Name:%s \t\t\t\t",Data[choice].name); printf("EPS:%d\n",EPS);
- printf("No.of.Shares:%d \t\t\t",Data[choice].volume); printf("PE :%d\n",PE);
- printf("Starting price:%d\t\t\t",Data[choice].start_price); printf("Dividend:%d\n",Dividend);
- printf("Market Capital:%d\n",Data[choice].market);
- _getch();
- }
- void inserting_the_data(list_t *collect,char*Data,int prev,int cur,int range)
- {
- int idx=0,position=0;
- if(cur==0 && prev!=cur)
- {
- insert(collect,Data,cur+1);
- }
- else if(cur==1 && prev!=cur)
- {
- position=cur*5;
- while(position--)
- {
- while(Data[idx]!='$')
- {idx++;}
- idx+=2;
- }
- insert(collect,Data,idx);
- }
- else if(cur==2 && prev!=cur)
- {
- position=10;
- while(position--)
- {
- while(Data[idx]!='$')
- {idx++;}
- idx+=2;
- }
- insert(collect,Data,idx);
- }
- else if(cur==3 && prev!=cur)
- {
- position=15;
- while(position--)
- {
- while(Data[idx]!='$')
- {idx++;}
- idx+=2;
- }
- insert(collect,Data,idx);
- }
- }
- void insert(list_t *collect,char *Data,int pos)
- {
- int count=5,idx=0,range=0;
- char temp[100]={0};
- while(range<count)
- {
- idx=0;
- while(Data[pos]!='#')
- {
- temp[idx++]=Data[pos];
- pos++;
- }
- temp[idx]='\0';
- pos++;
- strcpy(collect[range].name,temp);
- idx=0;
- while(Data[pos]!='#')
- {
- temp[idx]=Data[pos++];
- idx++;
- }
- temp[idx]='\0';
- collect[range].start_price=char_to_int(temp);
- idx=0;
- pos++;
- while(Data[pos]!='$')
- {
- temp[idx]=Data[pos++];
- idx++;
- }
- temp[idx]='\0';
- pos+=2;
- collect[range].volume=char_to_int(temp);
- collect[range].market=((collect[range].start_price)*(collect[range].volume))*2;
- range++;
- }
- }
- void my_Account(char *Name)
- {
- printf("My Account\n\n");
- printf("Name :%s\n",Name);
- printf("Starting Investment:50,000\n");
- // printf("Stock Value :%d",);
- }
- void portfolio(char *Name)
- {
- }
- int main()
- {
- printf("WELCOME\n");
- printf(" TO \n");
- printf(" HELIX \n");
- printf("Press any Key\n");
- _getch();
- Main_page();
- return 0;
- }
- int Main_page()
- {
- FILE *fp;
- char choice,x;
- char users[100];
- char username[100];
- char password[100];
- int i=0;
- main_sec:
- system("cls");
- while(1)
- {
- fflush(stdin);
- printf("Helix\n");
- printf("1)login\n");
- printf("2)signup\n");
- printf("3)exit");
- choice=_getch();
- if(choice== 49 || choice ==50 ||choice==51)
- break;
- else
- {
- printf("\nEnter valid choice\n");
- printf("press any key\n");
- _getch();
- system("cls");
- }
- }
- if(choice==49)
- {
- char x,*tempstr;
- char accountsDB[100];
- system("cls");
- printf("Login \n");
- printf("Username:");
- scanf("%s",username);
- printf("\n");
- i=0;
- while(username[i] != '\0')
- {
- users[i] = username[i];
- i++;
- }
- users[i] = '\0';
- i=0;
- printf("Password:");
- while ((x = _getch()) != '\r')
- {
- printf("*");
- password[i++] = x;
- }
- password[i] = '\0';
- i = 0;
- strcat(username, password);
- fp = fopen("PROJECT_DATA_FILE.txt","r");
- while((x = fgetc(fp)) != EOF)
- {
- accountsDB[i++] = x;
- }
- accountsDB[i] = '\0';
- fclose(fp);
- if(NULL == strstr(accountsDB, username))
- {
- printf("\n\n"space space"*Username or password is wrong");
- _getch();
- goto main_sec;
- }
- else
- {
- tempstr = strstr(accountsDB, username);
- }
- i=0;
- while(username[i]!='\0')
- {
- if(username[i]!=tempstr[i])
- break;
- i++;
- }
- if(i==strlen(username))
- {
- userpage(users);
- goto main_sec;
- }
- else
- {
- printf("\n\n*Username or password is wrong");
- _getch();
- goto main_sec;
- }
- }
- if(choice ==50)
- {
- system("cls");
- printf("Signup\n");
- printf("Username:");
- scanf("%s",username);
- i=0;
- while((x = username[i]) != '\0')
- {
- if(x == '|' || x == '#' || x == '$')
- {
- printf("\n*Username must not contain special characters like |, #, $ etc.");
- _getch();
- goto main_sec;
- }
- i++;
- }
- char accountsDB[100];
- fp = fopen("PROJECT_DATA_FILE.txt","r");
- i = 0;
- while((x = fgetc(fp)) != EOF)
- {
- accountsDB[i++] = x;
- }
- fclose(fp);
- char temp_pass[100];
- if(NULL == strstr(accountsDB, username))
- {
- i=0;
- printf("Password:");
- while ((x = _getch()) != '\r')
- {
- printf("*");
- password[i++] = x;
- }
- password[i] = '\0';
- printf("\nRe-Enter password:");
- i = 0;
- while((x = _getch()) != '\r')
- {
- printf("*");
- temp_pass[i++] = x;
- }
- temp_pass[i]='\0';
- if(strcmp(temp_pass,password)==0)
- {
- i = 0;
- fp = fopen("PROJECT_DATA_FILE.txt","a");
- fputc('|',fp);
- while((x = username[i]) != '\0')
- {
- fputc(x,fp);
- i++;
- }
- i = 0;
- while((x = password[i]) != '\0')
- {
- fputc(x,fp);
- i++;
- }
- fputc('$', fp);
- fputc('1', fp);
- fputc('#', fp);
- fputc('1', fp);
- fclose(fp);
- printf("\n\nSign up successful");
- _getch();
- goto main_sec;
- }
- else
- {
- printf("\n\n*Passwords do not match, try again");
- _getch();
- goto main_sec;
- }
- }
- else
- {
- printf("\n*Username is already taken");
- _getch();
- goto main_sec;
- }
- }
- if(choice==51)
- {
- system("cls");
- printf("Exit\n\n");
- printf("Are You Sure Want to Exit\n");
- printf("Enter y/n\n");
- x=_getch();
- if(x=='n'||x=='N')
- goto main_sec;
- else
- {
- printf("Thank u for visiting\n");
- }
- }
- }
- int char_to_int(char*num)
- {
- int length=strlen(num);
- int var=1;
- int i,c=0,temp;
- for(i=0; i<length; i++)
- {
- if(i==0 && num[i]==45 )
- {
- var=-1;
- }
- else
- {
- temp=(num[i]-48);
- c=c*10+temp;
- }
- }
- c=c*var;
- return c;
- }
Add Comment
Please, Sign In to add comment