Advertisement

05.05.2008 at 08:43PM PDT, ID: 23378457
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

How can I make a function to find the word from sentence vectors?

Tags: c++
I got everything done, except I dont know how toUpper case the first letter of each sentences..
it is not working for me.

Also, I have to make a function to find the word from the sentences.
I am thinking about make a function strindex (char *s, char *t), which returns the position of the leftmost
occurrence of t in s, or -1 if there is none
ex)
1. One dog jumped from some boy.
2. Some girl jumped to any dog.
3. &..
&..

//ask for a word pattern
enter a word: dog
dog is at position 5 of line 1.
dog is at position 25 of line 2.

Thank you for looking
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
#include <iostream>
#include <vector>
#include <cstring>
#include <ctime> 
#include <cstdlib> 
#include <string>
using namespace std;
 
void createVector(vector<char*> &);
void createSentence(vector<char*> &, vector<char*> & , vector<char*> &, vector<char*> & ,vector<char*> & ); 
void sortSentence(vector<char*> &);
void outputSentence(vector<char*> &);
 
///////////////////////////////////////////////////////////////////////////
void createVector(vector<char*> & sentence)
{
	int size1,size2,size3,size4;
 
	cout<<"enter size for article:"; 
	cin>> size1;
	vector<char*> article(size1);
	cout<<"enter size for noun:"; 
	cin>> size2;
	vector<char*> noun(size2);
	cout<<"enter size for verb:"; 
	cin>> size3;
	vector<char*> verb(size3);
	cout<<"enter size for preposition:"; 
	cin>> size4;
	vector<char*> preposition(size4);
 
	for(int i=0;i<size1;i++)
	{
		
		char buffer[256]; 
		cout<<"Type your article #" << (i+1)<< ":";
		cin>>buffer; 
		article[i] = new char[(strlen(buffer) +1)];
		strcpy(article[i],buffer);
 
	}
 
	//noun
	for(int i=0;i<size2;i++)
	{
		char buffer[256]; 
		cout<<"Type your noun #" << (i+1)<< ":";
		cin>>buffer; 
		noun[i] = new char[(strlen(buffer)+1)] ;
		strcpy(noun[i],buffer);;
 
	}
 
 
 
	//Verb
	for(int i=0;i<size3;i++)
	{
		char buffer[256]; 
		cout<<"Type your verb #" << (i+1)<< ":";
		cin>>buffer; 
		verb[i] = new char[(strlen(buffer)+1)] ;
		strcpy(verb[i],buffer);
 
	}
 
 
	//Preposition
	for(int i=0;i<size4;i++)
	{
		char buffer[256]; 
		cout<<"Type your Preposition #" << (i+1)<< ":";
		cin>>buffer; 
		preposition[i] = new char[(strlen(buffer)+1)] ;
		strcpy(preposition[i],buffer);;
 
	}
	createSentence(article,noun,verb,preposition,sentence);
 
}
 ///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
void createSentence(vector<char*> & article, vector<char*> & noun, vector<char*> & verb, vector<char*> &preposition, vector<char*> & sentence)
{
	srand (static_cast<int>(time(NULL)));
	for(vector<char*>::size_type x = 0; x < sentence.size(); x++)
	{
 
 
		int iarticle1 = rand() % (int)article.size();
		int iarticle2 = rand() % (int)article.size();
		int inoun1 = rand() %(int) noun.size();
		int inoun2 = rand() % (int)noun.size();
		int iverb  = rand() % (int)verb.size();
		int ipreposition = rand() % (int)preposition.size();
 
		sentence[x]=new char[strlen(article[iarticle1])+strlen(noun[inoun1])+strlen(verb[iverb])+strlen(preposition[ipreposition])+strlen(article[iarticle2])+strlen(noun[inoun2])+1];
		strcpy(sentence[x],article[iarticle1]);
		strcat(sentence[x]," ");
		strcat(sentence[x],noun[inoun1]);
		strcat(sentence[x]," ");
		strcat(sentence[x],verb[iverb]);
		strcat(sentence[x]," ");
		strcat(sentence[x],article[iarticle2]);
		strcat(sentence[x]," ");
		strcat(sentence[x],preposition[ipreposition]);
		strcat(sentence[x]," ");
		strcat(sentence[x],noun[inoun2]);
		strcat(sentence[x],".");
 
	}
 
}
///////////////////////////////////////////////////////////////
void outputSentence(vector<char*> & sentence)
{
 
for(int i=0; i < 20; i++)
{
	cout<< i+1 << '.';	
 
	cout<< sentence[i]<<endl;
 
}
 
}
///////////////////////////////////////////////////////////////
void sortSentence(vector<char*> & sentence)
{
     bool ended = false;
     char *temp;
     int size = (int)sentence.size();
 
      while (!ended)
      {
            ended = true;
            for (int i=0; i<size-1; i++)
            {
                  if (strcmp(sentence[i], sentence[i+1]) > 0)
                  {
                        temp = sentence[i];
                        sentence[i] = sentence[i+1];
                        sentence[i+1] = temp;
                        ended = false;
                  }
            }
      }
}
 
