Provide an implementation of the mymaximum function

Assignment Help Basic Computer Science
Reference no: EM13767286

Exercise 1: Finding the maximum value

int mymaximum(int a[], int numberOfElements);

Provide an implementation of the mymaximum function whose declaration is shown above. The first argument of the function is an array of int and the second argument is the number of ints that are in the array. The function returns the largest int that is in the array.

Write test code that thoroughly tests the function. The test code should use assertions.

Exercise 2: Appending integers

void append(vector<int> & v, int n);

Provide an implementation of the function whose declaration is shown above. The first argument of the function is a vector of int and the second argument is the number of consecutive integers to append to the vector starting from 0 and ending at n - 1. The function appends onto the vector v the values 0, 1, 2, ..., n - 1. (Hint: use the push_back function of vector to append these values to v.)

Write test code that thoroughly tests the function. The test code should use assertions.

Exercise 3: Appending vectors

void appendVector(vector<int> & v, const vector<int> & w);

Provide an implementation of the appendvector function whose declaration is shown above. Both arguments of the function are vectors of int. The function should modify vector v by appending to it all the elements of w. For example, if v = (4, 2, 5) and w = (11, 3), then v will become (4, 2, 5, 11, 3) as a result of calling the function. Hint: the vector class has a function called push_back that appends values passed into it.

Exercise 4: Vector insertion

Suppose a vector v contains a sequence of integers ordered from lowest to highest. For example, v might contain the values 3, 6, 7, 12.

Write a function called insert that takes this vector v as a first argument and an integer k as the second argument. The function inserts k into the vector so that it preserves the order of elements. For example, if v were (3, 6, 7, 12) and k were 8, then after calling the function, v would be (3, 6, 7, 8, 12). In your implementation of insert, do not use the insert function of the vector class (v.insert).
Write test code that thoroughly tests the function. The test code should use assertions.

Exercise 5: Counting occurrences

int countOccurrences(const vector<int> & v, int k);
Implement the function countoccurrences whose declaration appears above. The first argument of the function is a vector v of integers and the second argument is an integer k. The function returns the number of times k occurs in v.

Exercise 6: Two-dimensional arrays

bool isAllZeros(int a[50][100]);

Implement the function isAllZeros that uses a loop nested inside another loop to determine whether a 2-dimensional array contains only zeros. A declaration of the function is shown above. The array passed into the function will have 50 rows and 100 columns.

Exercise 7: Identical Vectors

bool areIdentical(const vector<int> & a, const vector<int> & b);

Write a predicate function that checks whether two vectors are identical (contain exactly the same elements in the same order). A declaration of the function is shown above. The function returns true if the two vectors are identical; otherwise it returns false.

Exercise 8: Unlucky Vectors

bool isUnlucky(vector<int> & v);

Implement a function that determines if the unlucky number 13 appears in a vector. The function returns true if 13 appears in the vector at least once; otherwise it returns false. Write test code that tesets every statement in the function. Use assertions in your test code.

Exercise 9: Ordered Vectors

bool isStrictlyIncreasing(const vector<int> & v);

Write a predicate function called isStrictlylncreasing that checks whether a vector of integers contains values that are in strictly increasing order. A declaration of the function is shown above. The function returns true if the elements are in strictly increasing order; otherwise it returns false. For example, it will return true for v = (2, 4, 5, 6, 8) and it will return false for (3, 4, 6, 6, 9).

Exercise 10: Flatten

vector<int> flatten(int a[100][200]);

Write a function named flatten that takes a 2-dimensional array of integers with 100 rows and 200 columns and returns a vector that contains all of the array's elements. Copy the values a row at a time. In other words, first copy row 0 into the vector, then row 1, then row 2, and so on. The declaration of flatten is given above.

Reference no: EM13767286

Questions Cloud

What is the difference between art and entertainment : What is the difference between art and entertainment? How has the commercial music industry affected the artistic integrity of popular musicians?
What is the bar''s angular acceleration : The 0.4kg slender bar and 1 kg disk released from rest in the position shown. if the disk roll, what is the bar's angular acceleration at the instant of release?
Reported about a sexual offender who continued offending : The Miami Herald reported about a sexual offender who continued offending, because the system continues to fail. Discusses this topic and in specific, the use of chemical castration as a sentencing method for convicted sex offenders
How mindfulness and other buddhism related approaches : Topic: How mindfulness and other Buddhism related approaches in psychology can be beneficial for children?
Provide an implementation of the mymaximum function : Provide an implementation of the mymaximum function whose declaration is shown above. The first argument of the function is an array of int and the second argument is the number of ints that are in the array. The function returns the largest int t..
How fast in rpm must a centrifuge rotate : How fast in rpm must a centrifuge rotate if a particle 7.0 cm from the axis of rotation is to experience an acceleration of 125,000 G's
What role ethnicity play in politics of a asian pacific : What role does ethnicity play in the politics of a given Asian Pacific country? How does film, fiction, or art represent economic, political, or social trends in a given Asian Pacific country?
What application does the ucc have here : What do you think about this situation? Should parties to a sales contract be able to rescind a contract because of mutual mistake of fact? Why or why not? Did either party act unethically in this case? Why or why not? What application does the UC..
Are the aircraft moving at a constant velocity : A 1000 kg aircraft going 25 m/s collides with a 1500 kg aircraft that is parked and they stick together after the collision and are going 10 m/s after the collision. If they skid for 8.2seconds before stopping, how far did they skid?  Hint: Are the a..

Reviews

Write a Review

Basic Computer Science Questions & Answers

  What is the order of the public key?

the weaknesses that arise in Elgamal encryption if a public key of small order is used. We look at the following example. Assume Bob uses the group Z ? 29 with the primitive element ?= 2. His public key is ?= 28.

  Compute expected payback percentage of machine

Compute the expected "payback" percentage of the machine. In other words, for each coin played, what is the expected coin return?

  Troubleshooting rip and eigrp vlab

Troubleshooting RIP and EIGRP vLab

  Remember to make only one step at a time

Prove the following. Remember to make only one step at a time and not skip steps. Remember to write what rule allowed you to make each step, and which lines you applied it to

  Create three integer variables and initialize them

Create three integer variables and initialize them to whichever value you'd like. ? Create three functions: ? A function that accepts two integers as parameters and subtracts the second from the first.

  Critically analyze the transmission media

Critically analyze the transmission media you would recommend for each different building and department of the medical instrument company

  Explain hacktivism includes cracking for higher purpose

And "hacktivism" includes cracking for "higher purpose". Is it feasible to crack systems and still be ethical? Support the position.

  What do you do when an application freezes

What do you do when your computer freezes and what do you do when an application freezes?

  Classify computer systems according to capacity

Classify computer systems according to capacity. How they are different from computers according to the classification of technology. Provide comparative study also.

  Compare the running time of this modification

Compare the running time of this modification with that of the original algorithm on sequences that are nearly sorted or reverse sorted, and on sequences with many identical elements. What do you observe?

  Course major and gpa of any students on athletic scholarship

Using the data from the database you created yesterday for me:Extract the First and Last Name, Student ID, Course Major and GPA of any students on athletic scholarship. Sort by Student ID. Produce a report with the data from Step #1 and Use good head..

  Examine how coppa and cipa are similar and how they are

write a three to five 3-5 page paper in which you describe the main compliancy requirements and the protected

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