Concept explainers
Write the definition for a class named Vector2D that stores information about a two-dimensional vector. The class should have functions to get and set the x and y components, where x and y are integers.
Next, overload the * operator so that it returns the dot product of two vectors. The dot product of two-dimensional vectors A and B is equal to
Finally, write a main subroutine that tests the * operation.
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
ABSOLUTE C++ -TEXT
Additional Engineering Textbook Solutions
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Database Concepts (8th Edition)
Modern Database Management
SURVEY OF OPERATING SYSTEMS
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
- Write a program that will sort a prmiitive array of data using the following guidelines - DO NOT USE VECTORS, COLLECTIONS, SETS or any other data structures from your programming language. This will also use your 'Currency' and 'Money' classes from the previous lab, so everything for this lab will be in a new file for 'main'. (Programming language Java) Create a helper function called 'RecurInsSort' such that: It is a standalone function not part of any class from the prior lab or any new class you feel like creating here, Takes in the same type of parameters as any standard Insertion Sort with recursion behavior, i.e. void RecurInsSort(Currency arr[], int size) Prints out how the array looks every time a recursive step returns back to its caller The objects in the array should be Money objects added or manipulated using Currency references/pointers. It is OK to print out the array partially when returning from a particular step as long as the process of sorting is clearly…arrow_forwarduse c++ to Write a function template palindrome that takes a vector parameter and returns true or false according to whether the vector does or does not read the same forward as backward (e.g., a vector containing 1, 2, 3, 2, 1 is a palindrome, but a vector containing 1, 2, 3, 4 is not)arrow_forwardCODE MUST BE IN OCAML LANGUAGE! 1. Create a type slidingTile, consisting of a char matrix and two integers x and y. The integers x and y are the coordinates of an empty tile. 2. Create a function val slide : slidingTile -> int -> int -> slidingTile = that given a slidingTile and two integers, that represent a location in the matrix, it slides the tile from the specified location to the empty tile, then returns the altered slidingTile. If provided location is not adjacent to the empty tile, or out of bounds, then return the slidingTile unaltered. 3. Create a function val print_tile : slidingTile -> unit = that prints a slidingTile on screen with the corresponding characters from the matrix. However, print an empty space where the empty tile is instead # let a=...# print_tile a;;12345678# slide a 2 2;;# print_tile a;;12345678# slide a 3 2;;# print_tile a;;1234567 8# slide a 4 2;;# print_tile a;;1234567 8# slide a 2 2;;# print_tile a;;1234 6758arrow_forward
- In C++, create a class for a 3-dimensional array. To make it more general, allow the actual dimensionality to be 0d, 1d, 2d, or 3d. It should support indexing with operator(). If the programmer subscripts with fewer indices than you 'need' (0 for a 1d, 0 or 1 for a 2d, 0 or 1 or 2 for a 3d -- note that you can't under-subscript a 0d array), you should return the appropriately sized sub-array (of your class's type). (Note: This will require multiple overloads of operator() with different numbers of index arguments.) Since, as a template, math operations don't make sense, you'll have to for-go addition, etc. But you could use + and += for concatenation. Basically aligning the common dimensions of the two arrays and concatenating along the remaining dimension. (There can be only one for this to make sense. If there are none remaining, there are options for those kinds of things!) Make sure to overload it for proper dimensionality: Of course, you should also support input (the programmer…arrow_forwardCreate an expansion of the structure. MyVector is a new vector that has the sort technique. The following actions can be taken to implement this new class: 1. Define a new class called MyVector as an extension of the structure. vector type. With this class, you ought to provide a default function Object() { [native code] } that only calls super();. The structure will be forced by this. To be called is the vector function Object() { [native code] }. This will then initialise the Vector class's protected fields. 2. Create the sort method as a new Vector method. The declaration that follows should be included: Public void sort(Comparator c) / pre: c is an acceptable comparator / post: sorts this vector according to c's order This function actually sorts the data in MyVector using an object of the Comparator type. You are free to utilise any kind. 3. Create a programme that reads a data file containing many fields and, dependingarrow_forwardcan you write in C++arrow_forward
- 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 peaksarrow_forwardGiven vector.h and vector.c from the Vector ADT section of the book, modify the code so that the vector holds characters instead of integers. Define also the following new functions in vector.c :arrow_forwardwrite in html and scriptarrow_forward
- Write a C ++ program that deletes positive integers from the vector and then writes the vector elements. in to do this; Write a function that takes an integer vector as a parameter and returns that vector after deleting its positive elements, and call the FunctionDelete positives (vector v) umw m B) Write a function that takes a vector as a parameter and prints the vector elements. Name this function printVektor (vector v). mw m m C) Write an appropriate amine method for the program. Define a vector containing negative and positive integers. Use the above function to show how to delete positive elements. Hint: the index positions of the elements are shifted after an item is mw m w w m v m w w mw m w deleted.arrow_forwardWrite a function named mean that accepts as a parameter a reference to a vector of real numbers, and returns the arithmetic mean (average) of the integers in the vector as a real number. For example, if the vector passed contains {2.0, 4.5, 6.5, 1.0}, your function should return 3.5. If the vector is empty, return 0.0. Do not modify the vector that is passed in.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
- 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