944,068 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2465
  • C++ RSS
Oct 16th, 2006
0

I need help with my homework!

Expand Post »
Hi,

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

http://www2.filehost.to/files/2006-1...4316_cplus.jpg

Thanks in advance
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Latifa is offline Offline
4 posts
since Oct 2006
Oct 16th, 2006
0

Re: I need help with my homework!

Show your effort now, then we can help you with the next step.
http://www.daniweb.com/techtalkforum...cement8-2.html
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 16th, 2006
0

Re: I need help with my homework!

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]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Latifa is offline Offline
4 posts
since Oct 2006
Oct 16th, 2006
0

Re: I need help with my homework!

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?
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 16th, 2006
0

Re: I need help with my homework!

I got till here,
Quote ...
#include <iostream>
#include <string>

using namespace std;



int main ()
{

string name;
cout<< "Enter name";
cin>> name;
Last edited by Latifa; Oct 16th, 2006 at 5:59 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Latifa is offline Offline
4 posts
since Oct 2006
Oct 16th, 2006
0

Re: I need help with my homework!

Maybe this will kick-start you
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main ( ) {
  5. string s = "hello world";
  6. cout << "The length is " << s.length() << endl;
  7. cout << "The 5th character is " << s[4] << endl;
  8. return 0;
  9. }

There are all sorts of different methods for manipulating strings.
http://www.sgi.com/tech/stl/basic_string.html
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 17th, 2006
0

Re: I need help with my homework!

There must be a cin
Quote ...
#include <iostream>
#include <string>
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;
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Latifa is offline Offline
4 posts
since Oct 2006
Oct 17th, 2006
0

Re: I need help with my homework!

to define a string variable,
C++ Syntax (Toggle Plain Text)
  1. string s;
then read in,
C++ Syntax (Toggle Plain Text)
  1. 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.
Last edited by jdarvwill; Oct 17th, 2006 at 12:06 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jdarvwill is offline Offline
1 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Object and classes doubt
Next Thread in C++ Forum Timeline: Another C++ N00B Begging For Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC