Solution to
Write a function called deleteRepeats that has a partially filled array of characters as a formal parameter and that deletes all repeated letters from the array. Since a partially filled array requires two arguments, the function will actually have two formal parameters: an array parameter and a formal parameter of type int that gives the number of array positions used. When a letter is deleted, the remaining letters are moved forward to fill in the gap. This will create empty positions at the end of the array so that less of the array is used. Since the formal parameter is a partially filled array, a second formal parameter of type int will tell how many array positions are filled. This second formal parameter will be a call-by-reference parameter and will be changed to show how much of the array is used after the repeated letters are deleted.
For example, consider the following code:
char a[10]; a[0] = 'a'; a[1] = 'b'; a[2] = 'a'; a[3] = 'c'; int size = 4; deleteRepeats(a, size); |
After this code is executed, the value of a[0] is 'a', the value of a[1] is 'b', the value of a[2] is 'c', and the value of size is 3. (The value of a[3] is no longer of any concern, since the partially filled array no longer uses this indexed variable.)
You may assume that the partially filled array contains only lowercase letters. Embed your function in a suitable test program.
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
SURVEY OF OPERATING SYSTEMS
Fluid Mechanics: Fundamentals and Applications
Introduction To Programming Using Visual Basic (11th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- In C++, Define a “Invalidanalyze” function that accepts an array of “Course” objects. It will return the following information to the caller: - The number of courses with empty or blank description - The number of courses with invalid negative units - The number of courses with invalid day number of the week - The total number of units for all invalid courses in the array Show how this method is being called and return proper information.arrow_forwardWrite a program that has a declaration in main() to store the following numbers in an array named temps: 6.5, 7.2,7.5, 8.3, 8.6, 9.4, 9.6, 9.8, and 10.0. There should be a function call to show() that accepts the temps array as aparameter named temps and then displays the numbers in the array.arrow_forwardIn java there must be at least two calls to the function with different arguments and the output must clearly show the task being performed. Develop a function that accepts an array and returns true if the array contains any duplicate values or false if none of the values are repeated. Develop a function that returns true if the elements are in decreasing order and false otherwise. A “peak” is a value in an array that is preceded and followed by a strictly lower value. For example, in the array {2, 12, 9, 8, 5, 7, 3, 9} the values 12 and 7 are peaks. Develop a function that returns the number of peaks in an array of integers. Note that the first element does not have a preceding element and the last element is not followed by anything, so neither the first nor last elements can be peaks. Develop a function that finds the starting index of the longest subsequence of values that is strictly increasing. For example, given the array {12, 3, 7, 5, 9, 8, 1, 4, 6}, the function…arrow_forward
- Write a JAVA program Write a function inside ProblemSolution class whose return type is void, accepts an array and the length of the array as input parameters. The function should call a static method display of MyArray class by passing an array and length value. Input 5 1 5 8 2 0 Where, First line of input represents the size of an array. Second line represents array elements. Output 1 5 8 2 0 Assume that, N is an integer within the range [0 to 10000]. Array elements are integers within the range [-2147483648 to 2147483647].arrow_forwardGive solution in C ++ Language with secreenshoot of source code. Part 01In this task, you need to do the following:• Write a function named displayMessage() that takes user name as input in character array and then shows greetings• Now take the name input in main() and pass the name as an argument to displayMessage() function• Change the displayMessage() method such that it returns the number of characters after displaying the greetings part 02Write a function power that takes two parameters a and b. And it returns the power as ab.arrow_forwardyou are required to store information about a house, take input from user regarding information about rooms, kitchen, bathroom, house price, lawn and terrace. store information of 1 if lawn or terrace are present in a house, 0 will indicate that no lawn is present. display all the houses (object array in functions) display houses with no lawn (simple function) display houses with maximum price. (function)arrow_forward
- Write a function called “CompareTwo” that accepts four parameters: A1 array of type integer, A2 array of type integer, S1 number of elements in A1 array, and S2 number of elements in A2 array. The function must return true if the sum of A1 equals to the sum of A2, otherwise it must return false.arrow_forwardC++ Write a function named “getTotalHourAndPayout” that accepts an array ofPayStub object pointers and its size. It will return the total number of hours andpayout amount for all of the PayStub in the given array. For example, if we have two paystubs of 40 hours and $10 pay rate with 50 hoursand $10 pay rate, it will return 90 hours and $950.Please show you would call and test this function.arrow_forwardC++ Write a function named “checkInvalidHours” that accepts an array of PaySubobjects and its size. It will go through the array and check for invalid hours(negative values). If it is negative, it will reset the hourly payrate to 0. It willreturn how many PayStub objects that it has reset the payrate to 0.Please show you would call and test this function.arrow_forward
- Write a function reportDuplicates() that takes a two di mensional integer array as a parameter and identifies the duplicate valuesin the array. The function then reports these to user. Sample input and corresponding output:How many rows? 5How many columns? 2Let’s populate the array:1 86 97 312 522 4Thank you, there are no duplicate elements!How many rows? 3How many columns? 4Let’s populate the array:3 7 5 76 9 7 38 5 12 6Thank you, 3 appears 2 times, 7 appears 3 times, 5 appears 2 times,and 6 appears 2 times.arrow_forwardOne problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example, you might want to add or delete entries from the array similar to the behavior of a vector . This project asks you to create a class called DynamicStringArray that includes member functions that allow it to emulate the behavior of a vector of strings. The class should have the following A private member variable called dynamicArray that references a dynamic array of type string. A private member variable called size that holds the number of entries in the array. A default constructor that sets the dynamic array to NULL and sets size to 0. A function that returns size . A function named addEntry that takes a string as input. The function should create a new dynamic array one element larger than dynamicArray , copy all elements from dynamicArray into the new array, add the new string onto the end of the new array, increment size, delete the old dynamicArray ,…arrow_forwardWrite a program that creates a 2D array of integers of size nXn initialized with test data.The program should have the following functions:● getTotal. This function should accept a 2D array as an argument and returnthe total of all the values in the array.● getAverage. This function should accept a 2D array as an argument and returnthe average of all the values in the array.● getRowTotal. This function should accept a 2D array as the first argument andan integer as its second argument. The second argument should be the subscriptof a row in the array. The function should return the total of the values in thespecified row.● getColumnTotal. This function should accept a 2D array as the first argumentand an integer as its second argument. The second argument should be thesubscript of a column in the array. The function should return the total of thevalues in the specified column.● getHighestInRow. This function should accept a 2D array as the firstargument and an integer as its second…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