//*********************************************************************************
// ICS 211 Data Structures 2001 Spring Semester
// Project : HW 3
//
// File : hw3.cpp
// Date : 16/04/2001
// Author: Seniz Demir
//
// Description: Operator overloading processes on String objects
//
// -------------------------------------------------------------------------------
//  Copyright (C) 2001 Yeditepe University
//                         Information and Computer Science Department
//                         All rights reserved
// -------------------------------------------------------------------------------

#include<iostream.h>
#include<math.h>
#include<assert.h>
#include<string.h>

//-------------------------------------------------------------------------------
// String
// Implementation Notes: Implementation of String class
//-------------------------------------------------------------------------------


class String {
        public:
        String(const char *s) ;
        ~String();
        const String &operator=(const String &);// comparison
        const String &operator+=(const String &);//concatenation
        char  operator[](int number ) const  ;//length
        void operator*(const String &);//reverse
        void setString(const char *string2);
        void showString();
        int getlength();
        String &operator^(int number);
        private:
              int length;//length of the string
        char *sPtr;//string
    };

//!!!!!!!!!!!!!!
//****************************************************************
// You will implement the following function:

void String::operator*(const String &s)//reverse
{
}
void String::showString()//prints the string
{
  cout<<sPtr;
}
char String::operator[](int number) const //gets the character at the specified index
{
return(sPtr[number]);
}
// Overloaded = operator; avoids self assignment
const String &String::operator=(const String &right)
{
        strcpy(sPtr,right.sPtr);
        return *this; // enables cascaded assignments
}

// Concatenate right operand to this object and
// store in this object

const String &String::operator+=(const String &right)
{
        strcat(sPtr,right.sPtr);
        return *this; // enables cascaded calls
}
int String::getlength() //returns string length
{
        return length;
}
String::String(const char *s)//constructor
{
   sPtr=new char[strlen(s)];
   strcpy(sPtr,s);
   length=strlen(sPtr);
}
String::~String()//destructor
{
delete [] sPtr;
}
void String::setString(const char *string2) //set string value
{
        sPtr=new char[length+1];
        assert(sPtr!=0);
        strcpy(sPtr,string2);
}

//!!!!!!!!!!!!!!
//****************************************************************
// You will implement the following function:
 String &String::operator^(int number) //concatenate the string to itself number of times
{
}

int main()

{
/*create two arrays that include totally six
 * objects of String class
 *
  create a menu and do the following operations
  1)concatenate two strings
  2)assign a string to another
  3)assign the reverse of a string to another
  4)get the power of a string
  5)quit

 User choose the strings that will be used in the operations defined above by
 determining the indices of them.

Assume s1 and s2 are two objects in the arrays

ex: operation assign
   user choooses index1 and index2
result:array1[index1]=array2[index2]
usage:s1=s2;
print s1;

ex: operation concatenation
    user chooses index1 and index2
result:array1[index1] concat array2[index2]
    show result
usage:s1+=s2;
print s1;

ex: operation power
     user chooses index1 and determines the power parameter as n
result:(array1[index1] concat array1[index1]) n times
usage: s1=s1^3;
print s1;

ex: operation reverse
    user chooses index1 and index2
result: array1[index1]=reverse(array2[index2])
usage: s1*(s2);
print s1;

user can do any of these operations until he/she wants to quit
*/
    return 0;
};


