473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

working with textfiles in c++

a text file contains a number of English sentences and each line in the file holds just one sentence. consider a class which will perform the following:
1 reads these sentences and stores them in an array
2 displays the sentences from the array created in 1
3 sorts the sentences into alphabetical order
4 given a word, determines how many times the given word occurs in all the sentences.

please, any one out there with an idea!
Oct 17 '06 #1
2 1890
arne
315 Expert 100+
a text file contains a number of English sentences and each line in the file holds just one sentence. consider a class which will perform the following:
1 reads these sentences and stores them in an array
2 displays the sentences from the array created in 1
3 sorts the sentences into alphabetical order
4 given a word, determines how many times the given word occurs in all the sentences.

please, any one out there with an idea!
Do you have written any code to start with? I don't think there will be too many people solving your assignments for you ... but there will be people willing to help if you come up with concrete problems or questions, I guess :-)
Oct 17 '06 #2
D_C
293 100+
Pseudocode for #1
Expand|Select|Wrap|Line Numbers
  1. open text file
  2. // it would be nice if it told you how many lines to make it
  3. while(not end of file)
  4. {
  5.   str = get next line
  6.   if(array full)
  7.     make a bigger array
  8.   insert str into next open spot in array
  9.   increment index for next open
  10. }
  11. close the text file
Pseudocode for #2
Expand|Select|Wrap|Line Numbers
  1. for(int i = 0; i < NEXT_OPEN_ENTRY; i++)
  2. {
  3.   output each sentence
  4. }
Pseudocode for #3
Expand|Select|Wrap|Line Numbers
  1. for(each array entry)
  2. {
  3.   select a default "minimum" string.
  4.   for(each unsorted array entry)
  5.   {
  6.     compare the minimum string to each entry
  7.     if each entry is alphabetically less than the current minimum
  8.       then it's your new minimum
  9.   }
  10.   swap the minimum string with the default
  11. }
You still have to figure out how to compare two strings, which isn't too bad. There should be a method of some sort to do it for you.

Pseudocode for #4
Expand|Select|Wrap|Line Numbers
  1. read in the word to search for
  2. initialize a counter to zero
  3. for(each string)
  4. {
  5.   while(not end of string)
  6.   {
  7.     while(not the end of the string) 
  8.     {
  9.       compare it with pattern
  10.       if there isn't a match
  11.        then fast forward to non-alphabetic characters
  12.     }
  13.     if a complete match
  14.       increment the counter
  15.     while(non-alphabetic characters)
  16.       fast forward to alphabetic characters
  17. }
Oct 17 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jorgen Gustafsson | last post by:
Hi, im trying to write a small progam to compare data in 2 textfiles. I want to search for values that doesnt exist in File2. The result should be "3" in the example below but Im not able to do...
2
by: Gary | last post by:
I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key. Syntax: System.Windows.Forms.SendKeys.Send("^(P)"); This is not working ..what could be the...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
16
by: moxmormor | last post by:
Hi, I've tried to upload a picture using the function imagecreatefromgif, with a script as simple as possible to avoid miss spellings and stuff like that. I've ran the following line of code to...
1
by: =?Utf-8?B?UmFm?= | last post by:
Hello, I have to write an application that scans textfiles for certain words. I'm talking about approximately 5000 words. The only way I can think of to do this is to scan each textfile for each...
9
by: Stef Mientki | last post by:
hello, I want to search multiple textfiles (python source files) for a specific word. I can find all files, open them and do a search, but I guess that will be rather slow. I couldn't find...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.