Write a c++ function which is called GetCopy ans IsEqual(testing cannot be modified)
charPtr getCopy(const charPtr s)
{
/*
returns a new cstring that is a copy of the cstring s.
That is a new cstring with as big memory as the size of
the cstring s is created and then all the characters of
s including the null char are copied to it.
*/
int lens = cstrlen(s);
char *Array = new char[lens+1];
for(int i = 0; i < lens;i++)
{
Array[i] = s[i];
}
Array[lens] = '\0';
return Array;
}
bool isEqual(charPtr s1, charPtr s2)
{
/*
returns true if the cstring s1 is equal to the cstring s2
Definition: Two c-strings s1 and s2 are equal if they have the same length
and characters of s1 and s2 at corresponding indexes are the same.
*/
}
//Test getCopy function
cout << endl << "Testing getCopy function";
cout << endl << "------------------------" << endl;
char* s2 = getCopy("irregular");
cout << "A copy of \"irregular\" is s2=\"" << s2 << "\"" << endl;
char* s3 = getCopy(s2);
cout << "A copy of s2=\"" << s2 << "\" is s3=\"" << s3 << "\"" << endl;
delete[] s2;
s2 = new char('\0');
cout << "s2 is modified to s2=\"" << s2 << "\" but s3 is still s3=\"" << s3 << "\"" << endl;
delete[] s3;
s3 = getCopy(s2);
cout << "A copy of s2=\"" << s2 << "\" is s3=\"" << s3 << "\"" << endl;
//Test isEqual function
cout << endl << "Testing isEqual function";
cout << endl << "------------------------" << endl;
if (isEqual(s2, s3))
cout << "s2=\"" << s2 << "\" and s3=\"" << s3 << "\" are equal" << endl;
else
cout << "s2=\"" << s2 << "\" and s3=\"" << s3 << "\" are not equal" << endl;
delete[] s3;
s3 = getCopy(s2);
if (isEqual(s2, s3))
cout << "s2=\"" << s2 << "\" and s3=\"" << s3 << "\" are equal" << endl;
else
cout << "s2=\"" << s2 << "\" and s3=\"" << s3 << "\" are not equal" << endl;
Step by stepSolved in 4 steps with 2 images
- Write in C++ Sam is making a list of his favorite Pokemon. However, he changes his mind a lot. Help Sam write a function insertAfter() that takes five parameters and inserts the name of a Pokemon right after a specific index. Function specifications Name: insertAfter() Parameters (Your function should accept these parameters IN THIS ORDER): input_strings string: The array containing strings num_elements int: The number of elements that are currently stored in the array arr_size int: The number of elements that can be stored in the array index int: The location to insert a new string. Note that the new string should be inserted after this location. string_to_insert string: The new string to be inserted into the array Return Value: bool: true: If the string is successfully inserted into the array false: If the array is full If the index value exceeds the size of the arrayarrow_forwardin c++ Write a function named “contains” that accepts a vector of Variableobject pointers and a search string. It will return the list of Variableobject pointers that contains that search string.Please note that the list can contain pointers to both Variable or VariableString objectsor any of its derived class objects. Build a list of pointers pointing to mixed objects of Variable and VariableString objectsand show your function returns the mix of both.arrow_forwardUsing C++ Assume proper includes have been executed, but not using directive or declaration. Write a definition of an iterator for a vector named vec of int values. Write a for loop that will display the contents vec on the screen, separated by spaces. Use iterators for the loop control.arrow_forward
- Use C++arrow_forwardStatement is true or falsearrow_forwardWrite a c++ function that accepts an array of doubles and the array’s size as its only arguments. The function should use dynamic memory allocation to create a new array that is double the size of the argument array. The function should copy the contents of the argument array to the second half of the new array and initialize the first half of the new 0s. The function should return a pointer to the new array. So, if the original array contained 1 2 3 4, the new array should contain 0 0 0 0 1 2 3 4. So, if the original array contained 1 2 3 4, the new array should contain 0 0 0 0 1 2 3 4.arrow_forward
- WRITE A PROGRAM IN C++ You work for an loan analytics organization have been tasked with writing a program that simulates an analysis of loan applications. Code a modular program that uses parallel arrays to store loan application credit scores (values generated between 300 and 900), score ratings (poor, fair, good, very good, or exceptional based on credit score) and loan status (approved or declined applications based on credit score). The program must do the following: The program must first ask the user for the number of loan applications that will be in the simulation. This must be done by calling the getNumLoanApplications() function (definition below). After the input of the number of accounts, the program must use loops and random numbers to generate the credit score, score rating, and application result for each loan application in parallel arrays. These arrays must not be declared globally (major error). The following arrays must be declared and populated: creditScores[]…arrow_forwardConsider the function void modify(int & x) { x = 10; }Show how to call the modify function so that it sets the integer int i;to 10.arrow_forwardneed help in C++ Problem: You are asked to create a program for storing the catalog of movies at a DVD store using functions, files, and user-defined structures. The program should let the user read the movie through the file, add, remove, and output movies to the file. For this assignment, you must store the information about the movies in the catalog using a single vector. The vector's data type is a user-defined structure that you must define on functions.h following these rules: Identifier for the user-define structure: movie. Member variables of the structure "movie": name (string), year (int), and genre (string). Note: you must use the identifiers presented before when defining the user-defined structure. Your solution will NOT pass the unit test cases if you do not follow the instructions presented above. The main function is provided (you need to modify the code of the main function to call the user-defined functions described below). The following user-defined functions are…arrow_forward
- This assignment will give you practice on basic C programming. You will implement a few Cprogramsarrow_forward8. using c++, Write a function method that determines the mean of all the values in an array of integers. Your mean function should call a separate function that you write that determines the sum. Don’t use built-in sum or mean gadgets, but roll your own.arrow_forward5. use c code to Write a stringSearch function that gets two strings one called needle and the other called haystack. It then searches in the Haystack for the needle. If it finds it, it returns the index of where the needle starts in the haystack. If the needle cannot be found, it should return -1 Prototype: int stringSearch(char needle[], char haystack) Example1: Haystack: “This is just an example” Needle: “just” Result: 8 Example2: Haystack: “This is just an example” Needle: “This” Result: 0 Example3: Haystack: “This is just an example” Needle: “this” Result: -1 Hint: all the answer need to include an output and use c code to answerarrow_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