Programação Estruturada 2 - Aula 05 - Código Fonte

237 visualizações

Publicada em

Código Fonte da Aula 05

Publicada em: Tecnologia
  • Seja o primeiro a comentar

  • Seja a primeira pessoa a gostar disto

Programação Estruturada 2 - Aula 05 - Código Fonte

  1. 1. Programação Estruturada II CÓDIGO FONTE DA AULA 05 PONTEIROS – 2015.1 Prof. Thomás da Costa thomasdacosta@gmail.com
  2. 2. TEMA: Aula de LAB 04 – PONTEIROS – 2015.1 Nos exercíciosdessaaula, iremosseguiros seguintespassos: 1) Copiar os exercíciospara o Dev-C++ e analisar sua execução. 2) Após a cópia, escrevernesta folhao que foi identificadonaexecuçãodo programa. 3) Por favormanter a atençãona aula, evitaracessosà internete outrasdistrações,para melhorentendimento dos programas Boa Codificação Prof. Thomás da Costa CENTRO UNIVERSITÁRIO ANHANGUERA DE SÃO PAULO Unidade Marte: Av. Braz Leme, 3.029 – Santana – São Paulo (SP) – 02022-011 – (11) 2972-9000 DISCIPLINA: Programação Estruturada II PROFESSOR: Thomás da Costa ALUNO: RA: TURMA: PERÍODO: DATA: CURSO: AVALIAÇÃO: ASS. PROFESSOR:
  3. 3. 1) explique a funcionalidade doprograma abaixo: #include <iostream> using namespace std; int main() { int *ptr; cout << ptr << endl; } Resposta: _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ 2) explique a funcionalidade doprograma abaixo: #include <iostream> using namespace std; int main() { int *ptr; int valor; valor = 1500; ptr = &valor; cout << ptr << endl; cout << *ptr << endl; } Resposta: _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________
  4. 4. 3) explique a funcionalidade doprograma abaixo: #include <iostream> using namespace std; int main() { int *ptr; int valor; int total; valor = 1600; ptr = &valor; total = *ptr; cout << *ptr << endl; cout << total << endl; } Resposta: _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ 4) explique a funcionalidade doprograma abaixo: #include <iostream> using namespace std; int main() { // PROGRAMA COM ERRO NAO COMPILA !!!! int *ptr_inteiro; double valor; valor = 345.76; ptr_inteiro = &valor; cout << *ptr_inteiro << endl; } Resposta: _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________
  5. 5. 5) explique a funcionalidade doprograma abaixo: #include <iostream> using namespace std; int main() { int *ptr_inteiro; double valor; valor = 345.76; ptr_inteiro = (int *)&valor; cout << *ptr_inteiro << endl; } Resposta: _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ 6) explique a funcionalidade doprograma abaixo: #include <iostream> using namespace std; int main() { int *ptr_inteiro; double valor_1; double valor_2; valor_1 = 345.76; ptr_inteiro = (int *)&valor_1; valor_2 = *ptr_inteiro; cout << valor_1 << endl; cout << *ptr_inteiro << endl; cout << valor_2 << endl; } Resposta: _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________
  6. 6. 7) explique a funcionalidade doprograma abaixo: #include <iostream> using namespace std; int main() { int *ptr; int x; ptr = &x; *ptr = 999; cout << &x << endl; cout << ptr << endl; cout << *ptr << endl; } Resposta: _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ 8) explique a funcionalidade doprograma abaixo: #include <iostream> using namespace std; int main() { int *ptr; int x; ptr = &x; *ptr = 999; cout << "Valor Original:" << ptr << endl; ptr++; cout << "Incremento:" << ptr << endl; ptr--; cout << "Decremento:" << ptr << endl; (*ptr)++; cout << "Inc. valor:" << *ptr << endl; (*ptr)--; cout << "Dec. valor:" << *ptr << endl; } Resposta: _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________
  7. 7. 9) explique a funcionalidade doprograma abaixo: #include <iostream> using namespace std; int main() { double *ptr; double x; ptr = &x; *ptr = 999.98; cout << "Valor Original:" << ptr << endl; ptr++; cout << "Incremento:" << ptr << endl; ptr--; cout << "Decremento:" << ptr << endl; (*ptr)++; cout << "Inc. valor:" << *ptr << endl; (*ptr)--; cout << "Dec. valor:" << *ptr << endl; } Resposta: _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________
  8. 8. 10) explique afuncionalidade doprograma abaixo: #include <iostream> using namespace std; int main() { int *ptr_1; int *ptr_2; int x, y; ptr_1 = &x; ptr_2 = &y; cout << ptr_1 << endl; cout << ptr_2 << endl; cout << (ptr_1 > ptr_2) << endl; cout << (ptr_1 < ptr_2) << endl; ptr_1 = &x; ptr_2 = &x; cout << (ptr_1 == ptr_2) << endl; } Resposta: _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________
  9. 9. 11) explique afuncionalidade doprograma abaixo: #include <iostream> #include <strings.h> using namespace std; int main() { char valores[100]; char *ptr; strcpy(valores, "Isto é um teste"); ptr = valores; cout << valores << endl; cout << ptr << endl; ptr = (char *)"Isto é um outro teste"; cout << ptr << endl; cout << valores[3] << endl; cout << *(ptr+3) << endl; } Resposta: _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________
  10. 10. 12) explique afuncionalidade doprograma abaixo: #include <iostream> #include <strings.h> #include <stdlib.h> using namespace std; int main() { int *ptr_1, *ptr_2; int valor_1, valor_2; char valor_convertido[100]; ptr_1 = &valor_1; ptr_2 = &valor_2; valor_1 = 316; valor_2 = 206; *ptr_1 = *ptr_1 << 2; cout << *ptr_1 << endl; *ptr_1 = *ptr_1 >> 2; cout << *ptr_1 << endl; itoa(*ptr_1, valor_convertido, 2); cout << "Valor binário:" << valor_convertido << endl; itoa(*ptr_2, valor_convertido, 2); cout << "Valor binário:" << valor_convertido << endl; itoa(*ptr_2 & *ptr_1, valor_convertido, 2); cout << "Operador AND:" << valor_convertido << endl; itoa(*ptr_2 | *ptr_1, valor_convertido, 2); cout << "Operador OR:" << valor_convertido << endl; itoa(*ptr_2 ^ *ptr_1, valor_convertido, 2); cout << "Operador XOR:" << valor_convertido << endl; itoa(~*ptr_2, valor_convertido, 2); cout << "Operador NEG:" << valor_convertido << endl; } Resposta: _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________ _______________________________________________________________________________________________

×