Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Strings are one of the most important fundamental data structures used in computers. A string is an array of characters stored in memory, in which

Strings are one of the most important fundamental data structures used in computers. A string is an array of characters stored in memory, in which the characters are encoded. The way strings are handled by programming languages vary, as there is no standard. For example, in C, there is no official data type for strings (in C++, however, there exists a templated data structure for declaring strings). To declare strings in C, an array of characters of fixed length size must be declared. C has library functions for performing operations on strings, such as strcpy (copy a string onto another) and strcat (concatenate one string onto another. Instructions For this exercise, lets assume that C++ does not have the string data type. In this assignment, you are tasked to create a simple String data structure. This structures data will use a pointer to a char memory space to store the string, a length integer to store the length of the string, and a capacity integer to store the length of the array. The data structure will also contain 6 methods: copy, concatenate, compare, grow, min, and difference. You are required to implement 3 of the 6 methods, as grow, min, and difference will be given to you in the appendix of this assignment file. class Str Data Members Name Data Type Access Type Description value char pointer Private Points to an array of characters that holds the string value length integer Private Integer that stores the length of the string pointed to by value. It is the value of the number of characters in the current string. capacity integer Private Integer that stores the number of elements in the array pointed to by value. It is the maximum length a string can currently be in the structure. class Str - Methods Name Return Type Arguments Access Type Description grow N/A N/A Private Doubles the length of the strings array. Used when the resulting string of an operation yields a length greater than the capacity. Used in copy and concatenate. min Integer a: integer b: integer Private Compares the arguments a and b, and returns the minimum of the two values. Should be used in the compare operation. difference Integer a: integer b: integer Private Returns the absolute value of the difference between a and b. Used in the compare operation. getCharArrSize Integer v: char pointer Private Determines the size of a character array pointed to by v and returns the size as an integer. copy none s: Str Object Public Overwrites the data of the string array with the data contained in s. concatenate none s: Str Object Public Appends the data inside s onto the data stored in the string. compare Boolean s: Str Object Public Compares each element of the data inside s each element of the string array. Returns true if all characters match and the length of the strings are equal.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

Define and explain the goals of employee orientation/onboarding

Answered: 1 week ago

Question

Question What is the advantage of a voluntary DBO plan?

Answered: 1 week ago

Question

Question How is life insurance used in a DBO plan?

Answered: 1 week ago