954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

I need help with my homework!

Hi,

I need help with my homework please, its due tommorow and i prommise to show my efforts in the next days :sad:

http://www2.filehost.to/files/2006-10-16_03/214316_cplus.jpg

Thanks in advance :)

Latifa
Newbie Poster
4 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

Show your effort now, then we can help you with the next step.
http://www.daniweb.com/techtalkforums/announcement8-2.html

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

I know that it means this:


below is a string of 20 chars
[01234567890123456789]

The first twelve are
[012345678901]

The last twelve are
[890123456789]

the middle 4 of the first string are shown marked with () below:
[0123(4567)08901]

the middle for of the last twelve are shown marked with () below:
[8901(2345)6789]

Latifa
Newbie Poster
4 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

Yes, I've read your jpeg.

But what code have you managed to come up with so far?


For example, can you read the string from the user, and just print it back to the user?
Can you add to that printing the length of the string?

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

I got till here,
#include
#include

using namespace std;

int main ()
{

string name;
cout<< "Enter name";
cin>> name;

Latifa
Newbie Poster
4 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

Maybe this will kick-start you

#include <iostream>
#include <string>
using namespace std;
int main ( ) {
    string s = "hello world";
    cout << "The length is " << s.length() << endl;
    cout << "The 5th character is " << s[4] << endl;
    return 0;
}

There are all sorts of different methods for manipulating strings. http://www.sgi.com/tech/stl/basic_string.html

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

There must be a cin
#include
#include
using namespace std;
int main ( ) {
string = name;
cin >> name;
cout << "The length is " << s.length() << endl;
cout << "The 5th character is " << s[4] << endl;


return 0;
}

Latifa
Newbie Poster
4 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

to define a string variable,

string s;


then read in,

cin >> s;


then using the string stl use the necessary functions.

in particular look at, s.length(), s.substr()
the rest is trivial once you know how to use these functions.

jdarvwill
Newbie Poster
1 post since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You