lesson_68

This commit is contained in:
Alexander Zhirov 2021-09-14 00:23:08 +03:00
parent e280a4648d
commit 9e5d745921
1 changed files with 104 additions and 0 deletions

104
lesson_68/main.cpp Normal file
View File

@ -0,0 +1,104 @@
/*
* main.cpp
*
* Created on: 13 сент. 2021 г.
* Author: alexander
*/
#include <iostream>
#include <string>
int calculate(int a, int b, char c)
{
switch (c)
{
case ('+'):
return a + b;
case ('-'):
return a - b;
case ('*'):
return a * b;
case ('/'):
return a / b;
case ('%'):
return a % b;
default:
exit(0);
}
}
void exercise_1()
{
std::cout << "Введите первое число: ";
int a;
std::cin >> a;
std::cout << "Введите второе число: ";
int b;
std::cin >> b;
std::cout << "Введите символ операции: ";
char c;
std::cin >> c;
std::cout << a << ' ' << c << ' ' << b << " = " << calculate(a, b, c)
<< std::endl;
}
enum class Animal
{
PIG, CHICKEN, GOAT, CAT, DOG, OSTRICH
};
std::string getAnimalName(Animal &a)
{
switch (a)
{
case Animal::PIG:
return "pig";
case Animal::CHICKEN:
return "chicken";
case Animal::GOAT:
return "goat";
case Animal::CAT:
return "cat";
case Animal::DOG:
return "dog";
case Animal::OSTRICH:
return "ostrich";
default:
exit(0);
}
}
int printNumberOfLegs(Animal &a)
{
switch (a)
{
case Animal::PIG:
case Animal::CAT:
case Animal::DOG:
case Animal::GOAT:
return 4;
case Animal::CHICKEN:
case Animal::OSTRICH:
return 2;
default:
exit(0);
}
}
void exercise_2()
{
Animal cat(Animal::CAT);
Animal chicken(Animal::CHICKEN);
std::cout << "A " << getAnimalName(cat) << " has " << printNumberOfLegs(cat) << " legs." << std::endl;
std::cout << "A " << getAnimalName(chicken) << " has " << printNumberOfLegs(chicken) << " legs." << std::endl;
}
int main()
{
exercise_1();
exercise_2();
return 0;
}