Skip to content

Instantly share code, notes, and snippets.

@werbet
Last active August 29, 2015 14:08
Show Gist options
  • Save werbet/9650dd9892f923cc9060 to your computer and use it in GitHub Desktop.
Save werbet/9650dd9892f923cc9060 to your computer and use it in GitHub Desktop.
Código da Aula de C++ de 05/11/2014
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
class Aluno
{
private:
char* nome;
char* curso;
public:
Aluno()
{
}
Aluno(char* n, char* c)
{
nome = new char[50];
curso = new char[50];
strcpy(curso, c);
strcpy(nome, n);
}
void imprime()
{
printf("%s estuda %s!\n", nome, curso);
}
};
class Lab
{
private:
Aluno* alunos;
int quantidade;
char* nome_lab;
public:
Lab(char* nome, Aluno* alunos_lab, int qtd)
{
nome_lab = new char[50];
strcpy(nome_lab, nome);
quantidade = qtd;
alunos = new Aluno[quantidade];
memcpy(alunos, alunos_lab, sizeof(Aluno) * quantidade);
}
void imprime()
{
printf("O laboratorio %s contem os seguintes alunos: \n", nome_lab);
int i;
for(i = 0; i < quantidade; i++)
alunos[i].imprime();
printf("-------------------------------------------\n");
}
};
int main()
{
char* nome;
char* curso;
Aluno* vetor;
int i;
int n;
int j;
printf("Digite a quantidade de alunos: \n");
scanf("%d", &n);
vetor = new Aluno[n];
for(i = 0; i < n; i++)
{
nome = new char[10];
printf("Digite o nome do aluno: \n");
scanf("%s", nome);
curso = new char[10];
printf("Digite o curso: \n");
scanf("%s", curso);
vetor[i] = Aluno(nome, curso);
}
Lab k_09("K-09", vetor, n);
k_09.imprime();
Lab k_11("K-11", vetor, n);
k_11.imprime();
system("PAUSE");
return 0;
}
//------------------------VERSÃO MODIFICADA-------------------------------------------------------------
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
class Aluno
{
private:
char* nome;
char* curso;
public:
Aluno()
{
}
Aluno(char* n, char* c)
{
nome = new char[50];
curso = new char[50];
strcpy(curso, c);
strcpy(nome, n);
}
void imprime()
{
printf("%s estuda %s!\n", nome, curso);
}
};
class Lab
{
private:
Aluno* alunos;
int quantidade;
char* nome_lab;
int capacidade;
public:
Lab(char* nome, int c)
{
quantidade = 0;
capacidade = c;
nome_lab = new char[50];
strcpy(nome_lab, nome);
alunos = new Aluno[capacidade];
}
void imprime()
{
printf("O laboratorio %s contem os seguintes alunos: \n", nome_lab);
int i;
for(i = 0; i < quantidade; i++)
alunos[i].imprime();
printf("-------------------------------------------\n");
}
void entrarAluno()
{
char* nome;
char* curso;
if(quantidade == capacidade)
{
printf("Laboratorio lotado!\n");
return;
}
nome = new char[50];
curso = new char[50];
printf("Digite o nome do aluno: \n");
//scanf("%s", nome);
gets(nome);
printf("Digite o curso: \n");
//scanf("%s", curso);
gets(curso);
alunos[quantidade] = Aluno(nome, curso);
quantidade++;
}
void entrarAlunos(int qtd)
{
for(int i = 0; i < qtd; i++)
entrarAluno();
}
};
int main()
{
Lab K09 = Lab("K09", 2);
K09.entrarAlunos(3);
K09.imprime();
system("PAUSE");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment