besoin d'aide pour mon TP en c++
Répondre à la discussion
Affichage des résultats 1 à 4 sur 4

besoin d'aide pour mon TP en c++



  1. #1
    inviteaf6ca43d

    Smile besoin d'aide pour mon TP en c++


    ------

    J'ai du mal à faire mon TP en c++. L'énoncé se trouve ici: http://www.colvir.net/prof/georges.d.../TP1_H2010.htm


    Et voici mon code (brouillon) que j'ai fait jusqu'a présent:

    Code:
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <stdlib.h>
    #include <stdio.h>
    
    
    using namespace std;
    
    const int m=50,n=30;
    
    void saisicarte(string tab[m][n], string* valeur)
    {
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(tab[m][n] = 0)
                {
                    tab[m][n] = valeur;
                }
            }
        }
    }
    
    
    
    void Affichercarte(string* tab[m][n])
    {
        cout << "Voici l'affichage de la carte:" << endl;
    
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
               cout << tab[i][j];
            }
            cout << endl;
        }
    }
    
    
    int x,y;
    
    void Remplircarte(string* tab[m][n],string* fichier_x_y)
    {
       tab[x][y] = fichier_x_y;
    }
    
    
    
    void Inserer(string* tab[m][n],string* fichier_x_y)
    {
        if(tab[x][y] == 0)
        {
            tab[x][y] = fichier_x_y;
        }
    }
    
    
    void Recherche(string* tab[m][n],string* valeur)
    {
       string position[m*n];
        int a = 0,b = 0;
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
    
               if(tab[x][y] == valeur)
                {
                   position[a] = i;//position de l'element;
                   position[b] = j;
                   a = a + 1;
                   b = b + 1;
                }
            }
        }
        //afficher le tableau des positions;
        for(int i=0;i<m;i++)
            {
                for(int j=0;j<n;j++)
                {
                    cout <<position[i][j];
                }
                cout << endl;
    
            }
    
    }
    
    
    void Supprimer(string* tab[m][n], string* valeur)
    {
    
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
    
               if(tab[i][j] == valeur)
                {
                    string decision,O,N;
                    cout << "Position: " << i <<"," << j<< endl;
                    cout << "Voulez-vous supprimer? (O)ui ou (N)on" << endl;
                    cin >> decision;
    
                    if(decision == O)
                    {
                        tab[i][j] = 0;
                    }else{
                        if(decision != N && decision != O)
                        {
                            cout<< "Commande invalide"<< endl;
                        }
                    }
    
                    //lire si o faire t[i][j] = 0;
                    //sinon rien
    
                }
            }
        }
    
    }
    
    /*
    void Enregistrer(tab[m][n])
    {
       //ouvrir un fichier
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)//parcourir le tableau
            {
               //fonction enregistrer
            }
            cout << endl;
        }
    }
    */
    
    void Quitter()
    {
        exit(0);
    }
    
    
    int main(int argc,char **argv)
    {
        int choix;
    
        cout << "Voici la liste des operations:" << endl
        << "1. Saisie le contenu d'une carte existante" << endl
        << "2. Afficher la carte" << endl
        << "3. Remplir la carte" << endl
        << "4. Rechercher un element" << endl
        << "5. Inserer un element" << endl
        << "6. Supprimer un element" << endl
        << "7. Enregistrer la carte courante" << endl
        << "8. Quitter" << endl
        << "Veuillez choisir une operation: ";
    
        cin >> choix;
    
        switch (choix)
        {
            case 1: saisicarte();
                    break;
        }
    
    //fin
    Le programme n'est pas terminer, car je suis un peu bloquer et je suis au courant qu'il y a quelques erreurs de compilation. Si quelqu'un pourrait m'aider a les corriger, ce serait sympa. Mais ce que je veux savoir, c'est comment on fait la fonction Enregistrer. Puis, je ne suis pas vraiment comment utiliser argv et argc dans mon programme. Je ne sais pas si je suis dans la bonne voix, ce serait super si quelqu'un peut m'aider a completer le TP ou donner des indications tres détaillées.


    J'ai mis en place la balise "Code" symbolisée par qui permet une lecture plus claire de ton code.

    yoda1234.

    -----
    Dernière modification par yoda1234 ; 18/02/2010 à 06h54.

  2. #2
    ProgVal

    Re : besoin d'aide pour mon TP en c++

    Bonjour,

    Et si tu nous les donnais ces erreurs de compilations ?
    Parce que vu que tu utilises des bibliothèques win32 et que je suis sous Linux, je ne peux pas essayer de compiler pour voir...

    Cordialement,
    ProgVal

  3. #3
    inviteaf6ca43d

    Re : besoin d'aide pour mon TP en c++

    Code:
    ||=== TP1, Debug ===|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp||In function `void saisicarte(std::string (*)[30], std::string*)':|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp|18|error: ambiguous overload for 'operator=' in '*(((std::string*)tab) + 6120u) = 0'|
    C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\basic_string.h|426|note: candidates are: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]|
    C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\basic_string.h|437|note:                 std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]|
    C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\basic_string.h|451|note:                 std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp|20|error: invalid conversion from `std::string*' to `char'|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp|20|error:   initializing argument 1 of `std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp||In function `void Enregistrer()':|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp|133|error: `m_nNbLignes' was not declared in this scope|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp|135|error: `m_nNbColonnes' was not declared in this scope|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp|137|error: `m_sNoms' was not declared in this scope|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp|135|warning: unused variable 'm_nNbColonnes'|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp|133|warning: unused variable 'm_nNbLignes'|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp||In function `int main(int, char**)':|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp|13|error: too few arguments to function `void saisicarte(std::string (*)[30], std::string*)'|
    C:\Documents and Settings\Owner\My Documents\TP1\main.cpp|174|error: at this point in file|
    ||=== Build finished: 8 errors, 2 warnings ===|


    Ca va etre difficile de retrouver les lignes ici. Mais le plus important c'est comment construire mon code selon l'énoncé. En passant, je pense que j'ai trouvé comment faire la fonction Enregistrer mais j'ai pas encore tester. Le voici:

    Code:
    void Enregistrer()
    {
    ofstream save("test.txt");
     int i=0;
     int j=0;
        for(i = 0; i<m_nNbLignes;i++)
        {
            for(j=0;j<m_nNbColonnes;j++)
            {
                if(!m_sNoms[i][j].empty()) // TODO: Enlever la condition
                {
                    save <<m_sNoms[i][j];save <<" ";
                    save <<i; save <<" ";
                    save <<j; save <<endl;
                }
            }
        }
    }

    Dites moi ce que vous en penser. Si vous pouvez m'aider a construire le reste, ce sera sympa. Merci

    J'ai mis le code dans des balises Code . C'était illisible.
    JPL, modérateur
    Dernière modification par JPL ; 18/02/2010 à 15h40.

  4. #4
    Jack
    Modérateur

    Re : besoin d'aide pour mon TP en c++

    avant d'aller plus loin, tu ne trouve pas un problème entre l'appel de la fonction:
    Code:
            case 1: saisicarte();
    et sa définition:
    Code:
    void saisicarte(string tab[m][n], string* valeur)
    {
        for(int i=0;i<m;i++)
        {
    
    etc ...
    A+

  5. A voir en vidéo sur Futura

Discussions similaires

  1. besoin d'aide pour mon dm
    Par invite70618ed5 dans le forum Mathématiques du collège et du lycée
    Réponses: 1
    Dernier message: 04/11/2009, 17h30
  2. Besoin d'aide pour mon dm !
    Par invite6cf4f760 dans le forum Mathématiques du collège et du lycée
    Réponses: 5
    Dernier message: 18/01/2008, 17h06
  3. besoin d'aide pour mon TPE
    Par invite96a10c2f dans le forum TPE / TIPE et autres travaux
    Réponses: 3
    Dernier message: 18/11/2006, 09h57
  4. besoin d'aide pour mon dm
    Par invite4041a5c6 dans le forum Mathématiques du collège et du lycée
    Réponses: 8
    Dernier message: 30/09/2006, 11h23
  5. Besoin d'aide pour mon projet
    Par inviteb0f7ec27 dans le forum Électronique
    Réponses: 3
    Dernier message: 08/11/2004, 21h10
Découvrez nos comparatifs produits sur l'informatique et les technologies.