English to Pig Latin Program

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 16470 Views - Last Post: 06 March 2010 - 06:21 PM Rate Topic: -----

#1 Guest_bryant.yu809*


Reputation:

English to Pig Latin Program

Posted 05 March 2010 - 11:32 PM

Hey, do any of you know where I can find an english to pig latin program for C++? I don't really understand how to do it....
Is This A Good Question/Topic? 0

Replies To: English to Pig Latin Program

#2 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: English to Pig Latin Program

Posted 05 March 2010 - 11:34 PM

We won't do your homework for you. Show us the code you have tried so far (using [code [/code] tags), and we will help with specific issues.
Was This Post Helpful? 0
  • +
  • -

#3 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: English to Pig Latin Program

Posted 05 March 2010 - 11:34 PM

Post your code.

We are not going to give you a program without any effort on your part.
Was This Post Helpful? 0
  • +
  • -

#4 Guest_bryant.yu809*


Reputation:

Re: English to Pig Latin Program

Posted 05 March 2010 - 11:45 PM

View Postbryant.yu809, on 05 March 2010 - 10:32 PM, said:

Hey, do any of you know where I can find an english to pig latin program for C++? I don't really understand how to do it....


sorry all, here's my code 1st version:
///////////////////////////////////////////////////////////////////////
//File: piglatin.cc
//Written by: Bryant Yu
//Date: 3/1/10
//Course: C++, Period 5
///////////////////////////////////////////////////////////////////////
#include <iostream>
#include "apstring.h"

apstring phrase;

void prompt ();
void translation ();

main ()
{
	prompt ();
	translation ();
	return 0;
}

void prompt ()
{
	cout << "I can translate English sentences and phrases into ";
	cout << "Pig Latin." << endl << "Please type an English sentence";
	cout << " or phrase and then press<Enter>." << endl;
	getline (cin, phrase);
}

void translation ()
{
	int tempi=0; 
	apstring phraseword;
	int len=phrase.length();
	for (int i=0; i<phrase.length(); i++)
	{
		if (phrase[i]==' ' || phrase[i]=='!' || phrase[i]==';' ||
		phrase[i]==':' || phrase[i]==',' || phrase[i]=='?' || phrase[i]=='('
		|| phrase[i]==')' || phrase[i]=='"' || phrase[i]=='-' || phrase[i]=='.' || 
		i==phrase.length())
		{
			if (i==phrase.length()-1)
				phraseword=phrase.substr(tempi, phrase.length());
			else
				phraseword = phrase.substr(tempi,i-tempi);
			tempi=i+1;
			bool firstwb=false;
			bool novowel=false;
			for (int j=0; j<10; j++)
			{
				for (int k=0; k<phraseword.length(); k++)
				{
					if (phraseword[k]!=vowels[j])
					{
						novowel=true;
					}
					if (k==phraseword.length()-1)
					{
						cout<<"Finished checking for no vowels" << endl;
						break;
					}
				}
				if (phraseword[0]==vowels[j])
				{
					cout << "First letter is a vowel" << endl;
					firstwb=true;
					phraseword+="yay";
					break;
				}
				else //if (phraseword.find(vowels[j])!=-1)
				{
					cout << "Vowels not at beginning, but in the word. " << endl;
					int vowelpos=phraseword.find(vowels[j]);
					if(vowelpos=-1)
					{
						apstring startw=phraseword.substr(0, vowelpos);
						apstring endw=phraseword.substr(vowelpos, phraseword.length());
						
						cout << startw << endl << endl;
						cout << endw << endl << endl;
					}
				}
			}
			if (novowel==true)
			{
				phraseword+="ay";
			}
			cout << phraseword << endl;
		}
	}
}






CODE V2!

///////////////////////////////////////////////////////////////////////
//File: piglatin.cc
//Written by: Bryant Yu
//Date: 3/1/10
//Course: C++, Period 5
///////////////////////////////////////////////////////////////////////
#include <iostream>
#include "apstring.h"

apstring phrase;

void prompt ();
void translation ();

