Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

?
Lv 6

C++ Beginner Help !!!????!?!?!?

I've been trying to create this program but I'm getting so lost, Help please

This is the assignment

Create a String object with the string “C++ Programming is Fun!”

Using the functions in the C++ string class (as listed on pp582-583 of the text), determine and

printout the following information:

1) The length of the string.

2) The character at index 5.

a) Please put single quotes around that character in the output.

3) The ASCII number of the character at index 5. (We can convert any character to its

integer equivalent by using a cast: (int) before the character.)

4) The substring starting at position 19 and ending at position 21 (inclusive).

5) The index of the first ‘g’ character in the string.

6) The index of the second ‘g’ character in the string.

And this is what I have done so far.. .But I know Its wrong

#include <iostream>

#include <string.h>

using namespace std;

int main()

{

string my_string = "C++ Programming is Fun!";

cout << "The length of my_string is " << my_string.length() << endl;

cout << "The character at index 5 is '" << my_string.at('5');

cout << "' // Put single quotes around output " << endl;

cout << "The ASCII number of the character at index 5 is " << my_string.at(5) << endl;

cout << "The substring starting at position 19 and ending at position 21 is " << my_string.substring(19-21) << endl;

cout << "The index of the first 'g' character in the string is " << my_string.indexof(g) << endl;

cout << "The index of the second 'g' character in the string is " << my_string.indexofsecond(g) << endl;

system("PAUSE");

return 0;

}

1 Answer

Relevance
  • 9 years ago
    Favorite Answer

    Take a look at this page: http://www.cplusplus.com/reference/string/string

    Find out what functions you will need for each task.

    Once you know what to do, give it a try.

    If you are unsuccessful, send your code to me via email and i will help you correct it.

    Source(s): Programmer.
Still have questions? Get your answers by asking now.