strindex (char *s, char *t)
{
 
}
 
///////////////////////////////////////////////////////////////
 
 
int main()
{
 	vector <char*> sentence(20);
	
   createVector(sentence);
   
   outputSentence(sentence);
   
   sortSentence(sentence);
   
   cout<<endl<<endl<<endl<<endl<<"AFTER SORTING"<<endl;
 
   outputSentence(sentence);
 
 
		system("pause");
}
 
////////////////////////////////////////////////////////////////////////////////////////////
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: jiwonman
Solution Provided By: josgood
Participating Experts: 1
Solution Grade: A
Views: 4
Translate:
Loading Advertisement...
05.05.2008 at 09:33PM PDT, ID: 21504778

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 09:33PM PDT, ID: 21504781

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 09:39PM PDT, ID: 21504808

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 09:43PM PDT, ID: 21504816

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 09:48PM PDT, ID: 21504834

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 09:51PM PDT, ID: 21504844

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 09:53PM PDT, ID: 21504850

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 09:54PM PDT, ID: 21504856

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.05.2008 at 10:02PM PDT, ID: 21504877

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.05.2008 at 09:33PM PDT, ID: 21504778
I still didnt find how to uppercase the first letter of sentences, also I made the function for searching a word...

char* strindex (char *s, char *t)
{
 int pl = (int)strlen(s);
 int sl = (int)strlen(t);
           int pi = 0, si = 0, last=0;
           do {
               if(s[pi] == t[si]) {
                   pi++;
                   si++;
               }
               else {   pi = 0;
                        last++;
                        si = last;
               }
           } while (pi < pl && si < sl);
           if (pi == pl)
              return si-pl;
           else
              return -1;

it gives
 error C2440: 'return' : cannot convert from 'int' to 'char *'
1>        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
error C2440: 'return' : cannot convert from 'int' to 'char *'
1>        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

Am I in right shape? the output should be like

enter a word: dog
dog is at position 5 of line 1.
dog is at position 25 of line 2.

 
05.05.2008 at 09:33PM PDT, ID: 21504781
by the way, here's the main func for searching word

  while(true)
   {
        
         char word[80];
         string s;
         cout<<"enter a word: ";
         cin>>word;
         for(int i=0;i<20;i++)
         strindex(sentence[i], word);
        
         cout<<"do you want to finish this application? than type end";
         cin>> s;
         if(s =="end")
            return 0;

   }
 
05.05.2008 at 09:39PM PDT, ID: 21504808

Rank: Master

To uppercase the first word of each sentence
   #include <ctype.h>
and then in createSentence, you can
            strcpy(sentence[x],article[iarticle1]);
            *sentence[x] = toupper(*sentence[x]);
 
05.05.2008 at 09:43PM PDT, ID: 21504816
Thank you...josgood!! pointer... !!
 
05.05.2008 at 09:48PM PDT, ID: 21504834

Rank: Master

Compilation problem can be fixed with
   if (pi == pl)
      return s+si;
   else
      return 0;

You are returning a char*, so the match needs to be something like "starting pointer + offset".  Returning NULL (or 0) is a valid way of saying there is no such address.
 
05.05.2008 at 09:51PM PDT, ID: 21504844

Rank: Master

strindex seems to be confused about whether it is keeping an offset into the string or is keeping a word count.
         last++;  // word count
         si = last; // offset into the string

If strindex is returning a word count, then I suggest you always
      return last;
where last is initially zero and is incremented every time a word is found.

Keep "last" separate from your "pi" and "si" string offsets.

It seems like you want the signature to be "int strindex".

Am I making sense?

 
05.05.2008 at 09:53PM PDT, ID: 21504850
I am trying to make an ouput look like

enter a word: dog
dog is at position 5 of line 1.
dog is at position 25 of line 2.

after I read your comments, I think I am going to wrong way.
 
05.05.2008 at 09:54PM PDT, ID: 21504856
I am making a function strindex (char *s, char *t), which returns the position of the leftmost
occurrence of t in s, or -1 if there is none..
 
05.05.2008 at 10:02PM PDT, ID: 21504877

Rank: Master

Good!  It sounds like you are on the right track.

I will be going to bed in the next few minutes.

If you have any further problems, post and I'll be happy to answer in the morning.
Accepted Solution
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628