[Solved] CH231A assignment1-Template array search

$25

File Name: CH231A_assignment1-Template_array_search.zip
File Size: 376.8 KB

SKU: [Solved] CH231A assignment1-Template array search Category: Tag:
5/5 - (1 vote)

First write a generic array_search() function using templates. The array search function should receive an array of elements, the corresponding number of elements, the element searched for and should determine if that element is in the array or not by returning its index or -1 if not in the array. Then write a test program with a main function which uses the function above for multiple types (some example basic data types and Complex objects).

You can assume that the array will contain at least one element. Make sure that your code works not only with basic data types but also with a simple Complex class.

you can assume that the array will contain at least one element. Make sure that your code works not only with basic data types but also with a simple Complex class.

Problem 1.2 Stack with templates

Language: C++

Design and implement a generic stack class. By using templates your stack has to be able to store any type of data. The underlying data structure should be an array.

While designing and implementing your class you cannot use any of the container classes from the Standard Template Library (STL).

Your class should support the following operations (read all the requirements before starting to write code):

  • Stack(): this constructor initializes the stack to a size of 10.
  • Stack(const Stack&): copy constructor, create a real copy of the stack.
  • Stack(int size): this constructor sets the stacks size to the given size.
  • bool push(T element): adds element to the top of the stack. It should return true, if the element has been successfully pushed. So as long as you do not provide an extend() method, you need to check for available space and return false if there is no more space.
  • bool pop(T& out): pops an element from the top of the stack. The element is put into out. It should not crash if there are no elements on the stack, but rather return false, otherwise it should return true.
  • T back(void): returns the data on the top of the stack, without changing the stack.
  • int getNumEntries(): returns the number of entries of the stack at a given moment.
  • Destructor for the template class.

Finally, write a simple program which tests the functionality of your stack.

Name the files Stack.h and testStack.cpp. You can assume that the input will be valid.

Problem 1.3 List with templates as doubly linked list

Language: C++

Implement a generic list using templates using a doubly linked list instead of an array. Provide constructors, destructor and methods for returning (with and without remove) the first and last element as well as adding a new element at the front and at the end of the list. Also implement a method which returns the amount of elements in the list.

Name the files LinkedList.h and testLinkedList.cpp. You can assume that the input will be valid.

Problem 1.4 Using vectors I

Language: C++

Write a program which does the following using a vector object:

  1. Read words from the keyboard (one per line) until the entered word is equal to the wordEND. You can assume that the words do not contain whitespace.
  2. Insert these words into the vector at the end (excluding the word END).
  3. Print the words on the standard output separated by spaces using the index operator.
  4. Print the words on the standard output separated by comma using a corresponding iterator.Make sure that you do not print a comma after the last word.

You can assume that the input will be valid.

Problem 1.5 Using vectors II

Language: C++

Write a program which does the following using a vector object:

  1. Read strings from the keyboard (one per line) until the string is equal to the string END. Make sure that you can read strings which contain spaces and/or tabs as well.
  2. Insert these strings into the vector at the end (excluding the string END).
  3. If the second and fifth elements (i.e., strings) exist, swap the second and fifth element. Ifone of them or both do not exist then print a message on the standard output.
  4. Replace the last element with the string ???.
  5. Print the strings on the standard output separated by comma using the index operator.Make sure that you do not print a comma after the last string.
  6. Print the strings on the standard output separated by semicolons using a correspondingiterator. Make sure that you do not print a semicolon after the last string.
  7. Print the strings on the standard output in the reversed order separated by space using aniterator.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CH231A assignment1-Template array search
$25