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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#include <iostream>
#include <vector>
class Any_power
{
public:
int size;
int count;
int a;
int b;
std::vector < std::vector < int > > power_container ; // vector 2D for matrix construction
explicit Any_power(): size( 3 ), count( 0 ), a( 2 ), b( 2 ) {}; // constructor
explicit Any_power( std::vector< std::vector < int > >& V_init ); // constructor for matrix
int power_function( int A, int B, std::vector < std::vector< int > >& p_cont ); // member function for calculate power a^b
void find_egual_item( int A, int B, std::vector < std::vector< int > >& p_cont ); // find ugual item on the vector 2D
int cleaner( std:: vector < std::vector < int > >& fresh_and_clean ); // delete item = 0 to vector2D
void printer( int C ); // stampa il risultato
void power_engine_start(); // funzione generatrice
};
/*
*--------------------------------------------------------------*
| constructor for vector 2D |
*--------------------------------------------------------------*
*/
inline Any_power::Any_power( std::vector< std::vector < int > >& V_init )
{
for ( int i = 0; i < size; i++ )
{
V_init.push_back( std::vector < int > ( size ) );
while ( 1 )
{
V_init.push_back( std::vector < int > ( size ) );
break;
}
}
}
/*
*--------------------------------------------------------------*
| member function for calculate power a^b |
*--------------------------------------------------------------*
*/
inline int Any_power::power_function( int A, int B, std::vector< std::vector< int > >& p_cont )
{
int i( 2 ) , C( 1 ) , digits( 1 ) , k( 1 );
p_cont[ A ][ 0 ] = 1; // <<>-------### the problem !!
while ( C <= B )
{
C += i ;
for ( int j = 2; j <= digits; j++ )
{
if ( k > 9 )
p_cont[ A ][ j ] = p_cont[ A ][ j ] * p_cont[ A ][ j ] + ( k / 10 );
else
p_cont[ A ][ j ] *= p_cont[ A ][ j ];
k = p_cont[ A ][ j ];
if ( p_cont[ A ][ j ] > 9 )
{
p_cont[ A ][ j ] = p_cont[ A ][ j ] % 10;
digits++;
}
}
i++;
}
return 0;
}
/*
*--------------------------------------------------------------*
| find ugual item on the vector 2D |
*--------------------------------------------------------------*
*/
inline void Any_power::find_egual_item( int A, int B, std::vector<std::vector<int> >& p_cont )
{
for( int i = 0; i <= A; i++ )
{
for( int j = 0; j <= B; j++ ) //attenzione! il numero รจ composto da tutta la serie di j!! change pls
{
if( ( p_cont[ i ][ j ] != 0 ) && ( p_cont[ A ][ j ] == p_cont[ i ][ j ] ) )
{
p_cont[ A ][ j ] = 0;
}
}
}
}
/*
*--------------------------------------------------------------*
| delete item = 0 to vector2D |
*--------------------------------------------------------------*
*/
inline int Any_power::cleaner( std::vector < std::vector < int > >& fresh_and_clean )
{
for( int i = 0; i < fresh_and_clean.size(); i++)
{
for( int j = 0; j < fresh_and_clean[ i ].size(); j++ )
{
if( fresh_and_clean[ i ][ j ] == 0 )
{
for( j = 0; j < fresh_and_clean[ i ].size(); j++ )
{
fresh_and_clean.erase( fresh_and_clean.begin() + i );
}
}
else
count++;
}
}
return count;
}
/*
*--------------------------------------------------------------*
| print result |
*--------------------------------------------------------------*
*/
inline void Any_power::printer( int C )
{
std::cout << " the number of different objects is: " << C;
}
/*
*--------------------------------------------------------------*
| funzione motore della classe |
*--------------------------------------------------------------*
*/
inline void Any_power::power_engine_start()
{
std::cout << " v "; // test1
for( a = 2; a <= 100; a++ )
{
for( b = 2; b <= 100; b++ )
{
std::cout << " z "; // test2
power_function( a, b, power_container );
}
}
find_egual_item( a, b, power_container );
printer( cleaner( power_container ) );
}
/*
*--------------------------------------------------------------*
| start programm |
*--------------------------------------------------------------*
*/
int main()
{
class Any_power object;
object.power_engine_start();
return 0;
}
|