Functions for operating on strings are provided with the standard C library; however, we would like to be able to treat strings in our programs as if they were a built-in type. Thus, in this exercise you are to develop a software package in C that implements the STRING Abstract Data Type (ADT). This ADT should at the minimum support the following operations:   Retrieve (i, s). Returns element I of string s. Print(s). Prints the contents of string s. Concatenate (s1, s2). Concatenates strings s1and s2and returns the resulting string. Copy (s1, s2). Copies the contents of string s1to string s2. Compare (s1, s2). Compares string s1 to string s2, returning a result indicating whether s1 is lexicographically greater than s2. Length (s). Returns the number of characters in the string s. Capacity (s). Returns the maximum numbers of characters that can be stored in the string s.   Proper data encapsulation requires that a structure be created that holds the string representation, as well as information about the string. The following declaration and structure should be placed in a header file called String.h along with the function prototypes for the operations listed above:   typedef struct { char *element; int length; int capacity; } string_type; /* function prototypes */ string_type Create(char *ary, int capacity); void Destroy(string_type str); void Print(string_type str); string_type Concatenate(string_type str1, string_type str2); ......     A code fragment that demonstrates how the string package will be used in given below:   #include “String.h” char a[] = “hello”; char b[] = “hi!”;main() { string_type str1, str2; str1 = Create(a, 15); str2 = Create(b, 15); Print(Concatenate(str1, str2)); ...... } Use your string package to perform the following task:   Sort the following strings: defunct, abeyance, irrelevant, acquiesce, western, zealous, electric, trihedral, unimodal, vanquish, ambient, abbreviate, edifice, genre, ferrous, breve, brocade.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Functions for operating on strings are provided with the standard C library; however, we would like to be able to treat strings in our programs as if they were a built-in type. Thus, in this exercise you are to develop a software package in C that implements the STRING Abstract Data Type (ADT). This ADT should at the minimum support the following operations:

 

  1. Retrieve (i, s). Returns element I of string s.
  2. Print(s). Prints the contents of string s.
  3. Concatenate (s1, s2). Concatenates strings s1and s2and returns the resulting string.
  4. Copy (s1, s2). Copies the contents of string s1to string s2.
  5. Compare (s1, s2). Compares string s1 to string s2, returning a result indicating whether s1 is lexicographically greater than s2.
  6. Length (s). Returns the number of characters in the string s.
  7. Capacity (s). Returns the maximum numbers of characters that can be stored in the string s.

 

Proper data encapsulation requires that a structure be created that holds the string representation, as well as information about the string. The following declaration and structure should be placed in a header file called String.h along with the function prototypes for the operations listed above:

 

typedef struct {

char *element;

int length;

int capacity;

} string_type;

/* function prototypes */

string_type Create(char *ary, int capacity);

void Destroy(string_type str);

void Print(string_type str);

string_type Concatenate(string_type str1, string_type str2);

......

 

 

A code fragment that demonstrates how the string package will be used in given below:

 

#include “String.h”

char a[] = “hello”;

char b[] = “hi!”;main()

{

string_type str1, str2;

str1 = Create(a, 15);

str2 = Create(b, 15);

Print(Concatenate(str1, str2));

...... }

Use your string package to perform the following task:

 

Sort the following strings: defunct, abeyance, irrelevant, acquiesce, western, zealous, electric, trihedral, unimodal, vanquish, ambient, abbreviate, edifice, genre, ferrous, breve, brocade. 

Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
ADT and Class
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education