Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ only - should be a basic program only using arrays, strings, if statements, for loops NOT pointers or any other more advanced tools. Other

C++ only - should be a basic program only using arrays, strings, if statements, for loops NOT pointers or any other more advanced tools. Other online programs did not follow this important information.

Your program must not use any function templates from the algorithms portion of the Standard C++ library

Your assignment is to produce a library that provides functions for many common manipulations of arrays of strings. For example, one function will find where a string occurs in an unordered array of strings. Another will change the order of strings in an array. For each function you must write, this specification will tell you its interface (what parameters it takes, what it returns, and what it must do). It's up to you to decide on the implementation (how it will do it). The source file you turn in will contain all the functions and a main routine. You can have the main routine do whatever you want, because we will rename it to something harmless, never call it, and append our own main routine to your file. Our main routine will thoroughly test your functions. You'll probably want your main routine to do the same. If you wish, you may write functions in addition to those required here. We will not directly call any such additional functions. If you wish, your implementation of a function required here may call other functions required here.

The program you turn in must build successfully, and during execution, no function (other than main) may read anything from cin or write anything to cout. If you want to print things out for debugging purposes, write to cerr instead of cout. When we test your program, we will cause everything written to cerr to be discarded instead we will never see that output, so you may leave those debugging output statements in your program if you wish.

All of the functions you must write take at least two parameters: an array of strings, and the number of items the function will consider in the array, starting from the beginning. For example, in

 

string folks[8] = { "samwell", "jon", "margaery", "daenerys", "tyrion", "sansa", "howard123", "jon" }; bool b = hasDuplicates( folks, 5 ); // should return true false and not inspect the last three elements... even though the array has 8 elements, only the first 5 had values we were interested in for this call to the function; the function must not examine any of the others.

The one error your function implementations don't have to handle, because they can't, is when the caller of the function lies and says the array is bigger than it really is. For example, in this situation, the function find can't possibly know that the caller is lying about the number of interesting items in the array:

 string people[5] = { "samwell", "jon", "margaery", "daenerys", "tyrion" }; bool b = hasDuplicates(people, 25 ); // Bad driver code call // your implementation doesn't have to check for this, because it can't 

To make your life easier, whenever this specification talks about strings being equal or about one string being less than or greater than another, the case of letters matters. This means that you can simply use comparison operators like == or < to compare strings. Because of the character collating sequence, all upper case letters come before all lower case letters, so don't be surprised by that result. The FAQ has a note about string comparisons.

Other functions are removed...THIS divide function .. I'm having issues with ... please complete.

int divide( string array[ ], int n, string divider ); Rearrange the elements of the array so that all the elements whose value is < divider come before all the other elements, and all the elements whose value is > divider come after all the other elements. (Yes, there might be numerous correct rearrangements that are valid.) Return the position of the first element that, after the rearrangement, is not < divider, or 0 if there are none.

Your implementations must not use any global variables whose values may be changed during execution.

The correctness of your program must not depend on undefined program behavior. Your program could not, for example, assume anything about t's value in the following, or even whether or not the program crashes:

 int main() { string s[3] = { "samwell", "jon", "tyrion" }; string t = s[3]; // position 3 is out of range 

A nice way to test your functions is to use the assert facility from the standard library. As an example, here's a very incomplete set of tests for this Program:

 #include  #include  #include  using namespace std; int main() { 

string a[6] = { "alpha", "beta", "gamma", "gamma", "beta", "delta" };

assert(hasDuplicates(a, 3 ) == false); assert(hasDuplicates(a, 6 ) == true);

cout << "All tests succeeded" << endl; return( 0 );

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

Step: 3

blur-text-image

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, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions