PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/www.cppreference.com/wiki/examples_2

https://github.com/tsgates/cclookup
#! | 417 lines | 355 code | 62 blank | 0 comment | 0 complexity | 35bcb0185e93a414d1705ac654ead2eb MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
  4. lang="en" dir="ltr">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <title>examples_2</title>
  8. <meta name="generator" content="DokuWiki" />
  9. <meta name="robots" content="index,follow" />
  10. <meta name="date" content="2010-10-28T18:17:24-0700" />
  11. <meta name="keywords" content="examples_2" />
  12. <link rel="search" type="application/opensearchdescription+xml" href="http://www.cppreference.com/wiki/lib/exe/opensearch.php" title="C++ Reference" />
  13. <link rel="start" href="../index.html" />
  14. <link rel="contents" href="http://www.cppreference.com/wiki/examples_2?do=index" title="Sitemap" />
  15. <link rel="alternate" type="application/rss+xml" title="Recent Changes" href="http://www.cppreference.com/wiki/feed.php" />
  16. <link rel="alternate" type="application/rss+xml" title="Current Namespace" href="http://www.cppreference.com/wiki/feed.php?mode=list&amp;ns=" />
  17. <link rel="alternate" type="text/html" title="Plain HTML" href="http://www.cppreference.com/wiki/_export/xhtml/examples_2" />
  18. <link rel="alternate" type="text/plain" title="Wiki Markup" href="http://www.cppreference.com/wiki/_export/raw/examples_2" />
  19. <link rel="canonical" href="examples_2" />
  20. <link rel="stylesheet" media="screen" type="text/css" href="lib/exe/css.php@t=custom1&amp;tseed=1289693594" />
  21. <link rel="stylesheet" media="all" type="text/css" href="lib/exe/css.php@s=all&amp;t=custom1&amp;tseed=1289693594" />
  22. <link rel="stylesheet" media="print" type="text/css" href="lib/exe/css.php@s=print&amp;t=custom1&amp;tseed=1289693594" />
  23. <script type="text/javascript" ><!--//--><![CDATA[//><!--
  24. var NS='';var JSINFO = {"id":"examples_2","namespace":""};
  25. //--><!]]></script>
  26. <script type="text/javascript" charset="utf-8" src="lib/exe/js.php@tseed=1289693594" ></script>
  27. </head>
  28. <body>
  29. <div class="dokuwiki export">
  30. <p>
  31. #include “CPE.€
  32. using namespace std;
  33. #include &lt;cstdlib&gt;
  34. #include &lt;sstream&gt;
  35. </p>
  36. <p>
  37. enum assinatura { MENSAL, DIARIO };
  38. </p>
  39. <p>
  40. unsigned int Parque::carregaClientes(istream&amp; is) {
  41. </p>
  42. <pre class="code">unsigned int contador=0;
  43. while (!is.eof()) {
  44. string nome, local, modalidade, lixo;
  45. unsigned int tel=0;
  46. assinatura tipo;
  47. if (!getline(is, nome))
  48. break;
  49. if (!getline(is, local))
  50. break;
  51. if (!(is &gt;&gt; tel))
  52. break;
  53. getline(is, lixo);
  54. if (!getline(is, modalidade))
  55. break;
  56. if ((modalidade.compare(&quot;MENSAL&quot;) == 0) || (modalidade.compare(&quot;mensal&quot;) == 0))
  57. else
  58. tipo = DIARIO;</pre>
  59. <pre class="code"> if (nome.length() &gt; 0) {
  60. if (tipo == MENSAL) {
  61. ClienteMensal* pCliente = new ClienteMensal(nome, local, tel, valorMes);
  62. clientes.push_back(pCliente);
  63. }
  64. else {
  65. ClienteDiario* pCliente = new ClienteDiario(nome, local, tel, valorHora);
  66. clientes.push_back(pCliente);
  67. }
  68. contador++;
  69. }
  70. }
  71. return contador;</pre>
  72. <p>
  73. }
  74. </p>
  75. <p>
  76. string Pessoa::lista() const {
  77. </p>
  78. <pre class="code"> ostringstream oss;
  79. oss &lt;&lt; nome &lt;&lt;&quot;, &quot;&lt;&lt; localidade &lt;&lt;&quot;, &quot;&lt;&lt; telefone;</pre>
  80. <p>
  81. return oss.str();
  82. }
  83. </p>
  84. <p>
  85. double Funcionario::leValor() const {
  86. </p>
  87. <pre class="code">return valor;</pre>
  88. <p>
  89. }
  90. </p>
  91. <p>
  92. string Funcionario::lista() const {
  93. </p>
  94. <pre class="code">ostringstream oss;
  95. oss &lt;&lt; &quot;Funcionario: &quot; &lt;&lt; Pessoa::lista() &lt;&lt; &quot;, &quot;&lt;&lt;leValor()&lt;&lt; &quot; euros&quot;;</pre>
  96. <p>
  97. return oss.str();
  98. }
  99. </p>
  100. <p>
  101. double Cliente::leValor() const {
  102. </p>
  103. <pre class="code">return valorAPagar;</pre>
  104. <p>
  105. }
  106. </p>
  107. <p>
  108. string Cliente::lista() const {
  109. </p>
  110. <pre class="code"> ostringstream oss;
  111. oss &lt;&lt; Pessoa::lista() &lt;&lt; &quot;, &quot;&lt;&lt; leValor()&lt;&lt; &quot; euros, &quot; &lt;&lt; (presente?&quot;estacionado&quot;:&quot;fora&quot;);
  112. return oss.str();</pre>
  113. <p>
  114. }
  115. </p>
  116. <p>
  117. string ClienteDiario::lista() const {
  118. </p>
  119. <pre class="code">ostringstream oss;
  120. oss &lt;&lt; &quot;Cliente diario : &quot; &lt;&lt; Cliente::lista();
  121. return oss.str();</pre>
  122. <p>
  123. }
  124. </p>
  125. <p>
  126. string ClienteMensal::lista() const {
  127. </p>
  128. <pre class="code">ostringstream oss;
  129. oss &lt;&lt; &quot;Cliente mensal : &quot; &lt;&lt; Cliente::lista();
  130. return oss.str();</pre>
  131. <p>
  132. }
  133. </p>
  134. <p>
  135. Pessoa::Pessoa(string umNome, string umaLocalidade, unsigned int umTelefone) {
  136. </p>
  137. <pre class="code">nome = umNome;
  138. localidade = umaLocalidade;
  139. telefone = umTelefone; </pre>
  140. <p>
  141. }
  142. </p>
  143. <p>
  144. Funcionario::Funcionario(string umNome, string umaLocalidade, unsigned int umTelefone, double umVencimento)
  145. </p>
  146. <pre class="code">: Pessoa(umNome, umaLocalidade, umTelefone) {</pre>
  147. <pre class="code">valor = umVencimento;</pre>
  148. <p>
  149. }
  150. Cliente::Cliente(string umNome, string umaLocalidade, unsigned int umTelefone, double valorTaxa): Pessoa(umNome, umaLocalidade, umTelefone) {
  151. </p>
  152. <pre class="code">presente = false;
  153. valor = valorTaxa;
  154. valorAPagar = 0; </pre>
  155. <p>
  156. }
  157. </p>
  158. <p>
  159. ClienteDiario::ClienteDiario(string umNome, string umaLocalidade, unsigned int umTelefone, double valorTaxa):
  160. </p>
  161. <pre class="code">Cliente(umNome, umaLocalidade, umTelefone, valorTaxa) {</pre>
  162. <p>
  163. }
  164. </p>
  165. <p>
  166. ClienteMensal::ClienteMensal(string umNome, string umaLocalidade, unsigned int umTelefone, double valorTaxa):
  167. </p>
  168. <pre class="code">Cliente(umNome, umaLocalidade, umTelefone, valorTaxa) {</pre>
  169. <p>
  170. }
  171. </p>
  172. <p>
  173. Parque::Parque(string umNome, unsigned int maxLotacao, float valHora, float valMes): valorHora(valHora), valorMes(valMes) {
  174. </p>
  175. <pre class="code">nome = umNome;
  176. lotacao = maxLotacao;
  177. ocupados = 0; </pre>
  178. <p>
  179. }
  180. </p>
  181. <p>
  182. Parque::~Parque() {
  183. </p>
  184. <pre class="code">vector&lt;Cliente*&gt;::iterator itc;
  185. vector&lt;Funcionario*&gt;::iterator itf;
  186. for(itc=clientes.begin(); itc!=clientes.end(); itc++ )
  187. { delete *itc; }
  188. clientes.clear();
  189. for(itf=funcionarios.begin(); itf!=funcionarios.end(); itf++)
  190. { delete *itf; }
  191. funcionarios.clear(); </pre>
  192. <p>
  193. }
  194. unsigned int Parque::carregaFuncionarios(istream&amp; is) {
  195. </p>
  196. <pre class="code">unsigned int contador=0;
  197. while (!is.eof()) {
  198. string nome, local, venc, lixo;
  199. unsigned int tel;
  200. double vencimento;
  201. if (!getline(is, nome))
  202. break;
  203. if (!getline(is, local))
  204. break;
  205. if (!(is &gt;&gt; tel))
  206. break;
  207. getline(is, lixo);
  208. if (!getline(is, venc))
  209. break;
  210. vencimento = atof(venc.c_str());
  211. if (nome.length() &gt; 0) {
  212. Funcionario* pFuncionario = new Funcionario(nome, local, tel, vencimento);
  213. funcionarios.push_back(pFuncionario);
  214. contador++;
  215. }
  216. }
  217. return contador;</pre>
  218. <p>
  219. }
  220. </p>
  221. <p>
  222. unsigned int Parque::numClientes() {
  223. </p>
  224. <pre class="code">return clientes.size();} </pre>
  225. <p>
  226. unsigned int Parque::numFuncionarios() {
  227. </p>
  228. <pre class="code">return funcionarios.size(); </pre>
  229. <p>
  230. void Parque::listaClientes(ostream&amp; os) {
  231. </p>
  232. <pre class="code">vector&lt;Cliente*&gt;::iterator itc;
  233. for(itc=clientes.begin(); itc!=clientes.end(); itc++ )
  234. { os &lt;&lt; ((*itc)-&gt;lista()) &lt;&lt; endl; }</pre>
  235. <p>
  236. }
  237. </p>
  238. <p>
  239. void Parque::listaFuncionarios(ostream&amp; os) {
  240. </p>
  241. <pre class="code">vector&lt;Funcionario*&gt;::iterator itf;
  242. for(itf=funcionarios.begin(); itf!=funcionarios.end(); itf++ )
  243. os &lt;&lt; ((*itf)-&gt;lista()) &lt;&lt; endl; </pre>
  244. <p>
  245. }
  246. </p>
  247. <p>
  248. bool Cliente::entra() {
  249. </p>
  250. <pre class="code">if (presente==false) {
  251. presente = true;
  252. return true;
  253. }
  254. else
  255. return false;</pre>
  256. <p>
  257. }
  258. </p>
  259. <p>
  260. bool Cliente::sai(float tempo){
  261. </p>
  262. <pre class="code">if (presente==true) {
  263. presente = false;
  264. return true;
  265. }
  266. else
  267. return false;</pre>
  268. <p>
  269. }
  270. </p>
  271. <p>
  272. bool ClienteDiario::sai(float tempo){
  273. </p>
  274. <pre class="code">bool estaNoParque=Cliente::sai(tempo);
  275. if (estaNoParque==false) return false;
  276. valorAPagar += tempo*valor;
  277. return true;</pre>
  278. <p>
  279. }
  280. </p>
  281. <p>
  282. bool ClienteMensal::sai(float tempo){
  283. </p>
  284. <pre class="code">bool estaNoParque=Cliente::sai(tempo);
  285. if (estaNoParque==false) return false;
  286. if (valorAPagar==0) valorAPagar=valor;
  287. return true;</pre>
  288. <p>
  289. }
  290. </p>
  291. <p>
  292. unsigned int Parque::numLugaresVagos() {
  293. </p>
  294. <pre class="code">return (lotacao-ocupados);</pre>
  295. <p>
  296. }
  297. </p>
  298. <p>
  299. bool Parque::entra(const string &amp;nome) {
  300. </p>
  301. <pre class="code">vector&lt;Cliente*&gt;::iterator itc;
  302. for (itc=clientes.begin(); itc!=clientes.end(); itc++) {
  303. if (((*itc)-&gt;getNome()) == nome &amp;&amp; ocupados&lt;lotacao)
  304. if ((**itc).entra()) {
  305. ocupados++;
  306. return true;
  307. }
  308. }
  309. return false; </pre>
  310. <p>
  311. }
  312. </p>
  313. <p>
  314. bool Parque::sai(const string &amp;nome, float tempo) {
  315. </p>
  316. <pre class="code">vector&lt;Cliente*&gt;::iterator itc;
  317. for (itc=clientes.begin(); itc!=clientes.end(); itc++) {
  318. if (((*itc)-&gt;getNome()) == nome)
  319. if ((**itc).sai(tempo)) {
  320. ocupados--;
  321. return true;
  322. }
  323. }
  324. return false; </pre>
  325. <p>
  326. }
  327. </p>
  328. <p>
  329. void Parque::listaClientesEstacionados(ostream&amp; os) {
  330. </p>
  331. <pre class="code">vector&lt;Cliente*&gt;::iterator itc;
  332. for(itc=clientes.begin(); itc!=clientes.end(); itc++ )
  333. {
  334. if ((**itc).estacionado())
  335. os &lt;&lt; (*itc)-&gt;getNome() &lt;&lt; endl;
  336. }</pre>
  337. <p>
  338. }
  339. </p>
  340. <p>
  341. double Parque::totalValorMes() {
  342. </p>
  343. <pre class="code">vector&lt;Cliente*&gt;::iterator itc;
  344. double tot=0;
  345. for(itc=clientes.begin(); itc!=clientes.end(); itc++ )
  346. {
  347. tot += (*itc)-&gt;leValor();
  348. }
  349. return tot;</pre>
  350. <p>
  351. }
  352. </p>
  353. </div>
  354. </body>
  355. </html>