Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ please, comment as well, Thank you! In lab exercises - Implement the Text

ID: 3875154 • Letter: I

Question

In C++ please, comment as well, Thank you!

In lab exercises

- Implement the Text ADT (use the declaration in the Text.h file) (40 points)

EXAMPLE:

#ifndef TEXT_H

#define TEXT_H

#include <stdexcept>

#include <iostream>

using namespace std;

class Text

{

public:

// Constructors and operator=

Text ( const char *charSeq = "" ); // Initialize using char*

Text ( const Text &other ); // Copy constructor

void operator = ( const Text &other ); // Assignment

// Destructor

~Text ();

// Text operations

int getLength () const; // # characters

char operator [] ( int n ) const; // Subscript

void clear (); // Clear string

// Output the string structure -- used in testing/debugging

void showStructure () const;

//--------------------------------------------------------------------

// In-lab operations

// toUpper/toLower operations (Programming Exercise 2)

Text toUpper( ) const; // Create upper-case copy

Text toLower( ) const; // Create lower-case copy

// Relational operations (Programming Exercise 3)

bool operator == ( const Text& other ) const;

bool operator < ( const Text& other ) const;

bool operator > ( const Text& other ) const;

private:

// Data members

int bufferSize; // Size of the string buffer

char *buffer; // Text buffer containing a null-terminated sequence of characters

// Friends

// Text input/output operations (In-lab Exercise 1)

friend istream & operator >> ( istream& input, Text& inputText );

friend ostream & operator << ( ostream& output, const Text& outputText );

};

#endif

- Text(), operator=() and ~Text(), getLength(), clear(), operator[]

Homework exercise

- Programming Exercise 2: Implement the functions toUpper() and toLower() and test them by activating LAB1_TEST1 (30 points)

- Programming Exercise 3: Implement the operators ==, <, > and test them by activating LAB1_TEST2 (30 points)

Explanation / Answer

Exercise 2: Implement the functions toUpper() and toLower()

Lower to Upper Case:-

#include<stdio.h>

#include<conio.h>

const int x = 32;

//Converts a string to uppercase

char *toUpperCase(char *a)

{

    for (int i=0; a[i]!=''; i++)

        a[i] = a[i] & ~x;

return a;

}

// Driver Code

int main()

{

    char str[] = "SanjaYKannA";

printf("%s", toUpperCase(str));

return 0;

}

Output:

SANJAYKANNA

Upper to Lower Case:-

#include<stdio.h>

#inculde<conio.h>

const int x = 32;

// Converts a string to lowercase

char * toLowerCase(char *a)

{

    for (int i=0; a[i]!=''; i++)

        a[i] = a[i] | x;

return a;

}

// Driver Code

int main()

{

    char str[] = "SanjaYKannA";

    printf("%s", toLowerCase(str));

    return 0;

}

Output:

sanjaykanna

Exercise 3: Implement the operators ==, <, >

}

Output:-