-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.cpp
More file actions
executable file
·814 lines (728 loc) · 24.4 KB
/
Copy pathsql.cpp
File metadata and controls
executable file
·814 lines (728 loc) · 24.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
/*
ISHA AGARWAL
Roll No-14075063
B.Tech Part -III
Computer Science and Engineering
*/
#include <bits/stdc++.h>
using namespace std;
deque <string> q; //stores the words of the query
vector<vector<string> > v(100); //stores the results of the query
deque <string> m; //stores the words of the current inner query to be executed of nested query
vector<string> cross; //stores the attribute's names which are to be given as output
void create_table(string); //creates a new table given by user
void insert_table(string); //inserts values into a table given by user
void query(string); //processes the query given by user and prints the result
void parser_function(string); //parses the query for create and insert function
void parser_function2(string); //parses the query and decides the operation to be implemented for nested query
void select_table(); //implements select operation
void project_table(); //implements project operation
void union_table(string,int); //implements union operation
void set_diff(string,int); //implements set difference operation
void rename_table(string,int); //implements rename operation
bool checkfordot(); //checks for presence of '.' (dot) in the given string
void pushinginvector(string,int); //pushes the contents of file in v vector of vectors
void condition(string); //checks for the condition in select statement
void checkoperators(string,int,string); //checks whether condition is satisfied or not
int stoint(string); //converts string type to int type
int SIZE=0; //stores the size of v vector of vectors
int flag=0; //variable
string table_name_1,table_name_2; //stores the table names when 2 tables are used
int table_divider; //starting index for table 2 in cross vector
int dot_flag=0;
int main()
{
//sample creation and insertion in database
create_table("create table student id int name string address string branch string course_id int");
insert_table("insert into student 1 isha bhu cse 101 ");
insert_table("insert into student 2 swati bhu cse 102 ");
insert_table("insert into student 3 arya bhu mnc 202 ");
insert_table("insert into student 4 ashtha bhu ece 201 ");
insert_table("insert into student 5 kiran bhu cse 102 ");
insert_table("insert into student 6 ram bhu mnc 202 ");
insert_table("insert into student 7 vivek bhu cse 103 ");
insert_table("insert into student 8 virat bhu cse 103 ");
create_table("create table course course_id int credits int prof string");
insert_table("insert into course 101 13 akm");
insert_table("insert into course 201 11 skg");
insert_table("insert into course 102 14 rsg");
insert_table("insert into course 202 15 aps");
insert_table("insert into course 103 12 kkg");
insert_table("insert into course 103 12 kkg");
//Sample Queries
query("( select course.credits<d.credits courseX( rename d course ) )");
query("( project name course_id ( select student.course_id=course.course_id ( select branch=cse studentXcourse ) ) )");
query("( project name prof course_id ( select prof=aks ( select * studentXcourse ) ) )");
query("( ( project course_id prof ( select * course ) ) U ( project course_id prof ( select credits=13 course ) ) )");
//query("( project course_id ( select credits=13 course ) )");
query("( project course_id ( select name=arya student ) )");
query("( select credits>12 course )");
query("( ( project course_id prof ( select * course) ) - ( project course_id prof ( select credits=13 course ) ) )");
//query("( project name ( select * student ) )");
query("( select course_id>105 student )");
query("( select * course )");
//query("( select * studentXcourse )");
query("( project id name ( select branch=cse student ) )");
//query("( project id name student )");
//sql prompt for the user
string s; //stores the query given by user
do
{
cout<<"\nmysql>"; //displays the sql prompt
getline(cin,s); //takes the query from user
if (s[0]=='c') //if the first letter is 'c', user wants to create a new table
create_table(s); //calls the create function
else if(s[0]=='i') //if the first letter is 'i', user wants to insert to an existing table
insert_table(s); //calls the insert function
else
query(s); //otherwise user wants to execute the nested or simple query
}while(s!="exit");
cout<<"\nBye!"<<endl; //takes input from user until user types "exit"
return 0;
}
void query(string s)
{
parser_function2(s); //parses the query and decides the operation to be implemented
int i,j;
for(i=0;i<cross.size();i++) //prints --- to make distiction between column name and result
cout<<"--------------";
cout<<endl;
for(i=0;i<cross.size();i++) //print column/attribute name stored in cross vector
cout<<setw(15)<<left<<cross[i];
cout<<endl;
for(i=0;i<cross.size();i++) //prints --- to make distiction between column name and result
cout<<"--------------";
cout<<endl;
set<vector<string> > print_set; //stores the output in set , this deletes the duplicate tuples
for(i=0;i<=SIZE;i++)
{
if(v[i].empty()!=true)
{
print_set.insert(v[i]); //insertion in set
}
}
set<vector<string> >::iterator it;
for (it=print_set.begin(); it!=print_set.end(); it++) //prints the contents of set
{
const vector<string>& vi = (*it);
for(j=0;j<vi.size();j++)
{
cout<<setw(15)<<left<<vi[j];
}
cout<<endl;
}
}
void create_table(string s) //creates a new table
{
parser_function(s); //parses the query and stores in deque q
q.pop_front(); //pops out "create" from deque q
q.pop_front(); //pops out "table" from deque q
string table_name=q.front(); //stores the name of table to be created given by user
fstream f; //pointer to the file
f.open( table_name.c_str(),ios::out ); //creates a file with name given by user
q.pop_front(); //pops out table name given by user from dequeue q
while(!q.empty()) //dequeue is left with only attributs name and its type given by user
{
string s=q.front(); //stores the attribute name given by user
f<<s; //writes the attribute name to the file
f<<" ";
q.pop_front(); //pops out attribute name after writing it to the file
q.pop_front(); //pops out attribute type
}
f<<"\n";
f.close(); //closes the file
q.clear(); //clears the dequeue q
}
void insert_table(string s) //inserts the values in the table
{
parser_function(s); //parses the query and stores in deque q
q.pop_front(); //pops out "insert" from deque q
q.pop_front(); //pops out "into" from deque q
string table_name=q.front(); //stores the name of table in which data is to inserted
ofstream f; //pointer to the file
f.open( table_name.c_str(),ios::app ); //opens the file of the given table name in append mode
q.pop_front(); //pops out the table name from dequeue q
while(!q.empty()) //dequeue only left with values to be inserted
{
f<<q.front(); //appends the contents to the file
q.pop_front();
f<<" ";
}
f<<"\n";
f.close(); //closes the file
q.clear(); //clears the dequeue q
}
void parser_function(string s) //parses the string and pushes the words dequeue q
{
q.clear();
string temp="";
for(int i=0;i<s.length();i++)
{
if(s[i]==' ' || s[i]==',')
{
q.push_back(temp);
temp="";
}
else if(i==s.length()-1)
{
temp=temp+s[i];
q.push_back(temp);
temp="";
}
else
temp=temp+s[i];
}
}
void parser_function2(string s) //decides the operation to be implemented given by user
{
q.clear();
cross.clear();
for(int i=0;i<=SIZE;i++)
v[i].clear();
SIZE=0;
m.clear();
string temp="";
int flag=0;
size_t found=s.find("rename"); //if rename found first , call rename_table function
if(found!=string::npos)
{
flag=1;
rename_table(s,found);
}
if(flag==1)
return;
for(int i=0;i<s.length();i++)
{
if(s[i]=='U') //if union found , call union_table function
{
union_table(s,i);
flag=1;
break;
}
else if(s[i]=='-') //if set difference found, call set_diff function
{
set_diff(s,i);
flag=1;
break;
}
}
if(flag==1) return ;
for(int i=0;i<s.length();i++)
{
if(s[i]==' '|| s[i]==',')
{
if(temp.length()!=0)
q.push_back(temp);
temp="";
}
else if(s[i]==')') //if closing bracket found, pop till opening bracket is found
{
m.clear();
while(q.back()!="(")
{
string t;
t=q.back();
m.push_front(t);
q.pop_back();
}
q.pop_back();
if(m.front()=="select") //if select found , call select_table function
select_table();
else if(m.front()=="project") //if project found , call project_table function
project_table();
}
else
{
temp=temp+s[i];
}
}
}
void select_table() //implements select operation
{
string s=m.back();
string op1="X"; //cartesian product operator = 'X'
size_t foundop1=s.find(op1); //searches for cartesian product operator
if(foundop1<s.size() && s[foundop1]=='X') //if 'X' found
{
string table1=s.substr(0,s.find(op1)); //table1 to the left of 'X'
string table2=s.substr(s.find(op1)+1,s.size()-s.find(op1)); //table1 to the right of 'X'
ifstream t1,t2;
table_name_1=table1;
table_name_2=table2;
t1.open(table1.c_str(),ios::in);
t2.open(table2.c_str(),ios::in);
string head="";
getline(t1,head);
string temp="";
for(int i=0;i<head.length();i++)
{
if(head[i]==' ')
{
cross.push_back(temp); //pushing attribute names of table1
temp="";
}
else
temp=temp+head[i];
}
head="";
temp="";
getline(t2,head);
table_divider=cross.size();
for(int i=0;i<head.length();i++)
{
if(head[i]==' ')
{
cross.push_back(temp); //pushing attribute names of table2
temp="";
}
else
temp=temp+head[i];
}
t2.close();
string a,b;
int i=0;
while(!t1.eof())
{
getline(t1,a); //string a from table1 file
ifstream t3;
t3.open(table2.c_str(),ios::in);
getline(t3,b);
while(!t3.eof())
{
getline(t3,b); //string b from table2 file
if(!a.empty() && !b.empty())
{
b=a+b;
pushinginvector(b,i); //pushing attribute values of both tables in v vector of vectors
i++;
}
}
t3.close();
}
t1.close();
m.pop_back();
condition(m.back()); //checks for the condition of select statement
}
else
{
//one table only
int tr=m.size();
if(tr!=2) //not a nested query. one table only
{
string table=m.back(); //table name
m.pop_back();
string mt,temp="";
ifstream t;
t.open(table.c_str(),ios::in); //opening file of that table
getline(t,mt);
for(int i=0;i<mt.length();i++)
{
if(mt[i]==' ')
{
cross.push_back(temp); //pushing attribute names in cross vector
temp="";
}
else
temp=temp+mt[i];
}
int i=0;
while(!t.eof())
{
getline(t,mt);
if(!mt.empty())
{
pushinginvector(mt,i); //pushing attribute values in v vector of vectors
i++;
}
}
condition(m.back()); //checks for the condition of select statement
}
else if(tr==2) //nested query, so size of outer query =2
{
condition(m.back()); //checks for the condition of outer query
}
}
}
void project_table() //projects the columns given by user as output
{
if(SIZE==0) //not a nested query then SIZE=0
{
string table=m.back(); //last element is table_name
m.pop_back(); //pops out table name from back from dequeue m
m.pop_front(); //pops out "project" from front from dequeue m
ifstream t;
t.open(table.c_str(),ios::in); //opens the file of that table name for taking input
string head="";
getline(t,head);
string temp="";
for(int i=0;i<head.length();i++)
{
if(head[i]==' ')
{
cross.push_back(temp); //pushes the attribute names in cross vector
temp="";
}
else
temp=temp+head[i];
}
int ii=0;
while(!t.eof())
{
getline(t,head);
if(!head.empty())
{
pushinginvector(head,ii); //pushes attribute values in v vector of vectors
ii++;
}
}
int i,j,k;
for(i=0;i<cross.size();i++)
{
for(j=0;j<m.size();j++)
{
if(cross[i]==m.at(j)) //checks which attributes to be projected in m dequeue
break;
}
if(j==m.size()) //if not found in dequeue m
{
int index=i;
cross.erase(cross.begin() + index); //erase it from cross vector
for(k=0;k<=SIZE;k++)
if(v[k].empty()!=true) //erase all its corrresponding values from v vector of vectors
v[k].erase(v[k].begin() + index);
i=index-1;
}
}
t.close(); //closes the file
}
else //else it is a nested query
{
m.pop_front(); // pops out "project" from dequeue m
int i,j,k;
for(i=0;i<cross.size();i++) //delete the columns with duplicate names
{
for(j=i+1;j<cross.size();j++)
{
if(cross[i]==cross[j])
{
int index=j;
cross.erase(cross.begin() + index);
for(k=0;k<=SIZE;k++)
if(v[k].empty()!=true)
v[k].erase(v[k].begin() + index);
j=index-1;
}
}
}
for(i=0;i<cross.size();i++) //checks which attributes to be projected in m dequeue
{
for(j=0;j<m.size();j++)
{
if(cross[i]==m.at(j))
break;
}
if(j==m.size()) //if not found in dequeue m
{
int index=i;
cross.erase(cross.begin() + index); //erase it from cross vector
for(k=0;k<=SIZE;k++)
if(v[k].empty()!=true)
v[k].erase(v[k].begin() + index); //erase all its corrresponding values from v vector of vectors
i=index-1;
}
}
}
}
void pushinginvector(string s,int i) //pushes the contents of file in v vector of vectors
{
string temp="";
for(int j=0;j<=s.length();j++) //parses the string s
{
if(s[j]==' ' || j==s.length())
{
v[i].push_back(temp); //pushes the word in v vector of vectors
temp="";
}
else
temp=temp+s[j];
}
SIZE=i; //size of current v vector of vectors
}
void condition(string s) // s contains the condition of select statement
{
int i,index;
if(s=="*") // if s==* , no condition is present
return;
int dots=0;
int op;
int index_dot[2]={0,0};
for(i=0;i<s.length();i++)
{
if(s[i]=='.')
{
index_dot[dots]=i; //stores the index of dot
dots++; //counts the number of dots
}
if(s[i]=='=' || s[i]=='!' || s[i]=='>' || s[i]=='<') //stores the index of operator
op=i;
}
if(dots==2) // 2 dots in select condition
{ // table1.col1(operator)table2.col2 eg: table1.col1=table2.col2
string table1,table2,col1,col2;
table1=s.substr(0,index_dot[0]); //table1
col1=s.substr(index_dot[0]+1,op-index_dot[0]-1); //col1 - attribute name of table1
table2=s.substr(op+1,index_dot[1]-op-1); //table2
col2=s.substr(index_dot[1]+1,s.length()-index_dot[1]); //col2 - attribute name of table2
if(table1!=table_name_1)
{
string temp; //swapping table and column name for tables 1 and 2
temp=table2;
table2=table1;
table1=temp;
temp=col2;
col2=col1;
col1=temp;
}
int index_col1; //index of col1 in cross vector(contains attribute names)
int index_col2; //index of col2 in cross vector(contains attribute names)
for(i=0;i<cross.size();i++)
{
if(cross[i]==col1 && i<table_divider)
index_col1=i;
if(cross[i]==col2 && i>=table_divider)
index_col2=i;
}
int j;
if(s[op]=='=')
for(j=0;j<=SIZE;j++)
{
if(v[j].empty()!=true)
{
if(v[j][index_col1]!=v[j][index_col2]) //if not satisfying '=' condition [equals]
v[j].clear(); //delete that tuple
}
}
else if(s[op]=='<')
for(j=0;j<=SIZE;j++)
{
if(v[j].empty()!=true)
{
if(stoint(v[j][index_col1])>=stoint(v[j][index_col2])) //if not satisfying '<' condition [less than]
v[j].clear(); //delete that tuple
}
}
else if(s[op]=='>')
for(j=0;j<=SIZE;j++)
{
if(v[j].empty()!=true)
{
if(stoint(v[j][index_col1])<=stoint(v[j][index_col2])) //if not satisfying '>' condition [greater than]
v[j].clear(); //delete that tuple
}
}
else if(s[op]=='!')
for(j=0;j<=SIZE;j++)
{
if(v[j].empty()!=true)
{
if(stoint(v[j][index_col1])==stoint(v[j][index_col2])) //if not satisfying '!' condition [not equals]
v[j].clear(); //delete that tuple
}
}
}
else //no dots in condition
{
string col,value;
col=s.substr(0,op); //attribute name is to the left of operator
value=s.substr(op+1,s.length()-op); //value with which it is to be compared, is to the right of operator
string oper=s.substr(op,1); //stores the operator
for(i=0;i<cross.size();i++)
{
if(col==cross[i])
{
index=i; //index of attribute name in cross vector
break;
}
}
checkoperators(oper,index,value); //checks whether condition is satisfied or not in that attribute column
}
}
void checkoperators(string op,int index,string value) //checks whether condition is satisied or not
{ //op : operator
int i; //index : for which attribute column we have to check
if(op=="=") //value : value with which it is to be compared
{
for(i=0;i<=SIZE;i++)
{
if(v[i][index]!=value) //if does not satisfies the condition [equals]
v[i].clear(); //delete the tuple
}
}
else if(op=="!")
{
for(i=0;i<=SIZE;i++)
{
if(v[i][index]==value) //if does not satisfies the condition [not equals]
v[i].clear(); //delete the tuple
}
}
else if(op==">")
{
for(i=0;i<=SIZE;i++)
{
if(stoint(v[i][index])<=stoint(value)) //if does not satisfies the condition [greater than]
v[i].clear(); //delete the tuple
}
}
else if(op=="<")
{
for(i=0;i<=SIZE;i++)
{
if(stoint(v[i][index])>=stoint(value)) //if does not satisfies the condition [less than]
v[i].clear(); //delete the tuple
}
}
}
void union_table(string s, int op) //implements union operation
{ //s : query given by user
string s1,s2; //op : location of 'U' union operator in string s
s1=s.substr(2,op-3); //s1 : sub query 1 - left of 'U'
s2=s.substr(op+2,s.length()-op-4); //s2 : sub query 2 - right of 'U'
parser_function2(s1); //parses subquery s1
int i,j;
set<vector<string> >myset; //create a set, so that duplicacy of tuples after union does not occur
for(i=0;i<=SIZE;i++)
{
if(v[i].empty()!=true)
myset.insert(v[i]); //insert the result of s1 in set
}
parser_function2(s2); //parses subquery s2
for(i=0;i<=SIZE;i++)
{
if(v[i].empty()!=true)
myset.insert(v[i]),v[i].clear(); //insert the result of s2 in set
}
set<vector<string> >::iterator it; //iterator for the set
SIZE=0;
for (it=myset.begin(); it!=myset.end(); it++)
{
const vector<string>& vi = (*it);
for(int j=0;j<vi.size();j++)
{
v[SIZE].push_back(vi[j]); //push the contents of set to v vector of vectors
}
SIZE++;
}
}
void set_diff(string s,int op) //implements the set difference operation
{ //s : query given by user
string s1,s2; //op : location of '-' set difference operator in string s
s1=s.substr(2,op-3); //s1 : sub query 1 - left of '-'
s2=s.substr(op+2,s.length()-op-4); //s2 : sub query 2 - right of '-'
parser_function2(s1); //parses subquery s1
int i,j;
set<vector<string> >myset; //create a set
for(i=0;i<=SIZE;i++)
{
if(v[i].empty()!=true)
myset.insert(v[i]); //insert the result of s1 in set
}
parser_function2(s2); //parses subquery s1
for(i=0;i<=SIZE;i++)
{
if(v[i].empty()!=true)
myset.erase(myset.find(v[i])),v[i].clear(); //deletes the tuple in result of s2 from s1 if found in s1
}
set<vector<string> >::iterator it; //iterator for the set
SIZE=0;
for (it=myset.begin(); it!=myset.end(); it++)
{
const vector<string>& vi = (*it);
for(int j=0;j<vi.size();j++)
{
v[SIZE].push_back(vi[j]); //push the contents of set to v vector of vectors
}
SIZE++;
}
}
void rename_table(string s,int op) //implements the rename operation
{ //s : query given by user
string t; //op : location of 'r' of rename in string s
int i,end=0;
for(i=op;i<s.length();i++)
{
if(s[i]==')')
end=i;
if(end!=0)
break;
}
int start=op-2;
t=s.substr(op,end-start-3);
string table,new_name,temp="";
vector<string> r;
for(i=0;i<t.length();i++)
{
if(t[i]==' ')
{
if(temp.length()!=0) r.push_back(temp);
temp="";
}
else if(i==t.length()-1)
{
temp=temp+t[i];
if(temp.length()!=0) r.push_back(temp);
temp="";
}
else
temp=temp+t[i];
}
table=r[2]; //table which is to be renamed
new_name=r[1]; //new name of the table
s.erase(start,end-start+1); //replace the rename string in s with new name
s.insert(start,r[1]);
fstream f1;
f1.open( new_name.c_str(),ios::out ); //create a new file with new table name
f1.close();
ofstream f;
f.open( new_name.c_str(),ios::app );
ifstream t1;
t1.open(table.c_str(),ios::in);
string head="";
while(!t1.eof()) //copy the contents of old table file into new table file name
{
getline(t1,head);
f<<head;
f<<"\n";
}
f.close();
t1.close();
parser_function2(s); //parse the resultant new query
}
int stoint(string s) //converts string to integer
{
int num=0;
int l=s.length();
int i;
int k=1;
for(i=l-1;i>=0;i--)
{
num=num+(s[i]-'0')*k;
k=k*10;
}
return num; //returns the integer value
}
bool checkfordot() //checks for presence of dot in a given condition
{
int j;
for(j=0;j<m.size();j++)
{
string str=m.at(j);
size_t found = str.find(".");
if (found!=std::string::npos)
{
dot_flag=1;
return true;
}
}
return false;
}