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_forwardC++ C++arrow_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_forward
- write a simple C code as I am beginerarrow_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_forwardC++You will create a header file with implementation that performs the task. Together with the header and implementation, you create a test program whose main function demonstrates that your functions work as they should. A file contains integers. You must write a function that show whether the integers in the file are sorted or not. The test program should give output if a file with digits is sorted or not. Input : file contains numeric values Output :The File is sorted Note :This algorithm down you can use it: a ← read Value from the file ; while not End Of File (eof) { b ← read Value from the file ; if a> b { return false; } a ← b; } return true;arrow_forward
- Write a function that takes (i) a FILE pointer (e.g. FILE *fp) type variable, (ii) an array of student struct (that you defined in the previous question), and (iii) the number of valid elements in that array as parameters, and write those elements in a file named "students.dat". This function should return 1 if it can successfully open this file; otherwise, it should return 0.Please use C languagearrow_forwardUse C++arrow_forwardStatement is true or falsearrow_forward
- C++You will create a header file with implementation that performs the task. Together with the header and implementation, you create a test program whose main function demonstrates that your functions work as they should. A file contains integers. You must write a function that show whether the integers in the file are sorted or not. The program should give output if a file with digits is sorted or not. Input : file contains numeric values Output :The File is sorted In esay way to understand my question : #include (Myfunction.h) cout << " Enter Your file name" << Endl; Output : The file is sorted or The file is not sorted.arrow_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_forwardWRITE 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_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