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

  Explain people-organizational and technological components

What is meant by information system? How does it work? Write down its people, organizational, and technological components?

  What is the address space in each of the following systems

An address space has a total of 1024 addresses. How many bits are needed to represent an address?

  Find wan organizations

Find WAN organizations (ISPs) that will connect you to the Internet or connect your offices. What services do they offer? What costs are involved?

  Write the code for invoking a method named sendobject

Write the code for invoking a method named sendObject . There is one argument for this method which is of type Customer . Assume that there is a reference to an object of type Customer , in a variable called John_Doe . Use this reference as your a..

  Find pythagorean triplets

Given an array of integers, find Pythagorean triplets. i.e. find a,b and c which satisfies a^2 + b^2 = c^2 Integers could be positive or negative.

  Create a list containing union of elements of two lists

Create a list containing the union of the elements of the two lists? Insert an element after the nth element of the list?

  Create a simple movie management system

Create a simple movie management system that manages a list of scheduled movies to be played at a fictitious movie theater. Your program must use of the "list" API in the C++ standard template library (STL).

  Calculations without an arithmetic and logic unit (alu)

Determine whether or not it is not possible for microprocessors to perform calculations without an Arithmetic and Logic Unit (ALU)

  Write a statement to print the counter value

Write a For loop such that the loop till iterate from 1000 to 1 decrementing the counter by 1 each time through the loop. Inside the loop, write a statement to print the counter's value to the Output window.

  Describes the ideal information security system

Write a 1500 to 1750 word paper that describes the ideal information security system plan for one of the following organization types: hospital, bank, manufacturer, online wholesale enterprise, department store, state revenue agency.

  One approach to system development

One approach to system development that Reliable might take is to start one large project

  Determine the size and contents

Determine the size and contents of: e=1:-1:5;

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