Results 1 to 3 of 3

Thread: Sentence with the least number of words (c++)

  1. #1
    Join Date
    Mar 2013
    Posts
    2
    Platforms
    Windows

    Question Sentence with the least number of words (c++)

    Hello,

    I don't know how to find the sentence with the least number of words, I figure out how to count the words, but I don't know how to use strlen and strcpy to find sentence with the least number of words. Hope someone can help! Here is the text of the assignment (I only need how to find a name with the least number of words):

    Create a field of 'N' animal shelter names. Find a name with the least number of words and copy it to a string'AZN'. In the 'AZN' string, transform every second letter of the first word into a capital letter.
    In the function 'ko' find the sum of ASCII codes of the changed string 'AZN'. In the function 'np' transform the sum of ASCII codes into a system with a base of 22. Create a 1D dynamic field 'Z' in which you will input the number of characters of every word from the 'AZN'.Print the name field, transformed 'AZN' string, newly created equivalent with a base of 22 and the 'Z' dynamic field.

    Qt Code:
    1. void main()
    2. {
    3. char shelter[N][min],AZN[min];
    4. int i,j,n,counter;
    5.  
    6. cout << "Enter the number of shelter: ";
    7. cin >> n;
    8. cin.ignore();
    9.  
    10. int *Z=new int [n];
    11.  
    12. for(i=0;i<n;i++)
    13. {
    14. cout << "Enter the name of " << i+1 << ". shelter: ";
    15. cin.getline(shelter[i],min);
    16.  
    17. counter=1;
    18.  
    19. for(j=0;j<strlen(shelter[i]);j++)
    20. {
    21. if(shelter[i][j]==' ')
    22.  
    23. counter++;
    24.  
    25. *(Z+i)=counter;
    26.  
    27. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Sentence with the least number of words (c++)

    First of all if it is a C++ assignment then use C++ approaches and not C approaches. Either way you need an array where you will keep a number of words in each string and then just find the index of the array that holds the smallest number. That's the most trivial approach.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2013
    Posts
    2
    Platforms
    Windows

    Default Re: Sentence with the least number of words (c++)

    Thank you!

Similar Threads

  1. Replies: 1
    Last Post: 5th March 2012, 06:34
  2. Is this sentence correct?
    By SWEngineer in forum Newbie
    Replies: 6
    Last Post: 21st June 2011, 01:56
  3. Highlighting individual words of a sentence
    By kellorooney in forum Newbie
    Replies: 1
    Last Post: 16th April 2010, 04:51
  4. Adding 3 words to Button with specified length betwwen words
    By chikkireddi in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2007, 11:08
  5. Replies: 5
    Last Post: 16th March 2007, 08:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.