Permutation

This is my code but the thing is that I need to create a void inside the class that already reads the permutation and performs the operations...instead of having the code in the main...



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <vector>

using namespace std;


class Permutacion{
       int per;

       public:
       vector<int> datos;
       Permutacion(){per=0;};
       void Set(int a){ datos.push_back(a);
       };
       void Actualizar_per(){
            per++;
            }; 
       int Get_per(){ 
           cout << per << endl;  
       };     
};







int main(){
    
    int tmn;
    cin >> tmn;
    
    int i=0,n;
    Permutacion conj;
    
    do{
       cin >> n;
       conj.Set(n);
       i++;
       }while(i<tmn);
       
       int c=1;
       do{
           for(int e=0;e<conj.datos.size(); e++)
               if(conj.datos.at(e)==c)
                 c++;
                 if(c<=tmn+1)
                      conj.Actualizar_per();
       }while(c<=tmn);
                      
       conj. Get_per();
    
 
}

Sorry...for crearly defining my problem I am having...my code works and gives me the permutation in reference to the cardinal that is input...but I need to have the Class Permutacion define a void that reads the Permutation instead of doing it in the int main()

example:

class Permutacion{
. //This is representing the code that is good
.
.
void Read_per(){

/* This is where I need help */
};
What is that function supposed to do?
Also
1
2
3
       int Get_per(){ 
           cout << per << endl;  
       };     
No return statement in a non-void function
1
2
3
4
 
int Get_per(){ 
           cout << per << endl;  
       }; 



This function is used later in the main body to show the permutation
the function is supposed to tell me this:

9
1 2 5 6 7 3 4 8 9

The result is two.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <vector>

using namespace std;

class Permutacion{

    private:

        vector<int> datos;
        int permutaciones;
        int tam;

    public:

        void Resuelvemeto();
        void ActPer(){permutaciones++;};
        void GetPer(){cout << permutaciones;};
        void SetVector(vector<int> vector){datos = vector;};

        void SetPer(){permutaciones = 0;};
        void ActualizaTam(int t){tam = t;}

};



void Permutacion::Resuelvemeto(){
    bool encontrado = false ;
    bool fin = false;
    SetPer();
    int i = 1;

    while(i<=tam){
        for(int j = 0 ; j < tam ; j++){
            if(datos.at(j)==i)
                i++;
        }
        ActPer();
    }

};

vector<int> LeerVector(int t){

    vector<int> v;
    for ( int i = 0 ; i < t ; i++){
        int a;
        cin >> a;
        v.push_back(a);
        }
    return v;
}

int LeerTamanyo(){
        int t;
        cin >> t;
        return t;
}

int main()
{
    Permutacion per;
    vector<int> vec;
    int tam;
    tam = LeerTamanyo();
    vec = LeerVector(tam);
    per.ActualizaTam(tam);
    per.SetVector(vec);
    per.Resuelvemeto();
    per.GetPer();
}


I figured it out
for crearly defining my problem I am having...
Topic archived. No new replies allowed.