#include <iostream>
#include <ctime>
#include <string>
#include <cmath>
#include <windows.h>
using namespace std;
template < typename T >
void FillArrRand( T *arr, const int size );
template < typename T >
void FillArrManual( T *arr, const int size );
template <typename T >
void PrintArr ( const T *arr, const int size);
template< typename T >
int IndexFirstAbsMin( const T* arr, const int size );
template< typename T >
int IndexLastAbsMin( const T* arr, const int size );
// 5 3 1 1 1
// 2 5 5 5 5
// 1 2 3 4 5 4 3 0
// функция возвращает произведение элементов между указанными индексами массива
template < typename T >
T CalcMult( const T *arr, const int first, const int last );
template <typename T>
void GetValueIn( T& value, const string& mes = "" ) {
bool flag;
cout << mes;
do {
cin >> value;
flag = true;
if ( !cin ) {
flag = false;
cin.clear();
}
string input;
getline( cin, input );
if ( input.find_first_not_of( " " ) != string::npos )
flag = false;
if ( !flag )
cout << "Неверно введено число! Повторите ввод: ";
} while( !flag );
}
int main() {
SetConsoleCP( 1251 );
SetConsoleOutputCP( 1251 );
srand( time( 0 ) );
int val;
GetValueIn( val, "Введите целое число: " );
cout << val << endl;
double dval;
GetValueIn( dval, "Введите вещественное число: " );
cout << dval << endl;
return 0;
}
template < typename T >
void FillArrRand( T *arr, const int size ) {
for (int i = 0; i < size; ++i )
arr[i] = rand() % 100 - 50 + ( rand() % 10 ) / 10.0;
}
template < typename T >
void FillArrManual( T *arr, const int size ) { // a[0]:
// a[1]:
for ( int i = 0; i < size; ++i ) {
cout << "a[" << i << "]: ";
GetValueIn( arr[i] );
}
}
template <typename T >
void PrintArr ( const T *arr, const int size) {
for( int i = 0; i < size; ++i )
cout << arr[i] << " ";
}
template< typename T >
int IndexFirstAbsMin( const T* arr, const int size ){
int index = 0;
for( int i = 1; i < size; ++i )
if( fabs( arr[ i ] ) < fabs( arr[ index ] ) )
index = i;
}
template< typename T >
int IndexLastAbsMin( const T* arr, const int size ){
int index = 0;
for( int i = 1; i < size; ++i )
if( fabs( arr[ i ] ) <= fabs( arr[ index ] ) )
index = i;
}
template< typename T >
int IndexFirstAbsMax( const T* arr, const int size ){
int index = 0;
for( int i = 1; i < size; ++i )
if( fabs( arr[ i ] ) > fabs( arr[ index ] ) )
index = i;
}
template < typename T >
int IndexLastAbsMax ( const T* arr, const int size) {
int index = 0;
for ( int i = 1; i < size; ++i )
if ( fabs( arr[ i ] ) >= fabs( arr[ index ] ) )
index = i;
}
template < typename T >
T CalcMult( const T *arr, const int first, const int last ) {
T mult = 1;
for (int i = first + 1; i < last; ++i )
mult *= arr[ i ];
return mult;
}