Starting from:

$29.99

Programming Paradigms Assignment 2 (Part 1): Basic C++ Concepts Solution


Develop the programs mentioned below using basic features of C++ programming language. Please don't use the concept of Class. No credit will be given if the following C++ features are not applied wherever applicable -
 Standard Input/Output
 Namespace
 Constant
 Reference variables
 Call by Reference
 Template Function
 Default parameter
 Inline function
 Static Polymorphism / Function overloading
 Free from memory leak / garbage / dangling reference
Problems

2. Develop a program that supports functionalities of a variable length 1-D array. Let us call it RuntimeSizeArray (RSA). RSA is supposed to be initialized with some predefined initial size to store integer elements. If the space in RSA is exhausted by populating elements, it inflates by adding extra space in it. However, RSA should have some upper bound of its size and once that is reached, RSA cannot inflate any more. Note that linklist shouldn’t be used in this program.

i. All required information (data) to maintain an array should be bundled in a structure called RSArray.
ii. Develop the following functions (subroutines shouldn’t be part of the structure) :
a) initialize(...) : This is to initialize the data related to an instance of the array
b) addElem(...) : Add/update element(s) into the array
c) fetchElem(...) : Obtain an element from the array of a desired location
d) inflate(...): Inflates the array size by adding extra space in it.
e) resetElements(...): Reset N number of elements from a given index of the array
f) getMaxSize(...) : Should notify the maximum number of elements the array can store
g) getCount(...) : Should notify the current number of elements in the array
iii. Any other suitable function(s) you think relevant
iv. Demonstrate the basic array functionalities using above routines
v. Demonstrate that multiple arrays can be instantiated and can co-exists in different state.
3. Write a generic method to swap elements. Demonstrate that it works for any data types such as int, short, float, double and struct.
4. Write a generic method to sort N (user's input) elements of any basic data type. Use any sorting algorithm of your choice. Demonstrate that it works for any basic data types such as int, short, float, double etc. Later try the similar approach for struct data types to realize that it does not work there.

5. In a game, let us consider that N (user's input) number of persons are standing on a circle boundary and waiting to be evicted. Counting begins at a specified point (randomly selected) on the boundary and proceeds around the circle in a specified direction. After a specified number of people (S) is counted to be skipped, a person is evicted. The procedure is repeated with the remaining people, starting from the person next to the evicted one, going into the same direction and skipping the same number of people, until only one person remains. The remaining person is selected as the winner of the game.

Write a program for this game. The aim of this program is to find the name of the persons evicted one after another and finally the name of the winner.

To develop the game you must use a circular linklist where each node of the linklist represents a person. While developing the game you are encouraged to adopt modular approach. Write suitable functions and put them in a separate file. Expose only those functions which are required to be used by the client program. Client program should include the corresponding header file and write only the main() function in it.

More products