main ()
{
     bool runBool=true;
     int count=0;
    do
    {
        prompt ();
	    translation ();
    } while (runBool==true);
	cin>>phrase;
	return 0;
}

void prompt ()
{
	cout << "I can translate English sentences and phrases into ";
	cout << "Pig Latin." << endl << "Please type an English sentence";
	cout << " or phrase and then press<Enter>." << endl;
	getline (cin, phrase);
}

void translation ()
{
	int tempi=0; 
	apstring phraseword;
	const apstring vowels = ("AaEeIiOoUu");
	int len=phrase.length();
	for (int i=0; i<phrase.length(); i++)
	{
		bool vowelBool=false;
		if (phrase[i]==' ' || phrase[i]=='!' || phrase[i]==';' ||
		phrase[i]==':' || phrase[i]==',' || phrase[i]=='?' || phrase[i]=='('
		|| phrase[i]==')' || phrase[i]=='"' || phrase[i]=='-' || phrase[i]=='.' || 
		i==phrase.length()-1)
		{
			if (i==phrase.length()-1)
				phraseword=phrase.substr(tempi, phrase.length());
			else
				phraseword = phrase.substr(tempi,i-tempi);
			tempi=i+1;
			len=phraseword.length();
			for (int w=0; w<len; w++)
			{
                for (int g=0; g<10; g++)
                {
                 switch (phraseword[w])
                 {
                         case 'a': case 'A': case 'E': case 'e': case 'I':
                         case 'i': case 'O': case 'o': case 'U': case 'u':
                         case vowels[g]:
                         {
                            if (w==0)
                            {
                               vowelBool=true;
                            }
                            else
                            {
                                cout << "There is a vowel in here somewhere...." << endl;
                            }
                            break;
                         }
                         default:
                         { 
                                vowelBool=false;
                                 break;
                         }
                }
                if (vowelBool==true)
                {
                    break;
                }
                }
                if(vowelBool==true)
                    break;
            }
            if (vowelBool==true)
            {
            phraseword+="yay";
            }
            else
            {
                phraseword+="ay";
            }
			cout << phraseword << endl;
		}
	}
}



Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)
Was This Post Helpful? 0

#5 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: English to Pig Latin Program

Posted 05 March 2010 - 11:49 PM

First, what's the problem?

Second, throw whatever reference or book you are using in the garbage right now.

Those headers and that syntax went out with the horse and buggy.
If you are taking a class, buy an updated book.
Was This Post Helpful? 0
  • +
  • -

#6 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: English to Pig Latin Program

Posted 05 March 2010 - 11:51 PM

Please use code tags when posting code.
Was This Post Helpful? 0
  • +
  • -

#7 Guest_bryant.yu809*


Reputation:

Re: English to Pig Latin Program

Posted 05 March 2010 - 11:55 PM

View Posteker676, on 05 March 2010 - 10:49 PM, said:

First, what's the problem?

Second, throw whatever reference or book you are using in the garbage right now.

Those headers and that syntax went out with the horse and buggy.
If you are taking a class, buy an updated book.


yea, I know, the teacher uses very old c++ lessons and creates his own files, thus the #include "apstring.h", I'm still working on V1, but on V2 I can't figure out how to find out which case statement was fufilled, and which vowel was found first in the word.
Was This Post Helpful? 0

#8 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: English to Pig Latin Program

Posted 06 March 2010 - 12:07 AM

I'm sorry but that code is completely unreadable. You need to indent it so we can get some idea where the loops and conditionals end.

Old is not the word. The last time I saw that kind of code was in a C++ book from 1995.
Learning C++ from a book that is 15 years old will not help you. It will hurt you.
Was This Post Helpful? 0
  • +
  • -

#9 carltech  Icon User is offline

  • What did you call me?
  • member icon

Reputation: 28
  • View blog
  • Posts: 997
  • Joined: 19-October 07

Re: English to Pig Latin Program

Posted 06 March 2010 - 12:07 AM

Your C++ teacher doesn't seem to know a lot about C++...or at least about the importance of keeping up with modern and good coding practices.

for instance you return 0 in a main function that doesn't have a type...that's just one of things I've noticed style-wise.

