Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Лабораторная работа для Гайделя №1 (допзадание. Рассчет веса на других планетах)
- #include <iostream>
- using namespace std;
- // Продолжение работы программы
- bool Prod()
- {
- cout << "Continue Y/N" << endl;
- char yn;
- cin >> yn;
- cin.clear();
- if (yn == 'Y' && cin.get() == '\n') return true;
- else if (yn == 'N' && cin.get() == '\n') return false;
- else
- {
- while (cin.get() != '\n');
- cout << "Error. Try again" << endl;
- Prod();
- }
- }
- // Ввод первой планеты
- char inputFirstPlanet()
- {
- cout << "Earth(E)" << endl << "Venus(V)" << endl << "Mars(M)" << endl;
- char firstPlanet;
- cin >> firstPlanet;
- cin.clear();
- if (firstPlanet == 'E' || firstPlanet == 'V' || firstPlanet == 'M') return firstPlanet;
- else
- {
- while (cin.get() != '\n');
- cout << "Error. Try again" << endl;
- return inputFirstPlanet();
- }
- }
- // Ввод второй планеты
- char inputSecondPlanet()
- {
- cout << "Earth(E)" << endl << "Venus(V)" << endl << "Mars(M)" << endl;
- char secondPlanet;
- cin >> secondPlanet;
- cin.clear();
- if (secondPlanet == 'E' || secondPlanet == 'V' || secondPlanet == 'M') return secondPlanet;
- else
- {
- while (cin.get() != '\n');
- cout << "Error. Try again" << endl;
- return inputSecondPlanet();
- }
- }
- // Получение отношения масс планет
- double getCoefficient(char firstPlanet, char secondPlanet)
- {
- if (firstPlanet == 'E' && secondPlanet == 'V') return 0.82;
- if (firstPlanet == 'E' && secondPlanet == 'M') return 1.1;
- if (firstPlanet == 'V' && secondPlanet == 'E') return 1.22;
- if (firstPlanet == 'V' && secondPlanet == 'M') return 1.34;
- if (firstPlanet == 'M' && secondPlanet == 'E') return 0.9;
- if (firstPlanet == 'M' && secondPlanet == 'V') return 0.75;
- if (firstPlanet == secondPlanet) {
- cout << "Error. First planet = second planet" << endl;
- return Prod();
- }
- }
- // Получение веса на второй планете
- double getSecondWeight(double coefficient, double firstWeight) {
- return coefficient * firstWeight;
- }
- // Получение веса на первой планете
- double inputFirstWeight() {
- double firstWeight;
- cin >> firstWeight;
- cin.clear();
- if (firstWeight > 0 && cin.get() == '\n') return firstWeight;
- else {
- while (cin.get() != '\n');
- cout << "Error. Try again" << endl;
- inputFirstWeight();
- }
- }
- int main()
- {
- char firstPlanet;
- char secondPlanet;
- double coefficient;
- double firstWeight;
- double secondWeight;
- do {
- cout << "select a first planet" << endl;
- firstPlanet = inputFirstPlanet();
- cout << "first weight = ";
- firstWeight = inputFirstWeight();
- cout << "select a second planet" << endl;
- secondPlanet = inputSecondPlanet();
- coefficient = getCoefficient(firstPlanet, secondPlanet);
- secondWeight = getSecondWeight(coefficient, firstWeight);
- cout << "second weight = " << secondWeight << endl;
- } while (Prod());
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement