I have been trying to do this practical, but the problem is I don't understand what/how am I going to programme this scenario, I am new in C++ programming language. If anyone can explain to me the following problem I would really appreciate it. Thank you in advance, Here is the case study:
This practical will focus on the use of vectors. Create a menu-driven, library-based system which performs the following operations:
• All functions apart from main are stored in a programmer defined library called libPrac6 with corresponding interface and implementation files.
• All functions must reside in the VectorSpace namespace.
• Generates a vector of random integers using user-provided values for the maximum, minimum, and number of entries.
• Prints the contents of the vector to the standard output.
• Empties the contents of the vector .
• Calculates and displays the arithmetic mean .
• Calculates and displays the median value (the built-in sort function may be used for this)
• Calculates and displays the modal values (most frequently occurring values).
• Must make use of both pass by value and pass by reference functions
Start by creating the menu and doing just the first two functions - generate a vector of random numbers and print it out.
Once you have that working, add the other functions one at a time.
You can search this site for lots of examples of menu driven programs, vectors, random numbers, arithmetic mean and mode. There are fewer examples of using namespaces. Libraries are implementation dependent so you'll need to tell us about what computer you're writing on and what development environment you're using.
Thank you so much for your response Dhayden, it really helped me, well I am using codeblocks as my development environment and the computer I am using is Dell Inspiron i7 8th Generation.
I've managed to write the code for the aforementioned problem, I will post my work here so that if you have time you can just show me if I've done the right thing, once again thanks for your time.
Never put usingnamespace xyz; in a header file. It causes that "using" functionality to spill over into any other header files that you may included after this one. The results can be really hard to debug. Instead, use the fully qualified names in headers and put the using namespace xyz; in the cpp file. Better still, use using std::vector; etc. so you're making visible only the symbols that you require.
Putting it all together (and into one file for my testing):
mean is the average ... sum of everything divided by the number of things summed.
median is the sorted list's center element. ( list[sizeoflist/2])
mode is the value that appears the most time. you just have to count them after sorting. you can do that while you sum them for the average, to save a loop.
you can look this stuff up online for in depth answers ... there may be conventional rules on what choices to make for odd sized list on median or which of several equally frequent items to pick for mode, I don't recall the edge case rules.