computer science 8003693 2

Week 3-4 Programming Assignment

Core Learning Outcomes addressed in this assignment:

  • Demonstrate creativity and problem-solving skills. (9)
  • Write C++ programs that use proper style and documentation. (10)
  • Write C++ programs that use Pointers and dynamic memory allocation. (11)
  • Write C++ programs that uses Function Templates. (11)
  • Its is C++ program

Grading Information: This Lab Homework is worth 76 points and due by Sunday of week 4 at midnight CST.

The purpose of this assignment is to assess if you can create a program that uses pointers, templates, and dynamic memory allocation.

Two files are required to make this program work, d_random.h and d_vector.h. 
Both files are available in the “Doc Sharing” area.

Directions Points
The file must be called week3-4Prog.cpp

This program will store in miniVector v a list of 15 random integers from 0 to 99, then it will output the vector, sort the vector, then output it again sorted. The miniVector class is on page 250.

Program Definition

1. Create program definition with the following templates and methods:

// output miniVector v
template <typename T>
void writeMiniVector(const miniVector<T>& v);
// use insertion sort to place miniVector v in descending order
template <typename T>
void sortMiniVector(miniVector<T>& v);

Main Method

1. Declare: miniVector<int> v;
2. Declare: randomNumber rnd;
3. call v.push_back(rnd.random(100)); to push 15 entries from 0-99 onto the vector
4. call writeMiniVector to output vector
5. call sortMiniVector to sort the vector
6. call writeMiniVector to output the sorted vector.

After you output the sorted vector:
Include: system(“PAUSE”); after your output to pause the screen.

writeMiniVector Method (const miniVector<T>& v)

1. Iterate through the vector v and output each element to the screen.

sortMiniVector Method (miniVector<T>& v)

1. Sort the elements of vector v.
2. Since it is passed-by-reference, no return is necessary.

Ensure you include ALL .cpp file(s) and any associated, student-defined .h (header) files required to make your program compile and run. The only files in the dropbox should be .cpp and .h files.  Do not turn in .zip, .exe, .rar, etc files. 10
Upload your page to the Dropbox.

NOTE: Complete your activity and submit it to the Dropbox by clicking on the Dropbox tab at the top of the course frame and choosing the correct Weekly Activity.

If needed, click on the Help button above for more information on Course Tools/Using the Dropbox.


Total Possible Points

Example output of your program

Original: 59 18 60 91 49 47 83 93 55 52 15 36 83 56 91
Sorted: 93 91 91 83 83 60 59 56 55 52 49 47 36 18 15