Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include <fstream>
  4. #include<string.h>
  5. #include <sstream>
  6. #include <cstdlib>
  7.  
  8. //strtol(s.c_str(),0,10);
  9. using namespace std;
  10.  
  11.  
  12.  
  13. void ScreenLogo()
  14. {
  15.  
  16. printf("\n\n\n\n\n==============================================================\n");
  17. printf(" \t [A] : To Add Record Choose A\n");
  18. printf(" \t [D] : To Display Record Choose D\n");
  19. printf(" \t [E] : To Exit E\n");
  20. printf("==============================================================\n\n\n\n\n");
  21. }
  22.  
  23. int IndexID()
  24. {
  25. int c=0;
  26. ofstream record,index;
  27. index.open("index.txt");
  28. record.open("record.txt");
  29. while(!index.eof())
  30. c++;
  31. return c++;
  32. }
  33.  
  34.  
  35.  
  36. void Add(char &control)
  37. {
  38. ofstream record,index;
  39. index.open("index.txt");
  40. record.open("record.txt");
  41. int ID,Age;
  42. char Name[100];
  43. ID = IndexID();
  44. cout<<"\nEnter Age : \n";
  45. cin>>Age;
  46. cout<<"\nEnter Your Name : \n";
  47. cin>>Name;
  48. index<<ID;
  49. record<<ID<<"|"<<Name<<"|"<<Age;
  50. cout<<"\n\n\n\n Your ID is "<<ID;
  51. ScreenLogo();
  52. cout<<"[+] Choose An Option : ";
  53. cin>>control;
  54. }
  55.  
  56.  
  57. void Display(char &control)
  58. {
  59. int ID,flag=0;
  60. ifstream records;
  61. cout<<"Enter IndexID : ";
  62. cin>>ID;
  63. ifstream file("index.txt");
  64. records.open("record.txt");
  65.  
  66. string line;
  67. while(getline(file,line))
  68. {
  69. int newline = strtol(line.c_str(),0,10);
  70. if(newline == ID)
  71. flag++;
  72. }
  73. if(flag)
  74. {
  75. //cout<<"\t\tIndexID is Stored in My Records";
  76. char output[100];
  77. while(!records.eof())
  78. {
  79. records >> output;
  80. char *pch;
  81. pch = strtok (output,"|");
  82. char Data[3];
  83. int i=0;
  84. while (pch != NULL)
  85. {
  86.  
  87. if(i == 0)
  88. printf ("ID : %s\n",pch);
  89. if(i == 1)
  90. printf ("Name : %s\n",pch);
  91. if(i == 2)
  92. printf ("Age : %s\n",pch);
  93. pch = strtok (NULL, "|");
  94. i++;
  95. }
  96.  
  97. //cout<<output;
  98.  
  99. }
  100.  
  101.  
  102. }else{
  103. cout<<"\t\tIndex is not Found ";
  104. }
  105.  
  106.  
  107.  
  108.  
  109. ScreenLogo();
  110. cout<<"[+] Choose An Option : ";
  111. cin>>control;
  112. }
  113. int main()
  114. {
  115. ScreenLogo();
  116. char x;
  117. cout<<"[+] Choose An Option : ";
  118. cin>>x;
  119. while(x != 'E')
  120. {
  121.  
  122. switch(x)
  123. {
  124. case 'A':
  125. Add(x);
  126. break;
  127. case 'D':
  128. Display(x);
  129. break;
  130. case 'E':
  131. exit;
  132. default:
  133. cout<<"[+] Choose An Option : ";
  134. cin>>x;
  135. }
  136.  
  137.  
  138. }
  139.  
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement