Concept explainers
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.
Step by stepSolved in 3 steps with 3 images
- In C Programming: Write a function printCourseRow() which receives a course pointer and prints all its fields as a single row. Use proper formatting so that when we print 2 or more courses as rows, the same members align below each other. Test the function, but don’t include the testing code in your homework.Upload a screenshot of a sample output.arrow_forwardDevelop an algorithm and write a C++ program that counts the letter occurrence in the string; make sure you use call by reference to the array of a class with letter and count as private member attributes when return from parse function. For the class member methods, provide the public accessor and modifier as well as print functions for the private member attributes. Write a test program that reads a C-string and displays the number of letters [a-z] and number of numbers [0-9] in the string. In addition to that, you need to output the histogram of the letter and count array. Here is a sample run of the program: <Output> Enter a string: 2023 is coming The number of letters in 2023 is coming is 8 The number of numbers in 2023 is coming is 4 ---- Histogram ---- Char Count 0 1 2 2 3 1 c 1 g 1 i 2 m 1 n 1 /* not a completed output */ <End Output>arrow_forwardIf s and t are strings, then index function (s, t) in C++ or a similar language would be the int that is the value of the function at the ordered pair (s, t). Translate this function into a standard mathematical function specification.arrow_forward
- Assignment-3 With the help of a C program show how to typecast a void * to an int * . Attach the code and output and upload the file on classroom.arrow_forwardC++ Attached is the questionarrow_forwardIn C++, what is the difference between emplace_back and push_back, when using vectors? I looked at other sources, and still find it confusing as to what s the difference between the two of these.arrow_forward
- This is in c++. Create a class of function objects called StartsWith that satisfies the following specification: when initialized with character c, an object of this class behaves as a unary predicate that determines if its string argument starts with c. For example, StartsWith(’a’) is a function object that can be used as a unary predicate to determine if a string starts with an a. So, StartsWith(’a’)("alice") would return true but StartsWith(’a’)("bob") would return false. The function objects should return false when called on an empty string. Test your function objects by using one of them together with the STL algorithm count_if to count the number of strings that start with some letter in some vector of strings. So basically, I want a class that returns true or false based on if the name that is typed starts with the character that I put down.arrow_forwardPHP Write a wordFilter function Write a function wordFilter($str) that takes a string representing a sentence as a parameter. It should replace all occurrences of certain blacklisted words with asterisks of the same length and return the substituted sentence. The words “shoot” “darn” and “fudge” (case insensitive) are considered blacklisted. However, these words as part of a larger word should be left alone (e.g. overshoot is fine as it is). Use one or more regular expressions with replacements in your solutions (e.g. preg_replace).arrow_forwardWrite a lisp program (please provide photos that it works)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education