Return a vector without using input / output in C ++ subprograms

0

Hello, I'm doing an activity and c ++ that is complicating me ... in fact there are several that I spend hours trying to find something and I can not and most of them are not on the internet, I tried to search the same logic of this program in some places and I have not found. Maybe I'm making a longer and more complicated path but let's ...

Statement ---

  

Make a program that has a subprogram that receives a nonnegative integer and returns a vector with all its digits. This subprogram can not have any read or write operations. Numbers can be returned in the forward or reverse order by subprogram. Good planning of the parameters is fundamental and will be an important part of the evaluation.   It is allowed to make other subprograms to assist in the creation of this subprogram.   // The main subprogram should read the integer and write all the digits found by the other subroutine.   EXAMPLE OF ENTRY - 812 ///// EX FROM EXIT: 8 1 2

Well what I thought was the following

I have created a function to separate this integer digit, but in the inverse (since the statement allows)

It got more or less like this

int inverso(int resto, int numero){
    while(numero>=resto)
    numero-=resto;
    return numero;}

In the Main () function with the integer value entered by the user to return the desired value would only use while(inteiro > 0){ cout << inverso(10, inteiro) << " "; a = a/10;

With this the output would be "2 1 8" but I have to print a vector with that number according to the statement then I imagined the following

I create a function to fill the vector with these numbers and within this function I call my "inverse" function to separate the digits and write in reverse order in the vector.

And to fill the vector with the required size I created a third function that takes the amount of digits.

int digitos(int n){
return ceil(log10(n+1));
}

I think this third function is unnecessary because I believe it is possible to store each value in a vector in the "inverse" function itself and then do just a simple assignment of vector values in the "inverse" function for the vector in the function that I want print.

In short, in main () would only read / write data.

If anyone can help me thank you, and sorry if I said much crap kkkk.

Ah the code has to be in c ++. So nothing to use C inheritance, like some functions, libraries etc ...

    
asked by anonymous 17.07.2018 / 17:13

0 answers