Hi guys

I'm doing a program for one of my class but the teacher asked us to write a language mangler to modfiy a sentence and make it nonsentence

And he want us :
- If any word has length 9 or more characters, insert into the word after the sixth letter either "-er-" or "-uh-" or "-um-". Cycle through these inclusions in a regular fashion.
- If a word ends in 's', add 'es' to it.
- Change any instance of "is" to "are", "he" to "him", "she" to "her".

Everything without using pointers and strings
we have to us NTCA

thank you for your help
jack

Recommended Answers

All 12 Replies

>Everything without using pointers and strings
By "string" you mean the std::string class? Assuming you can store the characters for a word somewhere (like an array or a vector), it's fairly easy to follow those rules. However, without knowing what level of C++ you're at, I'll probably end up giving you ideas that are too advanced to be useful. So please post your most recent attempt to solve the problem so that we can better help you.

>we have to us NTCA
The North Texas Cricket Association? No no, the Northumbrian Tent Camping Association! :D Don't just throw out acronyms unless they're pretty much guaranteed to be well known or easily researched.

Thank you for you replay

Actully he told us to choice randomly from a text file so I'm trying to use this function

void randPick(istream input, char phrase[])
{

int rad;
rad = rand()% 11;

input.open("input.txt");
for (int i=0; i <= rad; i++)
{
getline(input,phrase);

}

return;
}

but it's not working

if I can use arrays to get the hole phrase I think it'll be good

NTCA : null-terminated character arrays :)

Thank you for your help

>rad = rand()% 11;
How do you know there are ten lines in the file? How do you know that's always going to be true? It's fine for a single project where the size of the file is a hard limit, but in any reasonably robust code you'd want to count the lines first, or find a way of getting a random line without getting the size of the file first.

>but it's not working
My doctor hates it when I tell him that "something's not right", just like I hate it when you tell me that "it's not working". How is it not working?

>NTCA : null-terminated character arrays
I've been programming for over ten years. I've probably read more code and technical papers than most professional programmers with similar experience, and this is the first time I've seen that particular acronym. A search for that particular acronym on google produces exactly one hit, and that hit is a homework assignment. In other words, don't expect anyone to know what the hell you're talking about when you say NTCA. :icon_rolleyes:

Thank you

I used rad = rand()% 11; becuase he gave us a single file to work with so

