Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.47 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #define MAX 1000
  4. using namespace std;
  5.  
  6. //struct of customer
  7. struct Customer
  8. {
  9. //num of pax
  10. int num;
  11. //customer name
  12. string name;
  13. // phone number
  14. string phone;
  15. //booking date
  16. string date;
  17. //booking time
  18. string time;
  19. };
  20. //struct of restoren
  21. struct Restaurant
  22. {
  23. //Array of customers stored in the restaurant
  24. struct Customer customerArray[MAX];
  25. //The restaurant currently records the number of customers
  26. int m_size;
  27. };
  28.  
  29. int isEmty(Restaurant* rts, string Date) {
  30. for (int i = 0; i < rts->m_size; i++)
  31. {
  32. if (rts->customerArray[i].date==Date)
  33. {
  34. return i;
  35. }
  36. }
  37. return -1;
  38. }
  39. int isEmty(Restaurant* rts, int Num) {
  40. for (int i = 0; i < rts->m_size; i++)
  41. {
  42. if (rts->customerArray[i].num==Num)
  43. {
  44. return i;
  45. }
  46. }
  47. return -1;
  48. }
  49. void addCustomer(Restaurant*rts) {
  50. if (rts->m_size == MAX) {
  51. cout << "it is full, cannot at\n ";
  52. return;
  53. }
  54. else {//add the data
  55.  
  56. int Num;
  57. cout << "enter num of pax:\n";
  58. cin >> Num;
  59. rts->customerArray[rts->m_size].num = Num;
  60. string Name;
  61. cout << "enter customer name;\n";
  62. cin >> Name;
  63. rts->customerArray[rts->m_size].name = Name;
  64. string Phone;
  65. cout << "Enter phone Number:\n";
  66. cin >> Phone;
  67. rts->customerArray[rts->m_size].phone = Phone;
  68. string Date;
  69. cout << "Enter Booking Date:\n";
  70. cin >> Date;
  71. rts->customerArray[rts->m_size].date = Date;
  72. string Time;
  73. cout << "Enter Booking Time:\n";
  74. cin >> Time;
  75. rts->customerArray[rts->m_size].time = Time;
  76. rts->m_size++;//uodate the quantiti of m_size
  77. cout << "add finish\n";
  78. system("pause");
  79. system("cls");
  80.  
  81. }
  82. }
  83.  
  84. void nameBubbleSort(Restaurant* rts){
  85. int i,j;
  86. Customer current;
  87. for(i=0; i<rts->m_size;i++)
  88. for (j=0; j<rts->m_size-1; j++){
  89. if(rts->customerArray[j].name>rts->customerArray[j+1].name){
  90. current = rts->customerArray[j];
  91. rts->customerArray[j] = rts->customerArray[j+1];
  92. rts->customerArray[j+1] = current;
  93. }
  94. }
  95. }
  96.  
  97. void dateBubbleSort(Restaurant* rts){
  98. int i,j;
  99. Customer current;
  100. for(i=0; i<rts->m_size;i++)
  101. for (j=0; j<rts->m_size-1; j++){
  102. if(rts->customerArray[j].date>rts->customerArray[j+1].date){
  103. current = rts->customerArray[j];
  104. rts->customerArray[j] = rts->customerArray[j+1];
  105. rts->customerArray[j+1] = current;
  106. }
  107. }
  108. }
  109.  
  110. void phoneBubbleSort(Restaurant* rts){
  111. int i,j;
  112. Customer current;
  113. for(i=0; i<rts->m_size;i++)
  114. for (j=0; j<rts->m_size-1; j++){
  115. if(rts->customerArray[j].phone>rts->customerArray[j+1].phone){
  116. current = rts->customerArray[j];
  117. rts->customerArray[j] = rts->customerArray[j+1];
  118. rts->customerArray[j+1] = current;
  119. }
  120. }
  121. }
  122.  
  123. void nameBinarySearch(Restaurant* rts, string key){
  124. int low = 0;
  125. int high = SIZE-1;
  126. int median;
  127. nameBubbleSort(&rts);
  128. while(low <= high){
  129. median = (low+high)/2;
  130.  
  131. if(key == rts->customerArray[median].name){
  132. cout<<"*********************************************************\n" ;
  133. cout << "num of pax:" << rts->customerArray[median].num<< "\n";
  134. cout << "name:" << rts->customerArray[median].name << "\n";
  135. cout << "phone number :" << rts->customerArray[median].phone << "\n";
  136. cout << "Booking time:" << rts->customerArray[median].time << "\n";
  137. cout << "Booking Date :" << rts->customerArray[median].date << "\n";
  138. cout<<"*********************************************************\n";
  139. return;
  140. }else if(key < rts->customerArray[median].name){
  141. high = median - 1;
  142. }else{
  143. low = median + 1;
  144. }
  145. }
  146. cout<<"no data\n";
  147. }
  148.  
  149. void phoneBinarySearch(Restaurant* rts, string key){
  150. int low = 0;
  151. int high = SIZE-1;
  152. int median;
  153. nameBubbleSort(&rts);
  154. while(low <= high){
  155. median = (low+high)/2;
  156.  
  157. if(key == rts->customerArray[median].phone){
  158. cout<<"*********************************************************\n" ;
  159. cout << "num of pax:" << rts->customerArray[median].num<< "\n";
  160. cout << "name:" << rts->customerArray[median].name << "\n";
  161. cout << "phone number :" << rts->customerArray[median].phone << "\n";
  162. cout << "Booking time:" << rts->customerArray[median].time << "\n";
  163. cout << "Booking Date :" << rts->customerArray[median].date << "\n";
  164. cout<<"*********************************************************\n";
  165. return;
  166. }else if(key < rts->customerArray[median].phone){
  167. high = median - 1;
  168. }else{
  169. low = median + 1;
  170. }
  171. }
  172. cout<<"no data\n";
  173. }
  174.  
  175. int seachcustomer(Restaurant*rts){
  176. int m_num;
  177. string Date;
  178. int ch=0;
  179. cout<<"1.seach by num fo pax\n";
  180. cout<<"2.sech by date\n";
  181.  
  182. while(true){
  183. cin>>ch;
  184. if(ch==1){
  185. int Num;
  186. cout<<"enter number of pax\n";
  187. cin>>Num;
  188. Num=m_num+1;
  189. int ret = isEmty(rts, Num);
  190. if (ret!=-1){
  191. string Num, Name, Phone, Date, Time;
  192.  
  193. cout << "num of pax:" << rts->customerArray[ret].num << "\t";
  194. cout << "name:" << rts->customerArray[ret].name << "\t";
  195. cout << "phone number :" << rts->customerArray[ret].phone << "\t";
  196. cout << "Booking time:" << rts->customerArray[ret].time << "\t";
  197. cout << "Booking Date :" << rts->customerArray[ret].date << "\t";
  198. cout << "\n";
  199.  
  200. }
  201. else
  202. {
  203. cout << " no fine record\n";
  204. }
  205. cout << "\n";
  206. system("pause");
  207. system("cls");
  208.  
  209. }
  210. else if(ch==2){
  211. string Date;
  212. cout << "enter booking date you need seach";
  213. cin >> Date;
  214. int ret = isEmty(rts, Date);
  215.  
  216. if (ret != -1)
  217. {
  218. string Num, Name, Phone, Date, Time;
  219.  
  220. cout << "num of pax:" << rts->customerArray[ret].num<< "\t";
  221. cout << "name:" << rts->customerArray[ret].name<< "\t";
  222. cout << "phone number :" << rts->customerArray[ret].phone<< "\t";
  223. cout << "Booking time:" << rts->customerArray[ret].time<< "\t";
  224. cout << "Booking Date :" << rts->customerArray[ret].date<< "\t";
  225. cout << "\n";
  226.  
  227. }
  228. else
  229. {
  230. cout << " no fine record\n";
  231. }
  232. cout << "\n";
  233. system("pause");
  234. system("cls");
  235.  
  236. }else{
  237. cout<<"Erro input\n";
  238. }
  239. return 0;
  240. system("pause");
  241. system("cls");
  242. }
  243. }
  244.  
  245.  
  246. void ShowAll(Restaurant*rts) {
  247.  
  248. //if m_size=0 then emty else show all record
  249. if (rts->m_size == 0) {
  250. cout << "the recort is emty\n";
  251. }
  252. else
  253. {
  254. for ( int i = 0; i <rts->m_size; i++)
  255. { cout<<"*********************************************************\n" ;
  256. cout << "num of pax:" << rts->customerArray[i].num<< "\n";
  257. cout << "name:" << rts->customerArray[i].name << "\n";
  258. cout << "phone number :" << rts->customerArray[i].phone << "\n";
  259. cout << "Booking time:" << rts->customerArray[i].time << "\n";
  260. cout << "Booking Date :" << rts->customerArray[i].date << "\n";
  261. cout<<"*********************************************************\n";
  262. system("pause");
  263. system("cls");
  264.  
  265. }
  266. }
  267.  
  268. }
  269.  
  270. void ShowManu() {
  271. cout << "1.add\n ";
  272. cout << "2.show\n";
  273. cout << "3.sort\n";
  274. cout << "4.seach\n";
  275. cout << "0.exit\n";
  276. }
  277.  
  278. int main() {
  279.  
  280. Restaurant rts;
  281.  
  282. rts.m_size = 0;
  283.  
  284. int select = 0;
  285. int selectSort = 0;
  286. while (true)
  287. {
  288.  
  289. ShowManu();
  290. cin >> select;
  291. switch (select)
  292. {
  293. case 1://add
  294. addCustomer(&rts);
  295. break;
  296. case 2://show
  297. ShowAll(&rts);
  298. break;
  299. case 3:
  300. cout << "1.sort by name\n ";
  301. cout << "2.sort by date\n";
  302. cout << "0.exit\n";
  303. cin >> selectSort;
  304. switch (selectSort)
  305. {
  306. case 1://add
  307. nameBubbleSort(&rts);
  308. break;
  309. case 2://show
  310. dateBubbleSort(&rts);
  311. break;
  312. default:
  313. break;
  314. }
  315. break;
  316. case 4://seach
  317. seachcustomer(&rts);
  318.  
  319. break;
  320. case 0://exit
  321. cout << "welcome next time" << endl;
  322. system("pause");
  323. return 0;
  324. break;
  325. default:
  326. break;
  327. }
  328.  
  329. }
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement