CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Oct 2012
    Posts
    11

    Declaring Array at runtime

    I can not set the size of my array while running porgrama. Is there any way to do this in C + +?

    ---- code ------

    #include <iostream>
    #include <string>

    using namespace std;

    int MAX = 80;

    class aluno
    {
    private:
    char nome[80];
    int serie, grau;
    static int contador;
    public:
    aluno();
    aluno(char n[], int s, int g);
    void quantidade() {cout << "\nQuantidade de alunos: " << contador;}
    void imprime();
    };

    int aluno::contador;

    aluno::aluno(){
    cout << "\nNome: "; cin >> nome;
    cout << "\nSerie: "; cin >> serie;
    cout << "\nGrau: "; cin >> grau;
    contador++;

    }
    aluno::aluno(char n[], int s, int g)
    {
    strcpy(nome,n);
    serie = s;
    grau = g;
    contador++;
    }

    void aluno::imprime()
    {
    cout << "\nNome do Aluno: " << nome;
    cout << "\nNSerie do Aluno: " << serie;
    cout << "\nGrau do Aluno: " << grau;
    }

    int main()
    {
    int nr_alunos = 1;
    cout << "\nQuantos Alunos voce quer Cadastrar? "; cin >> nr_alunos;
    if (nr_alunos <= 0)
    exit;
    else
    aluno a[nr_alunos];

    return 0;
    }
    Last edited by Alex_Brazil; October 21st, 2012 at 05:25 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured