My Project for Finals

1.)Using Turbo C++ write a program that will accepts a string and output the words per line.For example an input of

The World is beautiful
will produce

The
World
is
beautiful..


Kindly help me guys.I have to submit it on Thursday ,i can do it now for i am still doing report in my work...Thanks
...Seriously? Do you mean to have us do your assignment for you?
This is honestly a five minute assignment if you put in the littlest effort. All you are doing is replacing spaces with newlines.
i can't use my installer here in computer...i'm just a beginner and all i know is basic now..im not totally saying do my assignment..even a instruction is a big help for me...thanks...

.im working 7:00 am - 7:00 pm and have my class at 7:00 pm - 10:00 pm...


.thanks.
Well it's hard for us to help we do not know what you know since you have provided no code for us to help with. The assignment is basically this:
1) Read in a sentence - std::getline will do nicely.
2) Replace the spaces with newlines
to further evaluate what giblit said,

1. declare a char array.
char str[ N ]; // where N is the length of the array and since you are using turbo c and std::string doesn't exist

2. use cin.getline(); to be able to "get the whole line" instead of cin >> w/c can only read a word.
1
2
cin.getline( str, N );
// where str is the array we declared earlier and N is the length of it 


3. use a for loop to check each element of str if it is equal to a space ' ', if so, then replace it w/ a newline '\n'
it should look something like :
1
2
3
4
for( int i = 0; i < strlen( str ); i++ ) { // strlen() returns the length of the string passed to it.
    // if str[ i ] is equal to space ' '
    //    then replace str[ i ] with '\n'
}


4. then normally print it :
cout << str;

remember to include the necessary headers, namely
1
2
3
// since you're using turbo C
<iostream.h> // for cout, istream::getline()
<string.h> // for strlen() 


Pilipino ka pla ?? kaya mu yan !!
Last edited on
.these help a lot...

.maraming salamat!


.
Topic archived. No new replies allowed.