If you use the code tags then it will be more readable and easier for me to spot bugs. Oh and any compiler errors?

This post has been edited by carltech: 06 March 2010 - 12:08 AM

Was This Post Helpful? 0
  • +
  • -

#10 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: English to Pig Latin Program

Posted 06 March 2010 - 12:09 AM

That code doesn't (or shouldn't) even compile in C++. C++ does not allow default-int.

This post has been edited by PlasticineGuy: 06 March 2010 - 12:09 AM

Was This Post Helpful? 0
  • +
  • -

#11 Guest_bryant.yu809*


Reputation:

Re: English to Pig Latin Program

Posted 06 March 2010 - 12:11 AM

View Postcarltech, on 05 March 2010 - 11:07 PM, said:

Your C++ teacher doesn't seem to know a lot about C++...or at least about the importance of keeping up with modern and good coding practices.

for instance you return 0 in a main function that doesn't have a type...that's just one of things I've noticed style-wise.

If you use the code tags then it will be more readable and easier for me to spot bugs. Oh and any compiler errors?

Compiles w/o errors in Dev C++ but you need to download apstring.h which I got in class. I will repost code.
Was This Post Helpful? 0

#12 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: English to Pig Latin Program

Posted 06 March 2010 - 12:13 AM

View Postbryant.yu809, on 05 March 2010 - 09:45 PM, said:

sorry all, here's my code 1st version:
///////////////////////////////////////////////////////////////////////
//File: piglatin.cc
//Written by: Bryant Yu
//Date: 3/1/10
//Course: C++, Period 5
///////////////////////////////////////////////////////////////////////
#include <iostream>
#include "apstring.h"

apstring phrase;

void prompt ();
void translation ();

main ()
{
	prompt ();
	translation ();
	return 0;
}

void prompt ()
{
	cout << "I can translate English sentences and phrases into ";
	cout << "Pig Latin." << endl << "Please type an English sentence";
	cout << " or phrase and then press<Enter>." << endl;
	getline (cin, phrase);
}

void translation ()
{
	int tempi=0; 
	apstring phraseword;
	int len=phrase.length();
	for (int i=0; i<phrase.length(); i++)
	{
		if (phrase[i]==' ' || phrase[i]=='!' || phrase[i]==';' ||
		phrase[i]==':' || phrase[i]==',' || phrase[i]=='?' || phrase[i]=='('
		|| phrase[i]==')' || phrase[i]=='"' || phrase[i]=='-' || phrase[i]=='.' || 
		i==phrase.length())
		{
			if (i==phrase.length()-1)
				phraseword=phrase.substr(tempi, phrase.length());
			else
				phraseword = phrase.substr(tempi,i-tempi);
			tempi=i+1;
			bool firstwb=false;
			bool novowel=false;
			for (int j=0; j<10; j++)
			{
				for (int k=0; k<phraseword.length(); k++)
				{
					if (phraseword[k]!=vowels[j])
					{
						novowel=true;
					}
					if (k==phraseword.length()-1)
					{
						cout<<"Finished checking for no vowels" << endl;
						break;
					}
				}
				if (phraseword[0]==vowels[j])
				{
					cout << "First letter is a vowel" << endl;
					firstwb=true;
					phraseword+="yay";
					break;
				}
				else //if (phraseword.find(vowels[j])!=-1)
				{
					cout << "Vowels not at beginning, but in the word. " << endl;
					int vowelpos=phraseword.find(vowels[j]);
					if(vowelpos=-1)
					{
						apstring startw=phraseword.substr(0, vowelpos);
						apstring endw=phraseword.substr(vowelpos, phraseword.length());
						
						cout << startw << endl << endl;
						cout << endw << endl << endl;
					}
				}
			}
			if (novowel==true)
			{
				phraseword+="ay";
			}
			cout << phraseword << endl;
		}
	}
}






CODE V2!

///////////////////////////////////////////////////////////////////////
//File: piglatin.cc
//Written by: Bryant Yu
//Date: 3/1/10
//Course: C++, Period 5
///////////////////////////////////////////////////////////////////////
#include <iostream>
#include "apstring.h"

