Advertisement

05.04.2008 at 09:03PM PDT, ID: 23375672
[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 to make sortsentence() and findwordfunction?

Tags: c, c++
As you see the code, I made twenty random sentences by using vectors.  I want to know howto sort them in alphabetical by using the function. I have to use the array of pointers. I think the pointers will be the hardest one for me. :) Thank you. I am not sure what I was doing on sortsentence function, so I made it comments. Thank you for reading.
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:
#include <iostream>
#include <vector>
#include <cstring>
#include <ctime> 
#include <cstdlib> 
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++)
	{
		char buffer[256];
 
		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();
 
		buffer=new char[(strlen(article[iarticle1])+strlen(noun[inoun1])+strlen(verb[iverb])+strlen(preposition[ipreposition])+strlen(article[iarticle2])+strlen(noun[inoun2])+1)];
		strcpy(buffer,article[iarticle1]);
		strcat(buffer," ");
		strcat(buffer,noun[inoun1]);
		strcat(buffer," ");
		strcat(buffer,article[iarticle1]);
		strcat(buffer," ");
		strcat(buffer,verb[iverb]);
		strcat(buffer," ");
		strcat(buffer,preposition[ipreposition]);
		strcat(buffer," ");
		strcat(buffer,noun[inoun2]);
		strcat(buffer,".");
	}
 
}
///////////////////////////////////////////////////////////////
void outputSentence(vector<char*> & sentence)
{
for(int i=0; i < sentence.size(); i++)
	cout<<i+1<<'.  '<< sentence[i]<<endl;
}
///////////////////////////////////////////////////////////////
/*
void sortSentence(vector<char*> & sentence)
{
	int* temp;
	int i,j;
	char* p, *po = sentence;
	
      if (*p > *sentence[j+1])
       { temp = hello[j];
         hello[j] = hello[j+1];
         hello[j+1] = temp;
       }
 
}
*/
///////////////////////////////////////////////////////////////
 
 
int main()
{
 	vector <char*> sentence(20);
	createVector(sentence);
   outputSentence(sentence);
   //sortSentence(sentence);
   //outputSentence(sentence);
		system("pause");
}
 
////////////////////////////////////////////////////////////////////////////////////////////
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: jiwonman
Solution Provided By: jaime_olivares
Participating Experts: 1
Solution Grade: A
Views: 0
Translate:
Loading Advertisement...
05.04.2008 at 09:49PM PDT, ID: 21498168

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.04.2008 at 09:59PM PDT, ID: 21498189

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 06:56PM PDT, ID: 21504286

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 07:45PM PDT, ID: 21504425

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 07:57PM PDT, ID: 21504460

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 08:06PM PDT, ID: 21504486

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 08:09PM PDT, ID: 21504496

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 08:21PM PDT, ID: 21504546

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.04.2008 at 09:49PM PDT, ID: 21498168
A side comment:
Why to use vector<char *> ?
Looks like a mix of C library and STL.
You can use STL 'string' type instead.
 
05.04.2008 at 09:59PM PDT, ID: 21498189
I have to use vectors with pointers. if I mixed it with other things, I am sure I am making a mistake, so please you can point that out for me too.. :)
 
05.05.2008 at 06:56PM PDT, ID: 21504286
hmm anyone?
 
05.05.2008 at 07:45PM PDT, ID: 21504425
also how do i make fist char to be uppercase in every sentences?
 
05.05.2008 at 07:57PM PDT, ID: 21504460
still I don't find a justification to use vector<char *>.
Anyway, your sort function has many errors and does not iterate through all the array. It can be a bubble sort, like:

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;
                  }
            }
      }
}
Accepted Solution
 
05.05.2008 at 08:06PM PDT, ID: 21504486
I was thinking about bublesort, but it was playing with my head for few hours. I thought strcmp will give me false answers, cuz of blank in the strings..
 thank you!! and I have two more question.

I am trying to uppercase the first letter of every sentences by using toupper()
but it is not working..
I get c3644 error 'function' : cannot convert parameter number from char to char*

also, how can I make a function to find the word from the sentences  that user is looking for? I am thinking about using a pointer to match with the word and the other one on the char vector.
 
05.05.2008 at 08:09PM PDT, ID: 21504496
the bubblesort works like a charm.. :) I think I am going to use it wisely. Thank you.
 
05.05.2008 at 08:21PM PDT, ID: 21504546
for findword function.. it's somewhat like..

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

I think I am going to to make a function something like..
strindex (char *s, char *t)


 
 
05.06.2008 at 05:05AM PDT, ID: 21506491
Hi, sorry for not being there, I was asleep. about the toupper(), you don't need it. Use stricmp instead.
 
 
05.06.2008 at 07:34AM PDT, ID: 21507597
haha it's okay. everything was helpful.. Also,
if you have a chance, can you take a look at my code on
http://www.experts-exchange.com/Programming/Languages/CPP/Q_23378729.html

Thank you.
 
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628