PageRenderTime 13ms CodeModel.GetById 10ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/www.cppreference.com/wiki/examples_3

https://github.com/tsgates/cclookup
#! | 209 lines | 173 code | 36 blank | 0 comment | 0 complexity | 87c85ea6a4cd0643a82029bf5d82b0a2 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_3</title>
  8<meta name="generator" content="DokuWiki" />
  9<meta name="robots" content="index,follow" />
 10<meta name="date" content="2010-10-28T18:17:27-0700" />
 11<meta name="keywords" content="examples_3" />
 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_3?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_3" />
 18<link rel="alternate" type="text/plain" title="Wiki Markup" href="http://www.cppreference.com/wiki/_export/raw/examples_3" />
 19<link rel="canonical" href="examples_3" />
 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[//><!--
 24var NS='';var JSINFO = {"id":"examples_3","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
 31<p>
 32#include “animal.h”
 33#include &lt;cstring&gt;
 34</p>
 35
 36<p>
 37Veterinario::Veterinario() {
 38</p>
 39<pre class="code">nome = especialidade = &quot;&quot;;</pre>
 40
 41<p>
 42}
 43Veterinario::Veterinario(string nom, string esp) {
 44</p>
 45<pre class="code">nome = nom;
 46especialidade = esp;</pre>
 47
 48<p>
 49}
 50Veterinario::Veterinario(const Veterinario &amp; v) {
 51</p>
 52<pre class="code">nome = v.nome;
 53especialidade = v.especialidade;</pre>
 54
 55<p>
 56}
 57string Veterinario::getNome() const {
 58</p>
 59<pre class="code">return nome;</pre>
 60
 61<p>
 62}
 63void Veterinario::setNome(string nom) {
 64</p>
 65<pre class="code">nome = nom;</pre>
 66
 67<p>
 68}
 69string Veterinario::getEspecialidade() const {
 70</p>
 71<pre class="code">return especialidade;</pre>
 72
 73<p>
 74}
 75void Veterinario::setEspecialidade(string esp) {
 76</p>
 77<pre class="code">especialidade = esp;</pre>
 78
 79<p>
 80}
 81</p>
 82
 83<p>
 84
 85Animal::Animal(string esp, bool sex, char * nom, int ida)
 86</p>
 87<pre class="code">:  especie(esp), sexo(sex), nome(new char(strlen(nom)+1)), veterinario(&quot;&quot;,&quot;&quot;) {
 88strcpy ((char*)nome, nom);
 89idade = ida;
 90numAnimais ++;</pre>
 91
 92<p>
 93}
 94Animal::Animal(string esp, bool sex, char * nom, int ida, Veterinario vet)
 95</p>
 96<pre class="code">:  especie(esp), sexo(sex), nome(new char(strlen(nom)+1)), veterinario(vet) {
 97strcpy ((char*)nome, nom);
 98idade = ida;
 99numAnimais ++;</pre>
100
101<p>
102}
103</p>
104
105<p>
106
107string Animal::getEspecie() const {
108</p>
109<pre class="code">return especie;</pre>
110
111<p>
112}
113bool Animal::getSexo() const {
114</p>
115<pre class="code">return sexo;</pre>
116
117<p>
118}
119char * Animal::getNome() const {
120</p>
121<pre class="code">return (char *)nome;</pre>
122
123<p>
124}
125int Animal::getIdade(void) const{
126</p>
127<pre class="code">return idade;</pre>
128
129<p>
130}
131void Animal::setIdade(int ida) {
132</p>
133<pre class="code">idade = ida;</pre>
134
135<p>
136}
137Veterinario Animal::getVeterinario() const {
138</p>
139<pre class="code">return veterinario;</pre>
140
141<p>
142}
143void Animal::setVeterinario(Veterinario vet) {
144</p>
145<pre class="code">veterinario = vet;</pre>
146
147<p>
148}
149</p>
150
151<p>
152
153ostream &amp; operator«(ostream &amp; os, Animal &amp; a){
154</p>
155<pre class="code">os &lt;&lt; &quot;Animal: &quot; &lt;&lt; a.getEspecie() &lt;&lt; &quot;, &quot; &lt;&lt; a.getSexo() &lt;&lt; &quot;, &quot; &lt;&lt; a.getNome() 
156       &lt;&lt; &quot;, &quot; &lt;&lt; a.getIdade() &lt;&lt; &quot;; Responsavel: &quot; &lt;&lt; (a.getVeterinario()).getNome() &lt;&lt; endl;
157return os;</pre>
158
159<p>
160}
161</p>
162
163<p>
164
165Animal::Animal(const Animal &amp; a)
166</p>
167<pre class="code">:  especie(a.especie), sexo(a.sexo), nome(new char(strlen(a.nome)+1)), veterinario(a.veterinario) {
168strcpy ((char*)nome, a.nome);
169idade = a.idade;</pre>
170
171<p>
172}
173Animal::~Animal() {
174</p>
175<pre class="code">delete [] nome;</pre>
176
177<p>
178}
179</p>
180
181<p>
182
183bool Animal::operator&lt;(const Animal &amp; a) {
184</p>
185<pre class="code">if (idade &lt; a.getIdade())
186	return true;
187else
188	return (false);</pre>
189
190<p>
191}
192</p>
193
194<p>
195
196int Animal::numAnimais = 0;
197</p>
198
199<p>
200int Animal::getNumAnimais() {
201</p>
202<pre class="code">return numAnimais;</pre>
203
204<p>
205}
206</p>
207</div>
208</body>
209</html>