Advertisement
Guest User

Untitled

a guest
Jan 14th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. /*
  2. * client.h
  3. *
  4. */
  5.  
  6. #ifndef CLIENT_H_
  7. #define CLIENT_H_
  8. #include <iostream>
  9. using namespace std;
  10. class Client {
  11. public:
  12. // constructors
  13. Client();
  14. Client(string, string, string, string, string);
  15. // getters
  16. string getName();
  17. string getAddr();
  18. string getTel();
  19. string getUserName();
  20. string getPassword();
  21. // setters
  22. void setName(string);
  23. void setAddr(string);
  24. void setTel(string);
  25. void setUserName(string);
  26. void setPassword(string);
  27. void Display();
  28. void output(ostream&);
  29. void input(istream&);
  30. void input();
  31. private:
  32. // fields
  33. string name;
  34. string addr;
  35. string tel;
  36. string userName;
  37. string password;
  38. };
  39. #endif /* CLIENT_H_ */
  40.  
  41. /*
  42. *ad client.cpp
  43. *
  44. */
  45.  
  46. #include <iostream>
  47. #include <iomanip>
  48. #include "client.h"
  49. using namespace std;
  50.  
  51. Client::Client() {
  52. setName("");
  53. setAddr("");
  54. setTel("");
  55. setUserName("");
  56. setPassword("");
  57. }
  58.  
  59. Client::Client(string new_name, string new_addr, string new_tel, string new_un, string new_pass) {
  60. setName(new_name);
  61. setAddr(new_addr);
  62. setTel(new_tel);
  63. setUserName(new_un);
  64. setPassword(new_pass);
  65. }
  66.  
  67. string Client::getName() {
  68. return name;
  69. }
  70.  
  71. string Client::getAddr() {
  72. return addr;
  73. }
  74.  
  75. string Client::getTel() {
  76. return tel;
  77. }
  78.  
  79. string Client::getUserName() {
  80. return userName;
  81. }
  82.  
  83. string Client::getPassword() {
  84. return password;
  85. }
  86.  
  87. void Client::setName(string p_name) {
  88. name = p_name;
  89. }
  90.  
  91. void Client::setAddr(string p_addr) {
  92. addr = p_addr;
  93. }
  94.  
  95. void Client::setTel(string p_tel) {
  96. tel = p_tel;
  97. }
  98.  
  99. void Client::setUserName(string p_userName) {
  100. userName = p_userName;
  101. }
  102.  
  103. void Client::setPassword(string p_password) {
  104. password = p_password;
  105. }
  106.  
  107. void Client::input() {
  108. string tmp;
  109.  
  110. cout << "INPUT CLIENT DATA" << endl;
  111. cout << "Name: ";
  112. cin >> tmp;
  113. setName(tmp);
  114. cout << "Address: ";
  115. cin >> tmp;
  116. setAddr(tmp);
  117. cout << "Telephone: ";
  118. cin >> tmp;
  119. setTel(tmp);
  120. cout << "Username: ";
  121. cin >> tmp;
  122. setUserName(tmp);
  123. cout << "Password: ";
  124. cin >> tmp;
  125. setPassword(tmp);
  126. }
  127.  
  128. void Client::Display() {
  129. cout << setw(20) << left << name
  130. << setw(40) << left << addr
  131. << setw(15) << left << tel << endl;
  132. }
  133.  
  134. /*
  135. * company.h
  136. *
  137. * Created on: 13 Ιαν 2017
  138. * Author: niksarid
  139. */
  140.  
  141. #ifndef COMPANY_H_
  142. #define COMPANY_H_
  143. #include <vector>
  144. #include "client.h"
  145. #include "employee.h"
  146. #include "route.h"
  147. #include "ticket.h"
  148. #include "executedRoute.h"
  149. using namespace std;
  150.  
  151. class Company {
  152. public:
  153. Company();
  154. ~Company();
  155. void add_client();
  156. void print_clients();
  157.  
  158. void loadClientsFromFile();
  159. void saveClientsToFile();
  160. private:
  161. vector<Client> clients;
  162. };
  163. #endif /* COMPANY_H_ */
  164.  
  165. void Company::loadClientsFromFile() {
  166. Client c;
  167. ifstream fin("clients.dat", ios::in | ios::binary);
  168.  
  169. if (fin) {
  170. while( fin.read( reinterpret_cast<char*>( &c ), sizeof(c) ) )
  171. clients.push_back(c) ;
  172. fin.close();
  173. } else cout << "clients.dat not found!" << endl;
  174. }
  175.  
  176. void Company::saveClientsToFile() {
  177. ofstream fout("clients.dat", ios::out | ios::binary);
  178.  
  179. if (fout) {
  180. int size = clients.size();
  181. cout << size << " clients saved!n";
  182.  
  183. for( const Client& c : clients )
  184. fout.write( reinterpret_cast<const char*>( &c ), sizeof(c) ) ;
  185.  
  186. } else cout << "Error in saving the clients data file!n";
  187. }
  188.  
  189. 2 [main] AirLine 7380 cygwin_exception::open_stackdumpfile: Dumping stack trace to AirLine.exe.stackdump
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement