Skip to content

Commit 0c3bef6

Browse files
authored
Add files
1 parent d1c2bf2 commit 0c3bef6

19 files changed

+674
-0
lines changed

PonteirosNovamente.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
8+
int array[] = {1, 2, 3, 4, 5};
9+
int *parray = &array[0];
10+
11+
int i = 0;
12+
13+
while(i < 5)
14+
{
15+
cout<<*parray << endl;
16+
parray--;
17+
i++;
18+
}
19+
20+
}

ProtegendoOsMembros.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <iostream>
2+
#include <string.h>
3+
4+
using namespace std;
5+
6+
class Linguagem
7+
{
8+
friend class LinguagemAmiga;
9+
friend void ClasseAmiga(Linguagem*);
10+
11+
protected:
12+
string nome;
13+
14+
public:
15+
void setNome(string nome)
16+
{
17+
this->nome = nome;
18+
}
19+
20+
string getNome()
21+
{
22+
return nome;
23+
}
24+
};
25+
26+
void ClasseAmiga(Linguagem* l)
27+
{
28+
cout << endl << "Classe amiga diz: " << l->nome;
29+
}
30+
31+
int main()
32+
{
33+
Linguagem l;
34+
35+
l.setNome("C++");
36+
cout << endl << l.getNome();
37+
38+
ClasseAmiga(&l);
39+
40+
return 0;
41+
}

RelembrandoConceitos.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
class Classbase
6+
{
7+
protected:
8+
int n1, n2;
9+
public:
10+
int n3, n4;
11+
12+
Classbase()
13+
{
14+
n1 = 1;
15+
n2 = 2;
16+
n3 = 3;
17+
n4 = 4;
18+
}
19+
};
20+
21+
class Subclasse : public Classbase
22+
{
23+
public:
24+
void foo()
25+
{
26+
cout << "SubClasse1: " << endl;
27+
cout << endl << n1 << endl;
28+
cout << n2 << endl << n3 << endl << n4 << endl;
29+
}
30+
};
31+
32+
int main()
33+
{
34+
return 0;
35+
36+
}

RetornoPorReferencia.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
typedef struct Pessoa
5+
{
6+
string nome;
7+
int idade;
8+
double peso, altura;
9+
}t_pessoa;
10+
11+
double& Calcular_imc(t_pessoa & pessoa)
12+
{
13+
double result = pessoa.peso / (pessoa.altura * pessoa.altura);
14+
double& imc = result;
15+
16+
return imc;
17+
}
18+
19+
int main()
20+
{
21+
22+
t_pessoa pessoa = {"Joao", 20, 92.45, 1.75};
23+
24+
cout << "IMC: " << Calcular_imc(pessoa) << endl;
25+
26+
return 0;
27+
}

RevisandoConceitos.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
class pessoa
6+
{
7+
private:
8+
int idade;
9+
int * vet;
10+
public:
11+
pessoa(int idade)
12+
{
13+
this->idade = idade;
14+
vet = new int[10];
15+
}
16+
~pessoa()
17+
{
18+
delete [] vet;
19+
}
20+
int obteridade()
21+
{
22+
return idade;
23+
}
24+
};
25+
26+
int main()
27+
{
28+
29+
pessoa *p = new pessoa(20);
30+
cout << p->obteridade() << endl;
31+
32+
delete p;
33+
34+
return 0;
35+
}

SobreCarregarConstrutor.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
class Carro
6+
{
7+
public:
8+
int ano;
9+
string nome;
10+
11+
Carro()
12+
{
13+
ano = 0;
14+
}
15+
Carro(int ano)
16+
{
17+
this->ano = ano;
18+
}
19+
};
20+
21+
int main()
22+
{
23+
24+
Carro carro;
25+
Carro carro2(2014);
26+
27+
cout << endl << "Ano carro contrutor 1: " << carro.ano;
28+
29+
cout << endl << "Ano carro contrutor 2: " << carro2.ano;
30+
31+
return 0;
32+
}

SobrecargaDeOperadores1.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
class Complexo
6+
{
7+
public:
8+
int real, imag;
9+
10+
Complexo(int real, int imag)
11+
{
12+
this->real = real;
13+
this->imag = imag;
14+
}
15+
16+
Complexo operator+(Complexo& c)
17+
{
18+
return Complexo(this->real + c.real, this->imag + c.imag);
19+
}
20+
};
21+
22+
int main()
23+
{
24+
Complexo c1(1, 2), c2(3, 4);
25+
26+
Complexo c3 = c1 +c2;
27+
28+
cout << "Parte real: " << c3.real << endl;
29+
cout << "Parte Imaginaria: " << c3.imag << endl;
30+
31+
return 0;
32+
}

SobrecargaDeOperadores2.cpp

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
class Pessoa
7+
{
8+
private:
9+
string nome;
10+
int id;
11+
public:
12+
13+
void inicializar(string novoNome, int novoId)
14+
{
15+
nome.replace(0, nome.size(), novoNome);
16+
id = novoId;
17+
}
18+
19+
Pessoa(string novoNome, int novoId)
20+
{
21+
//nome.replace(0, nome.size(), novoNome);
22+
//id = novoId;
23+
24+
inicializar(novoNome, novoId);
25+
}
26+
27+
Pessoa(Pessoa& p)
28+
{
29+
inicializar(p.nome, p.id);
30+
}
31+
32+
Pessoa& operator=(Pessoa& p)
33+
{
34+
if(this != &p)
35+
{
36+
inicializar(p.nome, p.id);
37+
}
38+
39+
return *this;
40+
}
41+
42+
string getNome()
43+
{
44+
return nome;
45+
}
46+
int getId()
47+
{
48+
return id;
49+
}
50+
51+
void mudarNome(char c)
52+
{
53+
nome[0] = c;
54+
}
55+
};
56+
57+
int main()
58+
{
59+
60+
Pessoa p1("Felipe", 1), p2("pedro", 2);
61+
62+
p1 = p2;
63+
64+
p1.mudarNome('C');
65+
66+
cout << "Nome: " << p1.getNome() << endl << "ID: " << p1.getId() << endl;
67+
cout << "Nome: " << p2.getNome() << endl << "ID: " << p2.getId() << endl;
68+
69+
return 0;
70+
}

0 commit comments

Comments
 (0)