Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Write a c++ function which is called GetCopy ans IsEqual(testing cannot be modified)

charPtr getCopy(const charPtr s)
{
    /*
    returns a new cstring that is a copy of the cstring s.
    That is a new cstring with as big memory as the size of 
    the cstring s is created and then all the characters of 
    s including the null char are copied to it.
    */
    int lens = cstrlen(s);
    char *Array = new char[lens+1];
    for(int i = 0; i < lens;i++)
    {
        Array[i] = s[i];
    }
    Array[lens] = '\0';
    return Array;
}

bool isEqual(charPtr s1, charPtr s2)
{
    /*
    returns true if the cstring s1 is equal to the cstring s2
        Definition: Two c-strings s1 and s2 are equal if they have the same length
        and characters of s1 and s2 at corresponding indexes are the same.
    */

}

//Test getCopy function
    cout << endl << "Testing getCopy function";
    cout << endl << "------------------------" << endl;
    char* s2 = getCopy("irregular");
    cout << "A copy of \"irregular\" is s2=\"" << s2 << "\"" << endl;
    char* s3 = getCopy(s2);
    cout << "A copy of s2=\"" << s2 << "\" is s3=\"" << s3 << "\"" << endl;
    delete[] s2;
    s2 = new char('\0');
    cout << "s2 is modified to s2=\"" << s2 << "\" but s3 is still s3=\"" << s3 << "\"" << endl;
    delete[] s3;
    s3 = getCopy(s2);
    cout << "A copy of s2=\"" << s2 << "\" is s3=\"" << s3 << "\"" << endl;

//Test isEqual function
    cout << endl << "Testing isEqual function";
    cout << endl << "------------------------" << endl;
    if (isEqual(s2, s3))
        cout << "s2=\"" << s2 << "\" and s3=\"" << s3 << "\" are equal" << endl;
    else
        cout << "s2=\"" << s2 << "\" and s3=\"" << s3 << "\" are not equal" << endl;
    delete[] s3;
    s3 = getCopy(s2);
    if (isEqual(s2, s3))
        cout << "s2=\"" << s2 << "\" and s3=\"" << s3 << "\" are equal" << endl;
    else
        cout << "s2=\"" << s2 << "\" and s3=\"" << s3 << "\" are not equal" << endl;

 

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education