Program on strings - Can anyone solve this program?

Reply

Join Date: Dec 2008
Posts: 3
Reputation: gharish is an unknown quantity at this point 
Solved Threads: 0
gharish gharish is offline Offline
Newbie Poster

Program on strings - Can anyone solve this program?

 
0
  #1
Dec 2nd, 2008
Introduction
You are going to design a program which will print out each line of its input that contains a specified pattern or string of characters. For example, searching for the pattern "Humpty" in an input text file that contains the following:

In Sixteen Hundred and Forty-Eight
When England suffered the pains of state
The Roundheads lay siege to Colchester town
Where the King's men still fought for the crown
There One-Eyed Thompson stood on the wall
A gunner of deadliest aim of all
From St. Mary's Tower his cannon he fired
Humpty Dumpty was its name
Humpty Dumpty sat on a wall
Humpty Dumpty had a great fall
All the king's horses and all the king's men
Couldn't put Humpty together again
Humpty Dumpty sat on a wall
Humpty Dumpty was two inches tall
He fell down and broke his shell
Poor little egg, I wish him well

should produce the following output on the screen:

Humpty Dumpty was its name
Humpty Dumpty sat on a wall
Humpty Dumpty had a great fall
Couldn't put Humpty together again
Humpty Dumpty sat on a wall
Humpty Dumpty was two inches tall


The program is to incorporate some additional features. It will allow four optional command line arguments. One option will ensure that each line of output is preceded with its line number, and the second will allow the user to view all of the lines except those that match the pattern. The third option will ignore the case of the strings being matched. The fourth option available, will ensure that only a count of the number of text lines selected is displayed rather than the lines themselves.


A common convention with C++ programs is that an argument beginning with a minus sign introduces an optional flag or parameter.

Using

-n to request line numbers,
-i to ignore case when performing the pattern match, and
-x to represent the except option,
-c to represent the count option,
the command: lookfor -n -i -x humpty test.txt

should produce the output:

1: In Sixteen Hundred and Forty-Eight
2: When England suffered the pains of state
3: The Roundheads lay siege to Colchester town
4: Where the King's men still fought for the crown
5: There One-Eyed Thompson stood on the wall
6: A gunner of deadliest aim of all
7: From St. Mary's Tower his cannon he fired
11: All the king's horses and all the king's men
15: He fell down and broke his shell
16: Poor little egg, I wish him well

the command: lookfor -c Dumpty test.txt

should produce the output:
5


The following are all examples of valid command lines:

lookfor Herne book.txt
lookfor -c 30000 salaries.doc
lookfor -x "the last time it happened" hope.fie
lookfor -n strcpy program.cpp
lookfor -inx "Fred Bloggs" names.doc
lookfor -i -n -x "Fat Controller" trains.doc
lookfor -x -n 25000 salaries.doc
lookfor -xic humpty humpty.txt
Last edited by gharish; Dec 2nd, 2008 at 1:58 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 3
Reputation: gharish is an unknown quantity at this point 
Solved Threads: 0
gharish gharish is offline Offline
Newbie Poster

Re: Program on strings - Can anyone solve this program?

 
0
  #2
Dec 2nd, 2008
can anyone do this for me....
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Program on strings - Can anyone solve this program?

 
1
  #3
Dec 2nd, 2008
"Can" - yes, lots of people here "can"
"Will" - probably not, it's your homework, you make an effort which is more than an exerise in copy and paste of your assignment.

http://www.catb.org/~esr/faqs/smart-questions.html
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 26
Reputation: babusek is an unknown quantity at this point 
Solved Threads: 1
babusek babusek is offline Offline
Light Poster

Re: Program on strings - Can anyone solve this program?

 
0
  #4
Dec 2nd, 2008
Go Through The Java Regular Expressions
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 3
Reputation: gharish is an unknown quantity at this point 
Solved Threads: 0
gharish gharish is offline Offline
Newbie Poster

Re: Program on strings - Can anyone solve this program?

 
0
  #5
Dec 2nd, 2008
I tried it but i was unable to do it.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,780
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 113
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: Program on strings - Can anyone solve this program?

 
0
  #6
Dec 2nd, 2008
Originally Posted by babusek View Post
Go Through The Java Regular Expressions
I guess he is looking for C++ code .
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 314
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: Program on strings - Can anyone solve this program?

 
0
  #7
Dec 2nd, 2008
Show us what you tried so far.
Last edited by Luckychap; Dec 2nd, 2008 at 4:39 am.
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Program on strings - Can anyone solve this program?

 
0
  #8
Dec 2nd, 2008
> I tried it but i was unable to do it.
So post it then.

Then we can help you and the help will be targetted to what you actually need (not what you wanted with your first post).
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC