Computer problems,Computer help
*AX SOFT>>>Programming & Design

HELPP! with this c++ program please("Find & Replace"), have my annual lab test tomm!!?


Thanks! and the program i need help with is :
A c++ prog to find a word from a paragraph (both word and para typed in by user) and replace it with a word he/ she specifies. Basically the text editor program for "Find and Replace" function.

(I know i have to use a 2 dimensional arrays but i am stranded midway.. i accept a 2-d char array and a word but how to compare that word in the 2-d array, i mean, how does one distinguish words in arrays??? )

Please be quick!! Thanku so much

Guess you're right..

1. i'm using a 2-d matrix to enter the paragraph like:

for(int i=0;i<10; i++)
gets(line[i]);

(for a 10-line para)

2.you've understood it right.. it's hard to manipulate, do u need more details, let me know?

I think we need some more information about this problem before we can help you.

First, how are you reading in the paragraph of text? Is the user going to enter it, or do you read it from a file?

Second of all, do you have to use a two-dimensional array? STL strings would be easier (#include <string>). The only reason you would need a 2-d array is if you store the paragraph as a matrix of characters (rows and columns). But the drawback to that is that it is a pain to manipulate such data. If you can use stl strings, or even a 1-d array of characters things would be much easier.

Let us know.
Thanks.
--------------------------------------...

Gotcha, a 2-d array will work fine. You need some nested loops to accomplish this task.

I'm going to give you some pseudo-code, and you will need to translate that into C++.

After you read in the martix, you will need a loop to go through each line the matrix. Your ( for i=0 to 9) loop will work for that. Once you get each line with that for loop, you will have to loop through each of the characters in that line in search of the first character in the special word....

for (i= 0 to 9) {
__for (j = 0 to (length of line[i] -1) ) {
____if (line[i][j] == word[0]) {
______/* when we get to this point in the code, we know that
_________we have found the first letter of the word, now all we
_________need to do check to see if the following letters match
_________the word as well
______*/

______bool found = true; // tracks if we found the word
______k = 0; // index for the following loop
______// this while loop compares each letter
______while (k < (size of word) and found==true) {
________if (find_word[k] == line[i][k])
__________k++; // letter did match, so compare next letter
________else
__________found = false; // happens when letter doesnt match
______}

______// now, if all the letters matched found will equal true,
______// but if one didnt match, found will have been set to false
________if (found == true) {
________// now we need a loop to replace line[i] with one that
________// has the new word in it

________char templine = line[i]; // save old line
________int temp=0;

________// put new word into line
________for (int m= j to (size of word-1) ){
__________line[i][m] = replace_word[temp];
__________temp++;
________}

________// this will put the remaining part of the old line
________// after the new word in the array
________int temp2 = j+(size of replace_word);
________for (int n= (j+size of find_word) to (size of templine-1) {
__________line[i][temp2] = templine[n];
__________temp2++;
________}
______}

____}
__}
}

There are probably some errors in this (for instance, in the while loop you will probably need to check if you have reached the end of line[i]). But in any case, that will work for a basic algorithm for you.

Good luck!
pw

import java.util.*;

public class Student
{
private String id;
private String firstname;
private String lastname;
private ArrayList <String> letters = new ArrayList <String> ();

public Student(String i, String f, String l)
{
id= i;
firstname = f;
lastname = l;
}

public String getID()
{
return id;
}

public String getFirstname()
{
return firstname;
}

public String getLastname()
{
return lastname;
}

public void addGrades(String g)
{
letters.add(g);
}

public double computeGPA()
{
double gpa = 0.0;
for (int i = 0; i < letters.size(); i++)
{
String ltrgrade = letters.get(i);
if (ltrgrade.equals("A"))
gpa = gpa + 4.0;
else if (ltrgrade.equals("B"))
gpa = gpa + 3.0;
else if (ltrgrade.equals("C"))
gpa = gpa + 2.0;
else if (ltrgrade.equals("D"))
gpa = gpa + 1.0;
else
gpa = gpa + 0.0;
}

if (gpa == 0.0)
{
gpa = 0.0;
}

else
{
gpa = gpa / letters.size();
}

return gpa;

}
}

Use std::string charAarray[12] ;

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • I am lost ...in VB.NET?

    I'm not sure about the version of VB.net because i never bought it but used in my school first of all learn VB which is simialar to basic (or Qbasic) language and different from java the...

  • How to run my newly created program in Visual C++?

    to compile or build: select Build and then Build Solution will compile once it has been built you can run your program from the Debug menu by selecting Start Without Debugging -------- EDIT:...

  • ASP ==>grid views?

    Yes, you can. The DataSource property in .Net 2.0 and up can accept anything with an IEnumerable interface, and it will use your public properties to auto-populate columns. E.g. List<MyBusi...

  • PLEASE HELP me start writing this PROGRAM in JAVA?

    Damn that's a large program. Might I ask what it's for? So, unless you are familiar with event listeners and things that respond to user input using the keyboard, I recommend you plac...

  • Help with a very simple C# code.?

    Bashar Y was almost there :) but it's a little different. In C# it would be: textbox1.Text = this.Width.ToString(); or Height of course, like he said. Make sure you don't forget T...

  • BlueJ (java) help! due today!?

    System.out.println("Does not look easy, may be you can contact a java expert live at website like ...

  • I hate movie maker...?

    Press cntrl-alt-delete and go to task manager.... close everything. Then, open the file. if this does not work, u saved it on a corrupt file or something.

    ...
  • Help with C++ please! my program is not working why? please help me! To start with, i get alot errors...?

    I can't quite understand your assignment. It sounds to me like what you are supposed to do is collect the number of registrants for an unknown number of companies, calculate each company&#...

  •  

    Categories--Copyright/IP Policy--Contact Webmaster