So I am first year at Uni and I am new to C++ and I am still trying to learn the basics. I can't seem to find the right way to start my exercise.

Ex1. Create a program, which is with a main() function and menu-function for:
1.1) Inputting N elements (User input) to a one dimensional array with validation check (N<=20)
1.2) Copy the contents of this array into another one in the reverse order.
1.3) Copy the first array (the inputted one) into a third one and sort it ascending/descending.
1.4) Output on the screen information about that array with clarifying text.

And here's my main problem. I know how to do 1.2 and 1.3 but I don't know where to start from.
I am torn between 2 options and I am not sure which one suits better. So the first one is declaring the size of the array as 20. Or setting a size max constant. And if the user enters f.ex. 16 elements the items of the array from 0-15 will be declared and the other 5 will be left empty. And then do a validation check
And the other one is asking the user to input the size and by using pointers to assign the inputted value to the size of the array. And then run a validation check.

What would you suggest me? How should I start?

Recommended Answers

All 2 Replies

Doesn't matter which method you use -- pointers and new (remembering the delete when you have finished with the array) is perfectly fine, however, so is declaring three arrays of size 20 and filling only the first part of each.

Note you need to check the user input isn't bigger than 20 before you do anything with the arrays. Also be careful about the user being "clever" and entering -1 elements or such like.

Finally, post some code if you get stuck.

Honestly the first thing that I always do when trying to figure out a problem is write it in psuedocode. This lays out what I need the program to do and will help me visualize the best solution to the problem. It also helps with other things such as helping you decide what/how many variables you need, how each situtation is handled such as if/then and whatever else. This is usually taught in the first couple of chapters in any introductory programming class (at least the ones I took).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.