Smallest sequence of numbers in the array

Assignment Help C/C++ Programming
Reference no: EM13104542

Write functions which solve each of the following problems. You must place all of your functions in one project. If you use any code that you find online, you must reference it in comments.

1. Write a function called my_str_n_cpy() that accepts pointer to a destination character array and a pointer to a source character array (which is assumed to be a string) and returns the pointer to the destination character array. This function needs to copy at most n characters, character by character, from the source character array to the destination character array. If a null character is encountered before n characters have been encountered, copying must stop. You may NOT use any functions found in <string.h> to solve this problem! Note: you may use array or pointer notation in this function.

2. Recall Binary Search:

Input: a list of n sorted integer values and a target value

Output: True if target value exists in list and location of target value, false otherwise

Method:

Set left to 1 and right to n

Set found to false

Set targetindex to -1

While found is false and left is less than or equal to right

Set mid to midpoint between left and right

If target = item at mid then set found to true and set targetindex to mid

If target < item then set right to mid - 1

If target  > item then set to left to mid + 1 

Return the targetindex

Write a C function called binary_search().

3. Write a function called bubble_sort() that accepts an array of pointers to strings and the number of strings as arguments, and returns nothing. The function sorts the strings according to the following algorithm:

1. set the marker U for the unsorted section at the end of the list (U is an integer index value)

2. while the unsorted section has more than one element do steps 3 through 7

3. set the current element marker C at the second element of the list (C is an integer index value)

4. while C has not passed U do steps 5 and 6

5. if the item at position C is less than the item to its left then exchange these two items

6. move C to the right one position

7. move U left one position

8. stop

Your implementation for this function may NOT use strcpy(). You may only exchange or swap pointers, but NOT actually make copies of the strings!

4. Write a recursive function called is_palindrome() that accepts a pointer to a string and its length, and recursively determines if the string is a palindrome. The function must return 1 for a palindrome, 0 otherwise. A palindrome is a sequence of symbols that may be interpreted the same forward and backward. For example, "race car". Note: whitespace should be ignored in your solution.

5. Write a recursive function called sum_primes() that accepts an unsigned integer, n, as an argument, and returns the sum of all primes from 2 to n. You must use recursion to solve this problem!

6. Write a function called maximum_occurences() that accepts a pointer to a string (consisting of alphanumeric and whitespace characters only), a pointer to an arrayof struct occurrences,  a pointer to an integer, and a pointer to a character as arguments. The structure is defined as follows:

typedef struct occurrences

{

          int num_occurrences;

          double frequency;

} Occurrences;

The function determines the frequency of each character found in the array. The frequency is defined as: number of one character symbol / total number of characters. The function should use the second array argument (of struct occurrences) to keep track of the frequency of each character. Also, it must return, through the pointers, the maximum number of occurrences of any one character and the corresponding character for which the maximum represents. Thus, for a string such as "test string", 't' occurs 3 times, which is the maximum occurrences for any one character in the string.

7. Write a function called sum_smallest_sequence() that accepts an array of signed integers and the number of items in the array as arguments, and returns the sum of the smallest sequence of numbers in the array. A sequence is defined as a single item or multiple items that are in adjacent memory locations.

8. Write a function called max_consecutive_integers() that accepts a two-dimensional array of signed integers, the number of rows, the number of columnsas input parameters, and two pointers as output parameters (one of these pointers is actually a pointer to a pointer, i.e. two stars!). The function finds the maximum consecutive sequence of one integer. The first pointer stores the address the start of the maximum consecutive sequence of the same integer. The second indirectly stores the number the same consecutive integers in a row. These sequences may wrap from one row to the next. For example ([$xxxx] denotes address value):

Row/Column

0

1

2

3

4

0

-5

[$1000]

6

[$1004]

0

[$1008]

2

[$1012]

2

[$1016]

1

2

[$1020]

2

[$1024]

2

[$1028]

9

[$1032]

3

[$1036]

2

3

[$1040]