apstring phrase;

void prompt ();
void translation ();

main ()
{
     bool runBool=true;
     int count=0;
    do
    {
        prompt ();
	    translation ();
    } while (runBool==true);
	cin>>phrase;
	return 0;
}

void prompt ()
{
	cout << "I can translate English sentences and phrases into ";
	cout << "Pig Latin." << endl << "Please type an English sentence";
	cout << " or phrase and then press<Enter>." << endl;
	getline (cin, phrase);
}

void translation ()
{
	int tempi=0; 
	apstring phraseword;
	const apstring vowels = ("AaEeIiOoUu");
	int len=phrase.length();
	for (int i=0; i<phrase.length(); i++)
	{
		bool vowelBool=false;
		if (phrase[i]==' ' || phrase[i]=='!' || phrase[i]==';' ||
		phrase[i]==':' || phrase[i]==',' || phrase[i]=='?' || phrase[i]=='('
		|| phrase[i]==')' || phrase[i]=='"' || phrase[i]=='-' || phrase[i]=='.' || 
		i==phrase.length()-1)
		{
			if (i==phrase.length()-1)
				phraseword=phrase.substr(tempi, phrase.length());
			else
				phraseword = phrase.substr(tempi,i-tempi);
			tempi=i+1;
			len=phraseword.length();
			for (int w=0; w<len; w++)
			{
                for (int g=0; g<10; g++)
                {
                 switch (phraseword[w])
                 {
                         case 'a': case 'A': case 'E': case 'e': case 'I':
                         case 'i': case 'O': case 'o': case 'U': case 'u':
                         case vowels[g]:
                         {
                            if (w==0)
                            {
                               vowelBool=true;
                            }
                            else
                            {
                                cout << "There is a vowel in here somewhere...." << endl;
                            }
                            break;
                         }
                         default:
                         { 
                                vowelBool=false;
                                 break;
                         }
                }
                if (vowelBool==true)
                {
                    break;
                }
                }
                if(vowelBool==true)
                    break;
            }
            if (vowelBool==true)
            {
            phraseword+="yay";
            }
            else
            {
                phraseword+="ay";
            }
			cout << phraseword << endl;
		}
	}
}



The professor(s) that is teaching this crap needs to be ran out on his ass just as fast as humanly possible. It's professors like this that are doing nothing but cheating these student by teaching them things they themselves programmed with back in the late 70's early 80's.

These kind of professors clearly could care less about the success of his/her students or if they even learned anything that can be used in this century, or even decade. By the time they reach this point they're merely worried about continuing to receive their paycheck.
Was This Post Helpful? 2
  • +
  • -

#13 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: English to Pig Latin Program

Posted 06 March 2010 - 12:15 AM

Visual C++ 2008 Express.

