Eeo 224 - object-oriented programming for electrical and


Object-Oriented Programming for Electrical and Computer Engineers

Exercise 1 - Random Walk

The following figure illustrates a random walk on an integer grid. You begin at the position Start and you are trying to get to the position Finish. Each time you reach a corner, you choose a direction at random, and take a unit step in that direction. You never wander outside the grid. So, if you are at the Start position, you have a choice of two directions: left and down. You choose one of these at random. If you are in the middle of the grid, you have a choice of four di¬rections: left, right, up and down. You choose one of these at random. Write a program to simu¬late the random walk, stopping when you reach the destination. Utilize the function rand () to generate a random number. Choose an N x N grid of size say N = 8.

Exercise 2 Standard Template Library (STL)

1. Create a Person class, with the person's name, age and the town of residence as the data members. Then create an STL deque of Person objects (≈ 5 objects). Display the contents of the deque.

2. In this problem, you will be utilizing STL vector. Noah and Sofia want to invite their friends to a party. Write a program which does the following:

- Reads the list of Noah's friends names, stores it in a vector, and displays it in sorted order.
- Reads the list of Sofia's friends names, stores it in a second vector, and displays it in sorted order.
- Creates a third vector, merges the contents of the previous two vectors, eliminates duplicates, and displays this list.Assignment 3
Standard Template Libraries (STLs) and Inheritance

Assignment

1. Write an algorithm to print different ways of arranging 4 rooks on a chess board, so that no rook can capture another. That is, none of them share the same row or column. Generate and display a few test cases.

2. Write a program to read in names and scores of N students, from a file. Then find the me- dian of all the scores. Utilize the STL container map. The scores should be in the range [0, 100]. As an example, you may use N = 10;

3. (a) Create an STL set S1 with N1 elements in the range [0, 400].
(b) Create an STL set S2 with N2 elements in the range [200, 600].
(c) Find the intersection of S1 and S2.
(d) Find the union of S1 and S2.
As an example, use N1 = 50, and N2 = 60.

4. Stephen Prata, Chapter 13, Programming Exercise 1 on base class Cd and derived class Classic.

Solution Preview :

Prepared by a verified Expert
Dissertation: Eeo 224 - object-oriented programming for electrical and
Reference No:- TGS02735591

Now Priced at $45 (50% Discount)

Recommended (99%)

Rated (4.3/5)