#include <iostream>
#include <string>
double power(double n, int p);
char power(char n, int p);
int power(int n, int p);
long power(long n, int p);
float power(float n, int p);
using namespace std;
enum Chose{int_, double_, float_, long_, char_};
int main()
{
Chose chose;
int chose_;
cout << "Выберите действие: ";
cin >> chose_;
switch(chose_)
{
case 1:
chose = int_;
break;
case 2:
chose = double_;
case 3:
chose = float_;
case 4:
chose = long_;
case 5:
chose = char_;
}
switch(chose)
{
case int_:
{
int power_;
int number;
cout << "Введите число: ";
cin >> number;
cout << "Введите степень: ";
cin >> power_;
int a = power(number, power_);
cout << a;
break;
}
case double_:
{
double nu;
int po;
cout << "Введите число: ";
cin >> nu;
cout << "Введите степень: ";
cin >> po;
double a = power(nu, po);
cout << a;
break;
}
case float_:
{
int power_;
float number;
cout << "Введите число: ";
cin >> number;
cout << "Введите степень: ";
cin >> power_;
float a = power(number, power_);
cout << a;
break;
}
case char_:
{
int power_;
char number;
cout << "Введите число: ";
cin >> number;
cout << "Введите степень: ";
cin >> power_;
char a = power(number, power_);
cout << a;
break;
}
case long_:
{
int power_;
long number;
cout << "Введите число: ";
cin >> number;
cout << "Введите степень: ";
cin >> power_;
char a = power(number, power_);
cout << a;
break;
}
}
}
//////////////////
int power(int n, int p)
{
int result = 1;
for(int i = 0; i < p; i++)
{
result = result * n;
}
return result;
}
//////////////////
long power(long n, int p)
{
long result = 1;
for(int i = 0; i < p; i++)
{
result *= n;
}
return result;
}
//////////////////
double power(double n, int p)
{
double result = 1;
for(int i = 0; i < p; i++)
{
result *= n;
}
return result;
}
//////////////////
char power(char n, int p)
{
char result = 1;
for(int i = 0; i < p; i++)
{
result *= n;
}
return result;
}
//////////////////
float power(float n, int p)
{
float result = 1;
for(int i = 0; i < p; i++)
{
result *= n;
}
return result;
}
//////////////////
case 1:
chose = int_;
break;
case 2:
chose = double_;
break;
case 3:
chose = float_;
break;
case 4:
chose = long_;
break;
case 5:
chose = char_;
break;
#include <iostream>
#include <string>
using namespace std;
enum Chose { int_, double_, float_, long_, char_ };
template<typename Tn, typename Tp>
Tn Power(Tn n, Tp p) {
Tn result = 1;
for (int i = 0; i < p; i++)
{
result = result * n;
}
return result;
}
template<typename Tn, typename Tp>
void UserInput() {
Tn power = 1;
Tp number = 1;
cout << "Введите число: ";
cin >> number;
cout << "Введите степень: ";
cin >> power;
Tn result = Power(number, power);
cout << "Result: " << result << endl;
}
int main()
{
setlocale(LC_ALL, "russian");
Chose chose;
int chose_;
cout << "Выберите действие: ";
cin >> chose_;
switch (chose_)
{
case 1:
UserInput<int, int>();
break;
case 2:
UserInput<double, int>();
break;
case 3:
UserInput<int, float>();
break;
case 4:
UserInput<int, long>();
break;
case 5:
UserInput<double, char>();
break;
}
system("pause");
}
#include <iostream>
#include <string>
template<typename T>
T power(T n, T p)
{
T result = 1;
for (T i = 0; i < p; i++)
{
result = result * n;
}
return result;
}
template<typename T>
T readPow() {
T power_;
T number;
std::cout << "Введите число: ";
std::cin >> number;
std::cout << "Введите степень: ";
std::cin >> power_;
return power(number, power_);
}
int main()
{
setlocale(LC_ALL, "Russian");
int chose;
std::cout << "Выберите действие: ";
std::cin >> chose;
switch (chose)
{
case 1:
std::cout << readPow<int>() << std::endl;
break;
case 2:
std::cout << readPow<double>() << std::endl;
break;
case 3:
std::cout << readPow<float>() << std::endl;
break;
case 4:
std::cout << readPow<long>() << std::endl;
break;
}
}