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<graphics.h>
- #include<time.h>
- #define space "\t \t \t"
- static int up_price=0;
- static int ind_pos=0;
- typedef struct cmp_data
- {
- char name[100];
- char start_price[100];
- char volume[100];
- char market[100];
- } cmp_data;
- typedef struct account_details
- {
- char name[100];
- int investement;
- int available_cash;
- int stock_value;
- int total_transaction;
- } account_details;
- typedef struct user_details
- {
- char username[100];
- void *portfolio;
- void *watch_list;
- account_details *account;
- void *trans_his;
- } user_details;
- typedef struct record
- {
- char cmp_name[100];
- int no_of_share;//buyed
- char volume[100];//no of shares total present.
- int buy_price;
- int pos;
- int selling_price;
- int percentage;//profit or loss gain
- char market_capital[100];
- char buy_time[40];
- char sell_time[40];
- int cash;//recived or given for shares;
- struct record*next;//next pointer to create new record;
- } record;
- int array[20]= {0};
- void status();
- int check_quantity_available(char *requested,char *available);
- void updating_funds(user_details*file,int cmp_num,int shares);
- int check_funds(char *quantity,int number,long long int cash);
- int check_quantity(char *quantity);
- void buy_section(int cmp_num,user_details* file);
- void updating_point();
- void signup_page();
- int* whole_data(int st_price,int page,int CURRENT,int *length);
- void fun_graph(int *data,int len,int st_price);
- void graph_coordinates(int *prev_data,int len,int st_price);
- void view_stock(cmp_data*Data,int current,int page,user_details*file);
- void graph_section(char *name,char* shares,char* st_price,int page,int CURRENT);
- void *myThreadFun(void *id);
- char *int_char(int src);
- void login_page();
- int char_to_int(char*num);
- void user_choice(int choice,char *Name,user_details *file);
- void userpage(char *username);
- void welcome_page(char *username);
- int Main_page();
- void insert_into_record(cmp_data*collect,char *Data,int pos);
- void arrow_fun(int exp,int act);
- void printf_sec(char *data);
- void printf_name(char *name);
- int calcu_eps(char* capital,char* shares);
- int calcu_pe(char*price,int eps);
- int calcu_Div(char* price);
- COORD coord= {0,0};
- void gotoxy(int x,int y)
- {
- coord.X=x;
- coord.Y=y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
- }
- user_details* create_user_info(char *username)
- {
- user_details *rcd=(user_details*)malloc(1*sizeof(user_details));
- strcpy(rcd->username,username);
- account_details *poin=(account_details*)malloc(1*sizeof(account_details));
- strcpy(poin->name,username);
- printf("Name:%s\n",poin->name);
- _getch();
- poin->investement=500000;
- poin->available_cash=500000;
- poin->stock_value=0;
- poin->total_transaction=0;
- rcd->account=poin;
- rcd->portfolio=NULL;
- rcd->trans_his=NULL;
- rcd->watch_list=NULL;
- return rcd;
- }
- user_details* checking_user_details(char *username)
- {
- FILE *FP,*FP_1,*FP_2;
- if((FP=fopen("User_Details.txt","r"))==NULL)
- {
- FP_1=fopen("User_Details.txt","w");
- user_details *rcd=create_user_info(username);
- fwrite(rcd,sizeof( *rcd),1,FP_1);
- return rcd;
- }
- /* user_details demo;
- while(fread(&demo,sizeof(user_details),1,FP))
- {
- if(strcmp(demo.username,username)==0)
- return demo;
- }*/
- FP_1=fopen("User_Details.txt","a");
- user_details *rcd;
- rcd=create_user_info(username);
- fwrite(rcd,sizeof(*rcd),1,FP_1);
- return rcd;
- }
- void *myThreadFun(void *id)
- {
- FILE * fp_3=fopen("Prices_list.txt","a+");
- char *str;
- time_t t;
- int random_1,idx,count=20;
- random_1 =idx=0;
- while(count--)
- {
- srand((unsigned) time(&t));
- random_1=rand()%10;
- Sleep(1000);
- if(random_1 == count)
- {
- if(random_1%2==0)
- str=int_char(random_1*2);
- else
- str=int_char(random_1*2*-1);
- }
- else
- {
- if(random_1%2!=0)
- str=int_char(random_1);
- else
- str=int_char(random_1*-1);
- }
- while(str[idx]!='\0')
- {
- fputc(str[idx],fp_3);
- idx++;
- }
- if(idx==0)
- {
- fputc('0',fp_3);
- }
- fputc('#',fp_3);
- idx=0;
- }
- fputc('$',fp_3);
- up_price++;
- printf("\n\n");
- printf(space space space"Press any key");
- fclose(fp_3);
- }
- int main()
- {
- printf("\n\n\n\n\n");
- printf(space "\tWELCOME\n");
- printf(space "\t TO \n");
- printf(space "\t HELIX \n");
- printf(space"\tPress any Key\n");
- _getch();
- Main_page();
- return 0;
- }
- void login_page()
- {
- FILE *fp;
- updating_point();
- char x,*tempstr;
- char accountsDB[100],username[100],password[100],users[100];
- system("cls");
- printf("\n\n\n\n");
- printf(space space "<<<<<<<<<<<<<<Login>>>>>>>>>>>> \n\n");
- 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);
- printf("\n"space "\t\tUsername : %c %c\n",179,179);
- 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);
- gotoxy(52,10);
- scanf("%s",username);
- printf("\n");
- int idx=0;
- while(username[idx] != '\0')
- {
- users[idx] = username[idx];
- idx++;
- }
- users[idx] = '\0';
- idx=0;
- 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);
- printf("\n"space "\t\tPassword : %c %c\n",179,179);
- 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);
- gotoxy(52,16);
- while ((x = _getch()) != '\r')
- {
- printf("*");
- password[idx++] = x;
- }
- password[idx] = '\0';
- idx = 0;
- strcat(username, password);
- fp = fopen("PROJECT_DATA_FILE.txt","r");
- while((x = fgetc(fp)) != EOF)
- {
- accountsDB[idx++] = x;
- }
- accountsDB[idx] = '\0';
- fclose(fp);
- if(NULL == strstr(accountsDB, username))
- {
- printf("\n\n"space"*Username or password is wrong\n");
- goto end_login;
- }
- else
- {
- tempstr = strstr(accountsDB, username);
- }
- idx=0;
- while(username[idx]!='\0')
- {
- if(username[idx]!=tempstr[idx])
- break;
- idx++;
- }
- if(idx==strlen(username))
- {
- userpage(users);
- goto end_login;
- }
- else
- {
- printf("\n\n"space"*Username or password is wrong\n");
- end_login:
- printf(space "\n"space"press any key\n");
- _getch();
- }
- }
- void userpage(char *username)
- {
- welcome_page(username);
- user_details *file=checking_user_details(username);
- int select=1,loop=1;
- user_sec:
- system("color 03");
- while(loop)
- {
- updating_point();
- if(select>7 ||select==0)
- {
- select =1;
- }
- system("cls");
- printf("\n\n\n\n");
- printf(space "<<<HELIX GUIDE>>>\n");
- arrow_fun(1,select);
- printf("HELP\n");
- arrow_fun(2,select);
- printf("PORTFOLIO\n");
- arrow_fun(3,select);
- printf("WATCH LIST\n");
- arrow_fun(4,select);
- printf("STOCK LIST\n");
- arrow_fun(5,select);
- printf("ACCOUNT\n");
- arrow_fun(6,select);
- printf("TRANSACTION HISTROY\n");
- arrow_fun(7,select);
- printf("EXIT\n");
- printf(space"Use the Arrow key's to move and select\n");
- switch(_getch())
- {
- case 'H':
- select--;
- break;
- case 'P':
- select++;
- break;
- case 13:
- if(select!=7)
- {
- user_choice(select,username,file);
- }
- else
- {
- loop=0;
- }
- break;
- }
- }
- }
- void Help_sec(char *Name)
- {
- updating_point();
- printf("\n");
- system("cls");
- printf(space"<<<<<<<<<<<<<<<<Help_sec>>>>>>>>>>>>>>>>>>>>>>\n\n");
- printf("->Helix is an virtual Trading app\n");
- printf("->Which is based on Equity share's\n");
- printf(" <<<<Company Details>>>>>\n");
- printf("->Company Name=XYZ\n");
- printf("->Volume=No of shares available\n");
- printf("->Starting price=Starting price of each share\n");
- printf("->Market Capital=Total turn over capital of the company\n");
- printf(" <<<<<Fundamental Details>>>>>>\n");
- printf("->EPS=Earning per share\n");
- printf("->It is used to determine company stock Condition\n");
- printf("->Its supply and Demand in the market\n");
- printf("->if eps<=26 then its is consider at under value share\n");
- printf("->if eps >26 then it is consider at over value share\n");
- printf("->PE ratio=Price Earnings\n");
- printf("->It is used to determine company financial condition\n");
- printf("->If its below 14 it is consider as good\n");
- printf("->Dividend=Payed by the comapny\n");
- printf("->To those who hold there company share for long term \n");
- printf("->Min range =1 year to max=unlimited as long the company exists in the market\n");
- printf("->Graph section \n");
- printf("->It is used to show the company Finanial condition\n");
- printf("->Its previous performance ,also used to calculate the technical analysis\n");
- printf(space"Press any key\n");
- _getch();
- }
- void portfolio(char *Name,user_details *file)
- {
- system("cls");
- printf("\n\n\n");
- printf(space"<<<<<<<<<<<<<<<<<<portfolio>>>>>>>>>>>>>>>>>>>\n\n");
- if(file->portfolio==NULL)
- {
- printf(space " COMPANY_NAME || Shares || Cur_price || Buy_priced \n\n" );
- printf(space " NULL || NULL || NULL || NULL \n");
- }
- else
- {
- char x;
- int loop=1,arrow=0,total=1,time=0;
- while(loop)
- {
- system("cls");
- printf(space " COMPANY_NAME || Shares || Cur_price || Buy_priced \n\n" );
- record *cur=(record*)file->portfolio;
- while(cur!=NULL)
- {
- arrow_fun(time,arrow);
- printf_name(cur->cmp_name);
- printf_sec(int_char(cur->no_of_share));
- printf(" %d ",array[cur->pos]);
- printf_sec(int_char(cur->buy_price));
- printf("\n");
- cur=cur->next;
- time++;
- }
- total=time+1;
- time=0;
- arrow_fun(total,arrow);
- printf("Go back\n");
- printf(space"Use the arrow keys\n");
- fflush(stdin);
- x=_getch();
- switch(x)
- {
- case 72:
- printf("dec\n");
- arrow--;
- break;
- case 80:
- printf("inc\n");
- arrow++;
- break;
- case 13:
- loop=0;
- break;
- }
- printf("arrow =%d",arrow);
- _getch();
- }
- }
- printf(space "Press any key\n");
- _getch();
- }
- void status()
- {
- printf(space"Will be added Soon\n");
- printf(space"Press any key\n");
- _getch();
- }
- void watch_list(char *Name,user_details *file)
- {
- system("cls");
- printf("\n\n\n\n");
- printf(space"<<<<<<<<<<<<<<<<<<Watch List>>>>>>>>>>>>>>>>>>>\n\n");
- status();
- }
- void inserting_the_data(cmp_data *collect,char*Data,int prev,int cur)
- {
- int idx=0,position=0;
- if(cur==0 && prev!=cur)
- {
- insert_into_record(collect,Data,cur+1);
- }
- else if(cur==1 && prev!=cur)
- {
- position=cur*5;
- while(position--)
- {
- while(Data[idx]!='$')
- {
- idx++;
- }
- idx+=2;
- }
- insert_into_record(collect,Data,idx);
- }
- else if(cur==2 && prev!=cur)
- {
- position=10;
- while(position--)
- {
- while(Data[idx]!='$')
- {
- idx++;
- }
- idx+=2;
- }
- insert_into_record(collect,Data,idx);
- }
- else if(cur==3 && prev!=cur)
- {
- position=15;
- while(position--)
- {
- while(Data[idx]!='$')
- {
- idx++;
- }
- idx+=2;
- }
- insert_into_record(collect,Data,idx);
- }
- }
- void insert_into_record(cmp_data *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;
- temp[100]= {0};
- while(Data[pos]!='#')
- {
- temp[idx]=Data[pos++];
- idx++;
- }
- temp[idx]='\0';
- strcpy(collect[range].start_price,temp);
- idx=0;
- temp[100]= {0};
- pos++;
- while(Data[pos]!='$')
- {
- temp[idx]=Data[pos++];
- idx++;
- }
- temp[idx]='\0';
- pos+=2;
- strcpy(collect[range].volume,temp);
- temp[100]= {0};
- char *str=int_char((char_to_int(collect[range].start_price))*(char_to_int(collect[range].volume))*2);
- strcpy(collect[range].market,str);
- range++;
- }
- }
- void stock_list(char *Name,user_details *file)
- {
- system("cls");
- FILE*fp=fopen("COMPANY_DATA.txt","r+");
- char x,cmp_details[1000];
- cmp_data *page_list =(cmp_data*)malloc(sizeof(cmp_data)*5);
- int idx=0,arrow=0;
- while((x = fgetc(fp)) != EOF)
- {
- cmp_details[idx++] = x;
- }
- cmp_details[idx] = '\0';
- int prev_page=4,cur_page=0,loop=1;
- while(loop)
- {
- system("cls");
- system("color f3");
- inserting_the_data(page_list,cmp_details,prev_page,cur_page);
- prev_page=cur_page;
- printf("\n\n <<<<<<<<<<<<<<<<<<<<<<<<<<<<Stock List>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
- printf(space"Company Name ||Starting price || Cur_price || Volume || MARKET \n");
- arrow_fun(0,arrow);
- printf_name(page_list[0].name);
- printf_sec(page_list[0].start_price);
- printf("%d ",array[(5*cur_page)+0]);
- printf_sec(page_list[0].volume);
- printf_sec(page_list[0].market);
- printf("\n");
- arrow_fun(1,arrow);
- printf_name(page_list[1].name);
- printf_sec(page_list[1].start_price);
- printf("%d ",array[(5*cur_page)+1]);
- printf_sec(page_list[1].volume);
- printf_sec(page_list[1].market);
- printf("\n");
- arrow_fun(2,arrow);
- printf_name(page_list[2].name);
- printf_sec(page_list[2].start_price);
- printf("%d ",array[(5*cur_page)+2]);
- printf_sec(page_list[2].volume);
- printf_sec(page_list[2].market);
- printf("\n");
- arrow_fun(3,arrow);
- printf_name(page_list[3].name);
- printf_sec(page_list[3].start_price);
- printf("%d ",array[(5*cur_page)+3]);
- printf_sec(page_list[3].volume);
- printf_sec(page_list[3].market);
- printf("\n");
- arrow_fun(4,arrow);
- printf_name(page_list[4].name);
- printf_sec(page_list[4].start_price);
- printf("%d ",array[(5*cur_page)+4]);
- printf_sec(page_list[4].volume);
- printf_sec(page_list[4].market);
- printf("\n");
- arrow_fun(5,arrow);
- printf("BACK\n");
- printf(space "use the arrow keys to turn pages and for selecting stock\n");
- printf(space "press enter for selecting\n");
- printf("\n\n\n"space space"Page:%d\n",cur_page);
- x=_getch();
- switch(x)
- {
- case 72:
- arrow--;
- break;
- case 80:
- arrow++;
- break;
- case 75:
- cur_page--;
- break;
- case 77:
- cur_page++;
- break;
- case 13:
- if(arrow==5)
- loop=0;
- else
- view_stock(page_list,arrow,cur_page,file);
- }
- if(arrow>5 ||arrow<0)
- {
- arrow=0;
- }
- if(cur_page>3 ||cur_page<0)
- {
- cur_page=0;
- arrow =0;
- }
- }
- }
- int calcu_eps(char* capital,char* shares)
- {
- int out_stan_shares=char_to_int(shares);
- return char_to_int(capital)/out_stan_shares-14;
- }
- int calcu_pe(char*price,int eps)
- {
- return eps/char_to_int(price);
- }
- int calcu_Div(char* price)
- {
- int dividend_yield=7;
- return char_to_int(price)/dividend_yield;
- }
- void updating_point()
- {
- char Data[1000],x,max[3];
- int i,pos=0,in=0,count=0,idx=0;
- FILE *fp1,*fp;
- 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);
- }
- if(ind_pos==0)
- {
- int new_arr[20]= {20,10,15,17,20,35,25,45,15,40,33,27,21,77,13,39,61,69,77,55};
- for(idx=0; idx<20; idx++)
- {
- array[idx]=new_arr[idx];
- }
- }
- if(ind_pos<up_price)
- {
- fp=fopen("Prices_list.txt","a+");
- idx= pos=in=count =0;
- x='k';
- while(count<ind_pos)
- {
- x=fgetc(fp);
- if(x=='$')
- {
- count++;
- }
- }
- count=0;
- if(ind_pos!=0)
- {
- x='k';
- }
- while(x!='$')
- {
- x=fgetc(fp);
- Data[idx]=x;
- idx++;
- }
- Data[idx]='\0';
- while(in<idx)
- {
- in++;
- while(Data[in]!='#' && Data[in]!='$')
- {
- max[pos++]=Data[in];
- in++;
- }
- if(Data[in]=='$')
- {
- in++;
- }
- else
- {
- if(pos==0)
- {
- max[pos++]='0';
- }
- max[pos]='\0';
- pos=0;
- array[count]+=char_to_int(max);
- count++;
- }
- }
- ind_pos++;
- pthread_t tid_2;
- pthread_create(&tid_2, NULL, myThreadFun, (void*)1);
- }
- }
- void view_stock(cmp_data*Data,int current,int page,user_details *file)
- {
- char x;
- int EPS,PE,Dividend,choice=0,loop=1;
- EPS=calcu_eps(Data[current].market,Data[current].volume);
- PE=calcu_pe(Data[current].start_price,EPS);
- Dividend=calcu_Div(Data[current].start_price);
- while(loop)
- {
- system("cls");
- system("color 04");
- updating_point();
- printf("\n\n");
- printf(space"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<View Stock>>>>>>>>>>>>>>>>>>>>>\n\n");
- printf(space"<<<<<<<<<<<<<<<<<<<<<<<<Company Details>>>>>>>>>>>>>>>>>>>>\n");
- printf(space"\t\t\t\t\tFundamentals Analysis\n");
- printf(space"Name:%s \t\t\t\t",Data[current].name);
- printf(space"EPS:%d\n",EPS);
- printf(space"No.of.Shares:%s \t\t\t",Data[current].volume);
- printf(space"PE :%d\n",PE);
- printf(space"Starting price:%s\t\t\t",Data[current].start_price);
- printf(space"Dividend:%d\n",Dividend);
- printf(space"Market Capital:%s\n",Data[current].market);
- printf(space"Current Price:%d\n",array[(5*page)+current]);
- printf(space"\n\n\n"space);
- arrow_fun(0,choice);
- printf("View current graph\n"space);
- arrow_fun(1,choice);
- printf("Buy Option\n");
- arrow_fun(2,choice);
- printf("Go back\n");
- x= _getch();
- switch(x)
- {
- case 'H':
- choice--;
- break;
- case 'P':
- choice++;
- break;
- case 13:
- if(choice==2)
- loop=0;
- else if(choice==0)
- {
- graph_section(Data[current].name,Data[current].volume,Data[current].start_price,page,current);
- }
- else if(choice==1)
- {
- buy_section((page*5)+current,file);
- }
- }
- if(choice<0 ||choice>2)
- {
- choice=2;
- }
- }
- }
- void buy_section(int cmp_num,user_details*file)
- {
- int flag=0;
- system("cls");
- set_up:
- if(flag==0)
- {
- FILE *fp;
- fp=fopen("COMPANY_DATA.txt","r");
- char data[1000],x;
- int idx=0,pos=0,cur_pos=0,last_pos=0;
- while((x = fgetc(fp)) != EOF)
- {
- data[idx++] = x;
- }
- data[idx]='\0';
- fclose(fp);
- idx=0;
- while(pos<cmp_num && data[idx]!='\0')
- {
- if(data[idx]=='$')
- {
- pos++;
- }
- idx++;
- }
- pos=0;
- cur_pos=idx;
- char temp_data[100],cmp_name[100],shares[100];
- idx++;
- while(data[idx]!='$')
- {
- temp_data[pos]=data[idx++];
- pos++;
- }
- last_pos=idx;
- temp_data[pos]='\0';
- idx=pos=0;
- while(temp_data[idx]!='#')
- {
- cmp_name[idx]=temp_data[idx];
- idx++;
- }
- cmp_name[idx++]='\0';
- char str_pric[100];
- while(temp_data[idx]!='#')
- {
- str_pric[pos++]=temp_data[idx++];
- }
- str_pric[pos]='\0';
- pos=0;
- idx++;
- while(temp_data[idx]!='\0')
- {
- shares[pos]=temp_data[idx++];
- pos++;
- }
- shares[pos]='\0';
- account_details *sec;
- char quantity[100];
- sec=file->account;
- system("cls");
- printf(space "<<<<<<<<<<<<<<<<<<<Buy Section>>>>>>>>>>>>>>>>>>>\n\n");
- printf(space "Compaany Name:%s\n",cmp_name);
- printf(space "Company Shares:%s\n",shares);
- printf(space "Current Price:%d\n",array[cmp_num]);
- printf(space "Available Funds :%d\n",sec->available_cash);
- printf(space "Buy Quantity:");
- scanf("%s",quantity);
- if(check_quantity(quantity)==0)
- {
- flag++;
- goto set_up;
- }
- if(check_quantity_available(quantity,shares)==0)
- {
- flag++;
- goto set_up;
- }
- if(check_funds(quantity,cmp_num,sec->available_cash)==0)
- {
- flag++;
- goto set_up;
- }
- char *s;
- int len=0;
- while(len!=25)
- {
- time_t t;
- time(&t);
- s=ctime(&t);
- len=strlen(s);
- }
- record *set=(record*)malloc(1*sizeof(record));
- set->buy_price=array[cmp_num];
- strcpy(set->cmp_name,cmp_name);
- set->no_of_share=char_to_int(quantity);
- strcpy(set->volume,shares);
- set->cash=char_to_int(quantity)*array[cmp_num];
- set->next=NULL;
- set->pos=cmp_num;
- strcpy(set->buy_time,s);
- if(file->portfolio==NULL)
- {
- file->portfolio=malloc(sizeof(record));
- file->portfolio=set;
- printf(space"first\n");
- }
- else
- {
- record *list=(record*)file->portfolio;
- while(list->next!=NULL)
- {
- list=list->next;
- }
- list->next=set;
- printf(space "Inserted\n");
- }
- updating_funds(file,cmp_num,char_to_int(quantity));
- flag=1;
- idx=0;
- printf(space"Current cash %d\n",sec->available_cash);
- fp=fopen("Company_data.txt","w");
- while(idx<cur_pos)
- {
- x=data[idx];
- fputc(x,fp);
- idx++;
- }
- idx=0;
- fputc('|',fp);
- while(cmp_name[idx]!='\0')
- {
- x=cmp_name[idx++];
- fputc(x,fp);
- }
- idx=0;
- fputc('#',fp);
- while(str_pric[idx]!='\0')
- {
- x=str_pric[idx++];
- fputc(x,fp);
- }
- idx=0;
- fputc('#',fp);
- char *new_quantity=int_char(char_to_int(shares)-char_to_int(quantity));
- while(new_quantity[idx]!='\0')
- {
- x=new_quantity[idx++];
- fputc(x,fp);
- }
- idx=last_pos;
- while(data[idx]!='\0')
- {
- x=data[idx++];
- fputc(x,fp);
- }
- fclose(fp);
- printf(space "Your Order is Succesfully Placed\n");
- _getch();
- }
- else
- {
- printf(space"Press any Key\n");
- _getch();
- }
- }
- int check_quantity_available(char *requested,char *available)
- {
- if(char_to_int(requested)<=char_to_int(available))
- return 1;
- else
- {
- printf(space "Requested quantity Not available\n");
- return 0;
- }
- }
- void updating_funds(user_details*file,int cmp_num,int shares)
- {
- account_details*sec=file->account;
- long long int cur=sec->available_cash;
- cur=cur-(array[cmp_num]*shares);
- sec->available_cash=cur;
- }
- int check_funds(char *quantity,int number,long long int cash)
- {
- long long int shares=char_to_int(quantity);
- if((shares*array[number])<cash)
- return 1;
- else
- return 0;
- }
- int check_quantity(char *quantity)
- {
- int idx=0;
- while(quantity[idx]!='\0')
- {
- if(quantity[idx]>47 && quantity[idx]<58)
- {
- idx++;
- }
- else
- {
- printf(space "Enter only Numbers\n");
- return 0;
- }
- }
- return 1;
- }
- int* whole_data(int st_price,int page,int CURRENT,int *length)
- {
- FILE *fp;
- char x='k',Data[10000],max_array[3];
- fp=fopen("Prices_list.txt","a+");
- int pos=0,index=0,new_arr[1000],price=0,var=(5*page)+CURRENT,value=0;
- while(value<ind_pos)
- {
- index=0;
- while(x!='$')
- {
- x=fgetc(fp);
- Data[index]=x;
- index++;
- }
- Data[index]='\0';
- int cur=0,low=0;
- while(cur!=var && low<index)
- {
- if(Data[low]=='#')
- {
- cur++;
- }
- low++;
- }
- cur=0;
- while(Data[low]!='#')
- {
- max_array[cur++]=Data[low];
- low++;
- }
- max_array[cur]='\0';
- int v;
- v=char_to_int(max_array);
- new_arr[value]=v;
- value++;
- pos++;
- x='k';
- }
- int *r=&value;
- *length=*r;
- return new_arr;
- }
- void graph_section(char *name,char* shares,char* st_price,int page,int CURRENT)
- {
- system("cls");
- int len,*data;
- data=whole_data(char_to_int(st_price),page,CURRENT,&len);
- int gd = DETECT,gm;
- initgraph(&gd, &gm, "C:\\TC\\BGI");
- setcolor(YELLOW);
- settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
- setcolor(WHITE);
- outtextxy(275,0,"Graph Section");
- outtextxy(50,20,"Name :");
- outtextxy(120,20,name);
- outtextxy(50,40,"Shares :");
- outtextxy(120,40,shares);
- outtextxy(450,40,"Cur_price :");
- outtextxy(545,40,int_char(array[(5*page)+CURRENT]));
- line(0,60,639,60);
- if(len==0)
- {
- outtextxy(10,430-char_to_int(st_price),st_price);
- line(10,430,10,430-char_to_int(st_price));
- }
- else
- {
- fun_graph(data,len,char_to_int(st_price));
- }
- line(0,430,639,430);
- outtextxy(150,440,"Press any Key");
- _getch();
- closegraph();
- }
- void fun_graph(int *data,int len,int st_price)
- {
- graph_coordinates(data,len,st_price);
- int add=0;
- if(len<2)
- {
- add=2;
- }
- int dist =600/(len+add);
- int idx=0,range=len+1;
- char *str=int_char(st_price);
- int x1=10,x2=10,y1=430,y2=430-st_price;
- while(idx<range)
- {
- outtextxy(x2,y2,str);
- line(x1,y1,x2,y2);
- x1=x2;
- y1=y2;
- x2=x2+dist;
- y2=430-data[idx]-10;
- str=int_char(data[idx]);
- idx++;
- }
- }
- void graph_coordinates(int *prev_data,int len,int st_price)
- {
- int idx,cur=st_price;
- int *data=(int*)malloc(len*sizeof(int));
- for(idx=0; idx<len; idx++)
- {
- data[idx]=prev_data[idx];
- cur+=data[idx];
- data[idx]=cur;
- if(data[idx]<0)
- {
- data[idx]=0;
- cur=0;
- }
- }
- cur=0;
- int pos=0,diff=0;
- for(idx=0; idx<len; idx++)
- {
- if(data[idx]>360)
- {
- cur=data[idx]-360+2;
- pos=idx;
- data[idx]-=cur;
- while(pos--)
- {
- diff=data[pos+1]-data[pos];
- if(diff>=cur)
- {
- pos=0;
- }
- else
- {
- data[pos]-=cur;
- }
- }
- }
- }
- for(idx=0; idx<len; idx++)
- {
- prev_data[idx]=data[idx];
- }
- }
- void printf_sec(char *data)
- {
- int len=strlen(data);
- printf("%s",data);
- if(len<12)
- {
- while(len<12)
- {
- printf(" ");
- len++;
- }
- }
- }
- void printf_name(char *name)
- {
- int len=strlen(name);
- printf("%s",name);
- if(len<25)
- {
- while(len<25)
- {
- printf(" ");
- len++;
- }
- }
- }
- void my_Account(char *Name,user_details *file)
- {
- system("cls");
- printf("\n\n\n\n");
- printf(space"<<<<<<<<<<<<<<<<<<My Account>>>>>>>>>>>>>>>>>>>\n\n");
- status();
- }
- void trans_sec(char *Name,user_details* file)
- {
- system("cls");
- printf("\n\n\n\n");
- printf(space"<<<<<<<<<<<<<<<<<<Transaction Histroy>>>>>>>>>>>>>>>>>>>\n\n");
- status();
- }
- void user_choice(int choice,char *Name,user_details* file)
- {
- if(choice==1)
- Help_sec(Name);
- else if(choice==2)
- portfolio(Name,file);
- else if(choice==3)
- watch_list(Name,file);
- else if(choice==4)
- stock_list(Name,file);
- else if(choice==5)
- my_Account(Name,file);
- else if(choice==6)
- trans_sec(Name,file);
- }
- void arrow_fun(int exp,int act)
- {
- if(exp==act)
- printf(space"->");
- else
- printf(space" ");
- }
- void welcome_page(char *username)
- {
- system("color f9");
- system("cls");
- printf("\n\n\n\n\n\n");
- printf(space"<<<<<<<<<<<<<<<<<<<<<Welcome Page>>>>>>>>>>>>>>>>>>>>>>\n\n");
- printf(space "Welcome to HELIX %s\n",username);
- printf("\n");
- printf(space "If you are new to HELIX \n");
- printf(space" Go to the Help Section First\n");
- printf(space"Other's wise carry on\n");
- printf(space"Press any key\n");
- _getch();
- system("cls");
- }
- int Main_page()
- {
- FILE *fp;
- char choice,x;
- char users[100];
- char username[100];
- char password[100];
- int i=0;
- main_sec:
- while(1)
- {
- fflush(stdin);
- system("cls");
- printf("\n\n\n\n\n");
- printf(space "Helix\n");
- printf(space"1)login\n");
- printf(space"2)signup\n");
- printf(space"3)exit\n");
- printf(space"Enter Your choice\n");
- printf(space);
- choice=_getch();
- if(choice== 49 || choice ==50 ||choice==51)
- break;
- else
- {
- printf("\n"space"Enter valid choice\n");
- printf(space"press any key\n");
- _getch();
- system("cls");
- }
- }
- if(choice==49)
- {
- login_page();
- goto main_sec;
- }
- if(choice ==50)
- {
- signup_page();
- goto main_sec;
- }
- if(choice==51)
- {
- system("cls");
- printf(space"Exit\n\n");
- printf(space"Are You Sure Want to Exit\n");
- printf(space"Enter y/n\n");
- x=_getch();
- if(x=='n'||x=='N')
- goto main_sec;
- else
- {
- printf("\n"space"Thank u for visiting\n");
- }
- }
- }
- void signup_page()
- {
- FILE *fp;
- int i;
- char x,username[100],password[100];
- system("cls");
- printf("\n\n\n\n\n");
- printf(space "\t<<<<<<<<<<<<<<<<<<<Signup>>>>>>>>>>>>>>>>\n\n");
- 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);
- printf("\n"space "\t\tUsername : %c %c\n",179,179);
- 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);
- gotoxy(52,11);
- 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 signup_end;
- }
- 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("\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);
- printf("\n"space "\t\tPassword : %c %c\n",179,179);
- 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);
- gotoxy(52,14);
- while ((x = _getch()) != '\r')
- {
- printf("*");
- password[i++] = x;
- }
- password[i] = '\0';
- 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);
- printf("\n"space "\t\tPassword : %c %c\n",179,179);
- 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);
- gotoxy(52,16);
- 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\n"space space "Sign up successful\n");
- goto signup_end;
- }
- else
- {
- printf("\n\n"space space"*Passwords do not match, try again\n");
- goto signup_end;
- }
- }
- else
- {
- printf(space "\n"space"*Username is already taken\n");
- signup_end:
- printf(space "press any key\n");
- _getch();
- }
- }
- int char_to_int(char*num)
- {
- int length=strlen(num);
- int i,temp,var=1;
- long long int c=0;
- 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;
- }
- 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;
- }
- if(n==0)
- {
- string[j++]='0';
- }
- while(n!=0)
- {
- r=n%10;
- string[j++]=(r+48);
- n/=10;
- }
- if(temp==1)
- {
- string[j++]=45;
- }
- string[j]='\0';
- strrev(string);
- return string;
- }
Add Comment
Please, Sign In to add comment