I test the function but it's not doing any thing just stuck until I use CTRL + C but I see it's creat an output.txt file but nothing on it :(

Thank you again

No one here is going to give you code to do your homework. You need to think about the problem some bit more than you have so far, post all the code you've got and any compiler errors or i/o errors, and then we'll help you fix it.

>input.open("input.txt");
input is an object of type std::istream. std::istream doesn't have an open member function. Your code shouldn't compile.

>getline(input,phrase);
The non-member function form of getline is for std::strings only. phrase is a pointer to char, so this shouldn't compile.

Maybe something more like this (still not ideal, but oh well):

bool randPick ( const char *filename, char phrase[], int size )
{
  std::ifstream in ( filename );
  bool rc = false;

  if ( in ) {
    int line_number = rand() % 11;
    int i;

    for ( i = 0; i < line_number; i++ ) {
      if ( !in.getline ( phrase, size ) )
        break;
    }

    rc = i > 0;
  }

  return rc;
}

This poster appears to be from my school, as I'm reasonably sure that there's a small chance of someone else doing an exactly identical assignment written so poorly. They make the instructions a challenge to read in itself. No joke

Anywhoo, I felt the need to be helpful, the instructions are as follows:
------
Specificationizers: You are to write a program that will read text from an input stream containing standard english text. (The particular stream used is to be chosen by the user of the program. Thus, prompt them for it by asking if the input is to be from the keyboard or from a file. This should be the first thing the program does.) After the text is run through your MANGLER, it is to be streamed out. (At the same time you prompt the user for the preferred input stream, prompt also for the output stream. In either case, input or output, if a file stream is chosen, accommodate that request with a file stream connected to the file the user chooses.) For this assignment, use null-terminated character arrays, not STL string class strings.
---------
So I am operating under the assumption that he wants us to stream the information into NTCA arrays -to make it harder than necissary in order to reinforce habits/ideas.

Which unfortunately if I understand it does not allow you to stream the information into an array of strings(which would be easy to modify).

As such I am assuming that some of the above code posted is roughly what we're to do, however, what I am doing would not really be ethical to share with you.

I'd tell you in person, but I don't know who you are, so anyway, they don't stop you from emailing them to ask the same type of question, generally they're helpful in that respect.

Your MANGLER is to do the following:

* If any word has length 9 or more characters, insert into the word after the sixth letter either "-er-" or "-uh-" or "-um-". Cycle through these inclusions in a regular fashion.
* If a word ends in 's', add 'es' to it.
* Change any instance of "is" to "are", "he" to "him", "she" to "her".
* The randomness: you will randomly pick a phrase from a file and randomly insert it into the text.

>They make the instructions a challenge to read in itself. No joke
I've got bad news for you, slick. In professional projects, you often don't get specifications that are even as good as this one. When you do get good specifications, they're often so detailed that it's like deciphering encrypted codes (see the language standard for an excellent example). No joke.

>to make it harder than necissary in order to reinforce habits/ideas.
More likely to make the exercise in any way challenging as std::string has member functions that neatly solve the problem without any thought from you. With C-style strings you have to actually put some effort into a working solution.

>Which unfortunately if I understand it does not allow
>you to stream the information into an array of strings
I don't see that restriction anywhere. In fact, while you're prohibited from using std::string, there doesn't seem to be a restriction on std::vector, so you can greatly simplify how you handle the array of strings by making it a vector of strings.

>They make the instructions a challenge to read in itself. No joke
I've got bad news for you, slick. In professional projects, you often don't get specifications that are even as good as this one. When you do get good specifications, they're often so detailed that it's like deciphering encrypted codes (see the language standard for an excellent example). No joke.

Fair enough, I bow to your experience :)

I don't see that restriction anywhere. In fact, while you're prohibited from using std::string, there doesn't seem to be a restriction on std::vector, so you can greatly simplify how you handle the array of strings by making it a vector of strings.

You are correct about that, however we have yet to go over vectors, and they *deeply* frown upon using things we eh 'shouldn't' know yet.

Example: using a cmath library for rounding up (it was a double of # of gallons) using using the ceil function. Apparently that annoyed them enough that it required a separate chastising email to be sent.

That would be my preferred method in this case, should I be allowed, but I got it done last night, mind numbing.

Ultimately, I was clarifying the instructions for the other student, but I do appreciate your advice. As painful as it was to think through and then write in a efficient way, I did it. I hope he got it done.

>and they *deeply* frown upon using things we eh 'shouldn't' know yet.
Probably because they don't want you to discover that your teachers, who should be experts on what they teach, are actually only about half a chapter ahead of you in learning C++. ;)

>Ultimately, I was clarifying the instructions for the other student
I know, but I feel the need to stick my finger in most of the pies on this forum.

>Which unfortunately if I understand it does not allow
>you to stream the information into an array of strings
I don't see that restriction anywhere. In fact, while you're prohibited from using std::string, there doesn't seem to be a restriction on std::vector, so you can greatly simplify how you handle the array of strings by making it a vector of strings.

:icon_rolleyes:

>and they *deeply* frown upon using things we eh 'shouldn't' know yet.
Probably because they don't want you to discover that your teachers, who should be experts on what they teach, are actually only about half a chapter ahead of you in learning C++. ;)

I can think of other possibilities :icon_wink:

>I can think of other possibilities
I can't[1]. As a teacher[2] I have no problem with students going above and beyond. The only good excuse for holding someone back when he's willing and capable of more is being embarrassed at not being able to keep up.

[1] Though I haven't given it much thought.
[2] Not as my primary occupation, of course. I actually work for a living. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.