Guest User

Untitled

a guest
Dec 15th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.96 KB | None | 0 0
  1. Hi every body please solve my question in my code i should save at least 2 person but i can't please help me .my code is about data bank(save information and print them)
  2.  
  3. #include<fstream>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. struct Person
  9. { char password;
  10. char username[20];
  11. char first_name[20];
  12. char last_name[20];
  13. char father_name[20];
  14. char birthdate[20];
  15. char birthplace[20];
  16. int age;
  17. char sex[10];
  18. char nationality[20];
  19. char job[20];
  20. char marital_status[20];
  21. long double phone_number;
  22. char address[80];
  23. char blood_type[5];
  24. float height;
  25. float weight;
  26. char allergen_type[20];
  27. char previous_disease[20];
  28. long double bank_account;
  29. char bank_account_expiration_date[20];
  30. float account_balance;
  31. };
  32. int main(){
  33. while(true){
  34. cout<<"which person are you? "<<" person[i]<<i"<<" for example ( person=3 << enter 3 )"<<endl;
  35. int i; cin>>i;if(i==0)break;
  36. cout<<"which one do you want? "<<" 1.sing up"<<" 2.sing in"<<" 0.exit"<<endl;
  37. int a; cin>>a;
  38. if (a == 1)
  39. {Person p_i;ofstream pepole("information.txt");
  40. cout<<"please enter your information carefully! "<<endl;
  41. cout<<"a) Identity information: "<<endl<<endl;
  42. pepole<<"person ("<<i<<")"<<endl;
  43. cout<<"password: ";
  44. cin>>p_i.password;pepole<<"password: "<<p_i.password<<endl;
  45. cin.ignore();
  46. cout<<"username: ";
  47. cin.getline(p_i.username,20);pepole<<"username: "<<p_i.username<<endl;
  48. cout<<"first name: ";
  49. cin.getline(p_i.first_name,20);pepole<<"first name: "<<p_i.first_name<<endl;
  50. cout<<"last name: ";
  51. cin.getline(p_i.last_name,20);pepole<<"last name: "<<p_i.last_name<<endl;
  52. cout<<"father name: ";
  53. cin.getline(p_i.father_name,20);pepole<<"father name: "<<p_i.father_name<<endl;
  54. cout<<"birthdate: ";
  55. cin.getline(p_i.birthdate,20);pepole<<"birthdate: "<<p_i.birthdate<<endl;
  56. cout<<"birthplace: ";
  57. cin.getline(p_i.birthplace,20);pepole<<"birthplace: "<<p_i.birthplace<<endl;
  58. cout<<"age: ";
  59. cin>>p_i.age;pepole<<"age: "<<p_i.age<<endl;
  60. cin.ignore();
  61. cout<<"sex: ";
  62. cin.getline(p_i.sex,10);pepole<<"sex: "<<p_i.sex<<endl;
  63. cout<<"nationality: ";
  64. cin.getline(p_i.nationality,20);pepole<<"nationality: "<<p_i.nationality<<endl;
  65. cout<<"job: ";
  66. cin.getline(p_i.job,20);pepole<<"job: "<<p_i.job<< endl;
  67. cout<<"marital status:";
  68. cin.getline(p_i.marital_status,20);pepole<<"marital status:"<<p_i.marital_status<<endl;
  69. cout<<"phone number: ";
  70. cin>>p_i.phone_number;pepole<<"phone number: "<<p_i.phone_number<<endl;
  71. cin.ignore();
  72. cout<<"address: ";
  73. cin.getline(p_i.address,80);pepole<<"address: "<<p_i.address<<endl;
  74. cout<<endl;
  75. cout<<"b) Health information: "<<endl<<endl;
  76. cout<<"blood type: ";
  77. cin.get(p_i.blood_type,5);pepole<<"blood type: "<<p_i.blood_type<<endl;
  78. cout<<"height(m): ";
  79. cin>>p_i.height;pepole<<"height(m): "<<p_i.height<<endl;
  80. cin.ignore();
  81. cout<<"weight(kg): ";
  82. cin>>p_i.weight;pepole<<"weight(kg): "<<p_i.weight<<endl;
  83. cin.ignore();
  84. cout<<"allergen type: ";
  85. cin.getline(p_i.allergen_type,20);pepole<<"allergen type: "<<p_i.allergen_type<<endl;
  86. cout<<"previous disease:";
  87. cin.getline(p_i.previous_disease,20);pepole<<"previous disease:"<<p_i.previous_disease<<endl;
  88. cout<<endl;
  89. cout<<"c) Banking information: "<<endl<<endl;
  90. cout<<"bank account: ";
  91. cin>>p_i.bank_account;pepole<<"bank account: "<<p_i.bank_account<<endl;
  92. cin.ignore();
  93. cout<<"bank account expiration date: ";
  94. cin.getline(p_i.bank_account_expiration_date,6);pepole<<"bank account expiration date: "<<p_i.bank_account_expiration_date<<endl;
  95. cout<<"account balance: ";
  96. cin>>p_i.account_balance;pepole<<"account balance: "<<p_i.account_balance<<endl;
  97. cout<<"thank you! Dear"<<p_i.first_name<<endl;
  98. cout<<"Your information sucecessfully saved."<<endl;
  99. cout<<endl;
  100. }
  101. else if (a == 2)
  102. {cout<<"please enter your password: ";
  103. int c;cin>>c;Person p_i;
  104. cout<<endl;
  105. if(p_i.password==c)
  106. {cout<< "which one your informations do you want? "<<endl;
  107. cout<< "1)username 2)password 3)first name 4)last name" <<endl;
  108. cout<< "5)father name 6)birthdate 7)birthplace 8)age" <<endl;
  109. cout<< "9)sex 10)nationality 11)job 12)martial status"<<endl;
  110. cout<< "13)phone number 14)address 15)blood type 16)height" <<endl;
  111. cout<< "17)weight 18)allergen type 19)previous disease 20)bank account" <<endl;
  112. cout<< "21)bank account expiration date 22)account balance" <<endl;
  113. int d;cin>>d;
  114. switch(d)
  115. {case 1:cout<<p_i.first_name<<" your password is "<<p_i.password<<endl;break;
  116. case 2:cout<<p_i.first_name<<" your username is "<<p_i.username[20]<<endl;break;
  117. case 3:cout<<" your first name is"<<p_i.first_name[20]<<endl;break;
  118. case 4:cout<<p_i.first_name<<" your last name is "<<p_i.last_name[20]<<endl;break;
  119. case 5:cout<<p_i.first_name<<" your father_name is "<<p_i.father_name[20]<<endl;break;
  120. case 6:cout<<p_i.first_name<<" your birthdate is "<<p_i.birthdate[20]<<endl;break;
  121. case 7:cout<<p_i.first_name<<" your birthplace is "<<p_i.birthplace[20]<<endl;break;
  122. case 8:cout<<p_i.first_name<<" your age is "<<p_i.age<<endl;break;
  123. case 9:cout<<p_i.first_name<<" your sex is "<<p_i.sex[10]<<endl;break;
  124. case 10:cout<<p_i.first_name<<" your nationality is "<<p_i.nationality[20]<<endl;break;
  125. case 11:cout<<p_i.first_name<<" your job is "<<p_i.job[20]<<endl;break;
  126. case 12:cout<<p_i.first_name<<" your marital status is "<<p_i.marital_status[20]<<endl;break;
  127. case 13:cout<<p_i.first_name<<" your phone number is "<<p_i.phone_number<<endl;break;
  128. case 14:cout<<p_i.first_name<<" your address is "<<p_i.address[80]<<endl;break;
  129. case 15:cout<<p_i.first_name<<" your blood type is "<<p_i.blood_type[5]<<endl;break;
  130. case 16:cout<<p_i.first_name<<" your height is "<<p_i.height<<endl;break;
  131. case 17:cout<<p_i.first_name<<" your weight is "<<p_i.weight<<endl;break;
  132. case 18:cout<<p_i.first_name<<" your allergen type is "<<p_i.allergen_type[20]<<endl;break;
  133. case 19:cout<<p_i.first_name<<" your previous disease is "<<p_i.previous_disease[20]<<endl;break;
  134. case 20:cout<<p_i.first_name<<" your bank account is "<<p_i.bank_account<<endl;break;
  135. case 21:cout<<p_i.first_name<<" your bank account expiration date is "<<p_i.bank_account_expiration_date[6]<<endl;break;
  136. case 22:cout<<p_i.first_name<<" your account balance is "<<p_i.account_balance<<endl;break;
  137. }}
  138. else
  139. cout<<"your password is worong!"<<endl<<"please enter your password again. ";cout<<endl;
  140.  
  141. }
  142. else if (a == 0)
  143. break;
  144. else
  145. cout<<"wrong input!!!!!"<< endl;
  146. }cout<<"good bye! have a nice day!";
  147. return 0;}
Add Comment
Please, Sign In to add comment