Hi All,
I have to implement string class and write a program to perform string manipulation in Mystring class.
input:
"he is going to school"
output

Case 1: (n=1)
He school to going is 
Case 2: (n=2)
He is school to going
Case 3:(n=5) 
No changes
Case 4 n<=0
school to going is He.

int main()
{

char str[100]= "";
int n;
//Take input str and n from console

MyString obj (str);
obj.manipulate(n);//Actual logic
obj.display();// This will print output
return 0;
}

can anybody throw some light on approach to for case 1 and case 2.

As I understand it, you have to write a manipulate function that uses a select case. Depending on the case seletion, you have to write some extra funtions that manipulate the input string accordingly.

It looks like the "manipulations" involve re-ordering the words, so the first stage would be to split the input into an array of words.

ps: Have you identified the relationship between n and the exact manipulation yet?

exact manipulation would be based on user selection value which is supported
only by n=1,2,5 and n<=0.
important part of this task is to display the values through print function based on manipulate function input.

Have you identified the relationship between n and the exact manipulation yet?

Agree. That needs to be nailed down.

exact manipulation would be based on user selection value which is supported

If n is 5 and the number of words is 13, what order do you print the 13 words? There should be some pattern. I believe James is asking that, though I won't assume, so I'll say that I am asking that. It's not 100% obvious what that order is from the example, but I would imagine there's a pattern i.e. (5,6,7,8,9,10,11,12,0,1,2,3,4) would be a possible pattern. That doesn't appear to be YOUR pattern though.

important part of this task is to display the values through print function based on manipulate function input.

It's unclear what the exact assignment is and where you are stuck. James mentioned splitting the input line into separate strings and you didn't respond to that, so does that mean you're not stuck there? I can't "shed light" on it since I can't figure out the pattern nor do I know where you're stuck and where you're not.

You seem to have two distinct parts to your project:

1) Code and test a class String

2) Use that class (and perhaps some of its methods) to process lines of words.

It may be helpful to start with part 2) and there, using the C++ string until 2) is ALL working properly.

Then, after all tests ok, sub in slight changes in code to 2) to use you own 'home grown' String class. (The methods you need in part 2) may guide what methods you need to code in your part 1) class String coding project.

if n=5 , no changes are required.Even i am not able to predict any pattern here.
is there any way to change the order of string with single API ?
kindly share the code base it will help me to proceed further with any possible and efficient approach.

Nobody is goig to "share the code base" with you. That's what we call cheating.
If you are prepared to do some work, and try to code it yourself, we will help you. That's what we call learning.

I doubt very much that you will find an existing API that does the mainipulation you want - but then the whole idea of this exercise is that you learn by coding it yourself!

ps: Maybe the pattern is that you keep the first n words and reverse the order of the remaining words? (In which case it's two loops and no need to consider any "cases".)

Even if I was willing to write the code for you, I wouldn't know how. If YOU don't know what the pattern is, how can we? And without knowing that pattern, the best coder on the planet couldn't write it for you.

You're making us guess way too much here. There is a spec somewhere which contains the needed information that you are not supplying (in advance, I'm not telling you to copy and paste verbatim the entire spec. But you need to write a post that contains all the relevant information and an example/explanation that makes the input/output obvious. Yours isn't).

Maybe the pattern is that you keep the first n words and reverse the order of the remaining words?

That might be it. Output for n=3 and n=4 would help confirm or deny that theory. But the OP says 3 and 4 are not "supported". If your pattern is the correct one, there'd be no reason to not support those values, plus I can't see why anyone would use a switch statement for that pattern(as you mentioned).

As a pet peeve, I DO see teachers sometimes organize a multistage assignment requiring students to code in ways no one would code for the beginning parts, then "fix it" towards the end. I've never liked that approach and it makes it extremely hard to help people. I have no idea whether that's the case here.

Till now i have implemented reverse case and no change case only but don't know how to implement other cases . This question was asked me during written test of big MNC company so thought i should share the same in this forum as i couldn't crack the same .
Thanks all for your analysis and sharing thought on this.

If you have the reverse case figured out the others are just a substring being reversed and concatenated with the unreversed part. If you're using std::string in your class to hold the base value, then std::string.find() can be used to find the spaces between words. Then pass the substring indicated to the reverse function.

I believe the task is to split the sentence into words and replace the n-th word with the last one. If n<0, the last word goes to the beginning of the sentence. In the example, when n>= "number of words in sentence", nothing happens.
It's up to you to write the code once you understand what is expected. As said earlier, otherwise it would be just cheating in school.

replace the n-th word with the last one

If you check that against the examples you will see that some words are reversed in order. It's not just a simple 1-word replacement

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.