3

[$1044]

2

[$1048]

1

[$1052]

-8

[$1056]

3

7

[$1060]

-2

[$1064]

6

[$1068]

0

[$1072]

4

[$1076]

The function should store the address of row 0, column 3 ($1012) via the first pointer, and 5 (2, 2, 2, 2, 2) indirectly via the second pointer.

Reference no: EM13104542

Questions Cloud

How two point charges q and 2q lie on the x-axis : two point charges q and 2q lie on the x-axis . which regions on the x-axis include a point where the electric field due to the two point charges is zero?
How far from the building will the stone land : A stone is thrown horizontally from the roof of a tall building with a speed of 23.3 m/s. If the cliff is 26.5 high and stone lands on level parking lot below, how far from the building will the stone land?
Explain objective of the cover letter for job search : When doing the job search, do you use the cover letter? If so, what is the objective of the cover letter? For job searching online/electronically, do you use the cover letter as well?
Finding the critical values : Embassy Club Condominium, located on the west coast of Florida, is undertaking a summer renovation of its main building. The prject is scheduled to begin May 1, and a September 1 (17- week) completion date is desired.
Smallest sequence of numbers in the array : Write a function called sum_smallest_sequence() that accepts an array of  signed  integers and the  number  of items in the array as arguments, and returns the sum of the smallest sequence of numbers in the array.
Compute number of observations : Estimated idle time of a fork lift truck is 40%. Relative accuracy desired = +/- 10%; Desired confidence level = 95%. How many observations (n) are required?
Securities and exchange commission under securities act 1933 : Some argue that government needs to increase its regulation of business for the good of society as a whole, while others believe that the marketplace is self-regulating and that government intervention through needless regulation places an unfair.
Mean deviation of the population : Find the mean, median, mode, variance, standard deviation, frequency table, cumulative frequency table, coefficient of variation, and mean deviation of the population.
Explain details from the which are good and written well : Write down the 100-word message to Susan Anker, author of the textbook, in which you explain five details from her book which are good and five details about book which are written well.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Object oriented programming paradigm is better choice

Explain why object oriented programming paradigm is considered better choice than structured programming paradigm. Does it reflect our "natural" way of thinking or do you find it artificial?

  Implement recursive algorithms using a stack

Show the difficulties of the added complexity and which of the two sorts is easier to implement nonrecursively? Why?

  Describe the probability of the moves

Write a program in C++ to describe the Probability of the moves

  Prepare a linux shell

Prepare a linux shell (in other words, write a C/C++ program) that will recursively prompt for input from the user. The shell should prompt as

  Create if-then statement with single alternative decision

Create the If-Then statement (or a flowchart with a single alternative decision structure) which assigns 20 to  variable y and allots 40 to variable z if variable x is greater that 100.

  Create class having constructor to recieve two ints

Create a class (in C++)named Card. The class should have two int data members named face and suit.The class should have a constructor that recieves the two ints and uses them to initialize the data members.

  Writing a program that creates a linked list

Writing a program that creates a linked list from 100 randomly generated numbers and sorts the using a heap. One heap in ascending order and one heap in descending order. Then displays the original linked list and both sorted lists.

  Write c program-visual studio to scan multiple text files

Write program in C or C++ and Visual Studio to scan multiple text files and count number of occurrences of each word in those files. Use binary tree to keep track of all words.

  Create class has three pieces of information as data members

Create a class called Date in C++ that includes three pieces of information as data members: month (type int), day (type int) and yaer (type int).

  Write a driver program called testrationalnumber.cpp

Write a driver program called testRationalNumber.cpp to test each of the above functions and overloaded operators in the RationalNumber class.

  Write program to read from file to find number of integers

Write down the program which reads from file numbers.txt 30 integers in range 0 - 200. Program ‎then determines number of integers in each of given ranges.

  Write function to accept character array

Write down the C++ function which will accept the character array of at most 30 cells. Your function must return true if string and its reverse are identical;

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd