Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 17
  1. #1

    [c++]1° traccia esercizi

    ciao. devo portare 3 esercizi in c++ sviluppati in dev c++. la prima traccia è la seguente:

    codice:
    Sviluppare un programma in C++ che legge e mnemorizza una 
    stringa di caratteri (massimo 60) contente una serie di 
    parole separate da spazio e stampa a video solo le parole più
     lunghe di 7 caratteri. Il programma deve essere strutturato 
    cme segue: 1)Il main legge e memorizza la stringa,utilizza 
    una funzione estraiParola e stampa le parole più lunghe di 7
     caratteri. 2)La funzione estraiParola data la stringa e 
    l'indice da cui iniziare la scansione della stringa 
    restituisce la parola identificata a partire dalla posizione
     i e la sua lunghezza

    con char stringa[60] e cin >> stringa memorizzo la stringa nell'array.
    con un ciclo while ripeto la funzione più volte scorrendo nell'indice.
    ma la funzione?come fa a controllare una parola?lo fa quando arriva ad uno spazio vuoto?


    grazie a tutti
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  2. #2
    ho fatto un mezzo algoritmo..dateci un'occhiata

    codice:
    char estraiParola(char stringa, char & i) {
     
       while(int i=0) {
           int contatore_spazio = 0;
           if(stringa[i]!=" ") {
           i++; 
           else { 
               if(((i - 1) - (contatore_spazio + 1) >= 7) {
                   cout << stringa[i - 7] stringa[i - 6] stringa[i - 5] stringa[i - 4]
                   stringa[i - 3] stringa[i - 2] stringa[i - 1] << endl; }
                   contatore_spazio = i;
                   i++
       }    
    }
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  3. #3
    up
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2005
    Messaggi
    10
    ma t serve una string o un char?
    se è char per cercare gli spazi che separano le parole devi usare gli apici singoli e non doppi. ' '
    se fosse string c sn delle funzioni utilissime ke praticamente fan tutto loro...e poi se è string nn usi un vettore

  5. #5
    credo proprio char!|
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  6. #6
    anche usando gli apici singoli mi da errore

    codice:
    if(stringa[i]!=" ") {
    
    "invalid types 'char[int]' for array subscript"
    :master:
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  7. #7
    codice:
    if(stringa[i]!=' ') {
    01010011 01100001 01101101 01110101 01100101 01101100 01100101 01011111 00110111 00110000
    All errors are undocumented features waiting to be discovered.

  8. #8
    ora mi da errore di sintassi in

    cout << stringa[i - 7] stringa[i - 6] stringa[i - 5] stringa[i - 4] stringa[i - 3] stringa[i - 2] stringa[i - 1] << endl;
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  9. #9
    anzi no...l'errore ora sta più avanti..nella riga estraiParola

    codice:
    #include <iostream>
    #include <stdlib.h>
    
    using namespace std;
    //PROTOTIPO KE STA IN HEADER.H
    char estraiParola(char stringa);
    //
    
    char estraiParola(char stringa) {
     
       while(int i=0) {
           char stringa[60];
           int contatore_spazio = 0;
           if(stringa[i]!=' ') {
           i++; 
            } else { 
               if(((i - 1) - (contatore_spazio + 1)) >= 7) {
                   cout << stringa[i - 7] << stringa[i - 6] << stringa[i - 5] << stringa[i - 4]
                   << stringa[i - 3] << stringa[i - 2] << stringa[i - 1] << endl; }
                   contatore_spazio = i;
                   i++;
       }    
    }   
           
    int main(int argc, char *argv[])
    {
        int esci = 1;
        int i = 0;
        char stringa[60];
        do{
            cout << "Inserisci una stringa di caratteri (massimo 60)" << endl;
            cin >> stringa;
          estraiParola(stringa);
    cout << stringa;
      
      
      
      
      
      
      
      
      cin.ignore(1);
      system("cls");
    }   while(esci);
    
      system("PAUSE");	
      return 0;
    }
    http://codecanyon.net/category/all?ref=Manuelandro
    And I bet she told a million people that she'd stay in touch, Well all the little promises they dont mean much,When theres
    memories to be made

  10. #10
    Originariamente inviato da Manuelandro
    anzi no...l'errore ora sta più avanti..nella riga estraiParola

    codice:
    #include <iostream>
    #include <stdlib.h>
    
    using namespace std;
    //PROTOTIPO KE STA IN HEADER.H
    //devi passare una stringa non un carattere !
    char estraiParola(char *stringa);
    //
    
    char estraiParola(char *stringa)
    {
       // Qual'è la condizione di uscita dal ciclo? 
       while(int i=0) {
           char stringa[60];
           int contatore_spazio = 0;
           if(stringa[i]!=' ') {
           i++; 
            } else { 
               if(((i - 1) - (contatore_spazio + 1)) >= 7) {
                   cout << stringa[i - 7] << stringa[i - 6] << stringa[i - 5] << stringa[i - 4]
                   << stringa[i - 3] << stringa[i - 2] << stringa[i - 1] << endl; }
                   contatore_spazio = i;
                   i++;
           }   
       // Questa funzione deve restituire un char...
       }
       return 0; 
    // manca una parentesi...
    } 
    
    
          
    int main(int argc, char *argv[])
    {
        int esci = 1;
        int i = 0;
        char stringa[60];
        do{
            cout << "Inserisci una stringa di caratteri (massimo 60)" << endl;
            cin >> stringa;
          estraiParola(stringa);
    cout << stringa;
      
    
      cin.ignore(1);
      system("cls");
    }   while(esci);
    
      system("PAUSE");	
      return 0;
    }
    Mi sembra ci sia dell' altro da sistemare (non ho controllato tutto).

    Non si capisce in che modo vuoi individuare le parole nella stringa
    01010011 01100001 01101101 01110101 01100101 01101100 01100101 01011111 00110111 00110000
    All errors are undocumented features waiting to be discovered.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.