Replacing "apstring.h" with <string> and apstring with string yields the following lengthy error log:
1>------ Build started: Project: test, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
//cut
1>test - 49 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Adding using namespace std; reduces to:
1>------ Build started: Project: test, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\users\elias\documents\visual studio 2008\projects\project1\test\test\main.cpp(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\elias\documents\visual studio 2008\projects\project1\test\test\main.cpp(24) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(1144): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(1146): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(1148): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(1150): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files\microsoft visual studio 9.0\vc\include\istream(155)
//etc
1>        while trying to match the argument list '(std::ostream, std::string)'
1>Build log was saved at "file://c:\Users\Elias\Documents\Visual Studio 2008\Projects\Project1\test\test\Debug\BuildLog.htm"
1>test - 5 error(s), 3 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Making main return int reduces it to:
1>------ Build started: Project: test, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\users\elias\documents\visual studio 2008\projects\project1\test\test\main.cpp(18) : warning C4189: 'count' : local variable is initialized but not referenced
1>c:\users\elias\documents\visual studio 2008\projects\project1\test\test\main.cpp(42) : warning C4018: '<' : signed/unsigned mismatch
1>c:\users\elias\documents\visual studio 2008\projects\project1\test\test\main.cpp(48) : warning C4389: '==' : signed/unsigned mismatch
1>c:\users\elias\documents\visual studio 2008\projects\project1\test\test\main.cpp(50) : warning C4389: '==' : signed/unsigned mismatch
1>c:\users\elias\documents\visual studio 2008\projects\project1\test\test\main.cpp(64) : error C2051: case expression not constant
1>Build log was saved at "file://c:\Users\Elias\Documents\Visual Studio 2008\Projects\Project1\test\test\Debug\BuildLog.htm"
1>test - 1 error(s), 4 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Also, I would recommend against using Dev-C++ -- it is a very old IDE using an outdated version of gcc/g++.

This post has been edited by PlasticineGuy: 06 March 2010 - 12:28 AM

Was This Post Helpful? 0
  • +
  • -

#14 Guest_bryant.yu809*


Reputation:

Re: English to Pig Latin Program

Posted 06 March 2010 - 12:16 AM

-sigh- I know, this year our c++ teacher retired at the beginning of the year, we've been having multiple subs, and just got our permanent teacher who hasn't taught C++ for 9 years....
Was This Post Helpful? 0

#15 Guest_bryant.yu809*


Reputation:

Re: English to Pig Latin Program

Posted 06 March 2010 - 12:19 AM

View Postbryant.yu809, on 05 March 2010 - 11:16 PM, said:

-sigh- I know, this year our c++ teacher retired at the beginning of the year, we've been having multiple subs, and just got our permanent teacher who hasn't taught C++ for 9 years....

here is the apstring.h file I am using.
#ifndef _APSTRING_H
#define _APSTRING_H

#include <iostream>
using namespace std;
// uncomment line below if bool not built-in type
// #include "bool.h"

// *******************************************************************
//  APCS string class
//
//  string class consistent with a subset of the standard C++ string class
//  as defined in the draft ANSI standard
// *******************************************************************

extern const int npos;  // used to indicate not a position in the string

class apstring
{
  public:

  // constructors/destructor

    apstring( );                         // construct empty string ""
    apstring( const char * s );          // construct from string literal
    apstring( const apstring & str );      // copy constructor
     ~apstring( );                        // destructor

  // assignment

    const apstring & operator = ( const apstring & str ); // assign str
    const apstring & operator = ( const char * s );       // assign s
    const apstring & operator = ( char ch );              // assign ch

  // accessors

    int    length( )                  const;    // number of chars
    int	  capacity( )	const;
    int    find( const apstring & str ) const;  // index of first occurrence of str
    int    find( char ch )            const;    // index of first occurrence of ch
    apstring substr( int pos, int len ) const;    // substring of len chars 
                                                // starting at pos
    char * c_str( )             const;    // explicit conversion to char *

  // indexing

    char   operator[ ]( int k )       const;    // range-checked indexing
    char & operator[ ]( int k );                // range-checked indexing

  // modifiers

    const apstring & operator += ( const apstring & str );// append str
    const apstring & operator += ( char ch );            // append char
 
        
  private:
      int myLength;                     // length of string (# of characters)
      int myCapacity;                   // capacity of string
      char * myCstring;                 // storage for characters         
};

// The following free (non-member) functions operate on strings
//
// I/O functions

ostream & operator << ( ostream & os, const apstring & str );
istream & operator >> ( istream & is, apstring & str ); 
istream & getline( istream & is, apstring & str );  
          
// comparison operators:

bool operator == ( const apstring & lhs, const apstring & rhs );  
bool operator != ( const apstring & lhs, const apstring & rhs );  
bool operator <  ( const apstring & lhs, const apstring & rhs );  
bool operator <= ( const apstring & lhs, const apstring & rhs );  
bool operator >  ( const apstring & lhs, const apstring & rhs );  
bool operator >= ( const apstring & lhs, const apstring & rhs );  

// concatenation operator +

apstring operator + ( const apstring & lhs, const apstring & rhs );
apstring operator + ( char ch, const apstring & str );
apstring operator + ( const apstring & str, char ch );

// *******************************************************************
// Specifications for string functions
//
// Any violation of a function's precondition will result in an error
// message followed by a call to abort.
//
// constructors / destructor
//
// string( )
//    postcondition: string is empty
//
// string( const char * s )
//    description:   constructs a string object from a literal string
//                   such as "abcd"
//    precondition:  s is '\0'-terminated string as used in C
//    postcondition: copy of s has been constructed
//
// string( const string & str )
//    description:   copy constructor
//    postcondition: copy of str has been constructed
//
// ~string( );
//    description:   destructor
//    postcondition: string is destroyed
//
// assignment
//
// string & operator = ( const string & rhs )
//    postcondition: normal assignment via copying has been performed
//
// string & operator = ( const char * s )
//    description:   assignment from literal string such as "abcd"
//    precondition:  s is '\0'-terminated string as used in C
//    postcondition: assignment via copying of s has been performed
//
// string & operator = ( char ch )
//    description:   assignment from character as though single char string
//    postcondition: assignment of one-character string has been performed
//
// accessors
//
// int length( ) const;
//    postcondition: returns # of chars in string
//
// int find( const string & str)  const;
//    description:   find the first occurrence of the string str within this
//                   string and return the index of the first character.  If
//                   str does not occur in this string, then return npos.
//    precondition:  this string represents c0, c1, ..., c(n-1)
//                   str represents s0, s1, ...,s(m-1)
//    postcondition: if s0 == ck0, s1 == ck1, ..., s(m-1) == ck(m-1) and
//                   there is no j < k0 such that s0 = cj, ...., sm == c(j+m-1),
//                   then returns k0;
//                   otherwise returns npos
//
// int find( char ch ) const;
//    description:   finds the first occurrence of the character ch within this
//                   string and returns the index.  If ch does not occur in this
//                   string, then returns npos.
//    precondition:  this string represents c0, c1, ..., c(n-1)
//    postcondition: if ch == ck, and there is no j < k such that ch == cj
//                   then returns k;
//                   otherwise returns npos
//
// string substr( int pos, int len ) const;
//    description:   extract and return the substring of length len starting
//                   at index pos
//    precondition:  this string represents c0, c1, ..., c(n-1)
//                         0 <= pos <= pos + len - 1 < n.
//    postcondition: returns the string that represents
//                   c(pos), c(pos+1), ..., c(pos+len-1)
//
// const char * c_str( ) const;
//    description:   convert string into a '\0'-terminated string as
//                   used in C for use with functions
//                   that have '\0'-terminated string parameters.
//    postcondition: returns the equivalent '\0'-terminated string
//
// indexing
//
// char operator [ ]( int k ) const;
//    precondition:  0 <= k < length()
//    postcondition: returns copy of the kth character
//
// char & operator [ ]( int k ) 
//    precondition:  0 <= k < length()
//    postcondition: returns reference to the kth character
//
// modifiers
//
// const string & operator += ( const string & str )
//    postcondition: concatenates a copy of str onto this string
//
// const string & operator += ( char ch )
//    postcondition: concatenates a copy of ch onto this string
//
//
// non-member functions
//
// ostream & operator << ( ostream & os, const string & str) 
//    postcondition: str is written to output stream os
//
// istream & operator >> ( istream & is, string & str )
//    precondition:  input stream is open for reading
//    postcondition: the next string from input stream is has been read
//                   and stored in str
//
// istream & getline( istream & is, string & str )
//    description:   reads a line from input stream is into the string str
//    precondition:  input stream is open for reading
//    postcondition: chars from input stream is up to '\n' have been read
//                   and stored in str; the '\n' has been read but not stored
//
// string operator + ( const string & lhs, const string & rhs )
//    postcondition: returns concatenation of lhs with rhs
//
// string operator + ( char ch, const string & str )
//    postcondition: returns concatenation of ch with str
//
// string operator + ( const string & str, char ch )
//    postcondition: returns concatenation of str with ch
//
//***************************************************************

#include "apstring.cpp"		// kludge, added on 4/7/97

#endif

Was This Post Helpful? 0

  • (3 Pages)
  • +
  • 1
  • 2
  • 3