Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string>
- #include <cmath>
- #include <algorithm>
- #include <stdlib.h>
- #include <iostream>
- #include <windows.h>
- using namespace std;
- const string digits = "0123456789ABCDEFGHIJKLMNOPQRASUVWXYZ";
- void validation(int base) {
- cout << "Error: исходное число ¤вл¤етс¤ некорректной записью дл¤ системы с основанием " << base << ".\n¬ ";
- cout << base << "-ой системе допустимы только следующие символы: ";
- for (int i = 0; i < base; i++) {
- cout << digits[i] << " ";
- }
- }
- string DecToAny(int number, int to_final) {
- string result;
- cout << endl << "ѕереводим целую часть " << number << " в " << to_final << "-ую систему последовательным делением на " << to_final << ":" << endl;
- do {
- cout << number << " / " << to_final << " = " << number / to_final << ", остаток:" << digits[number % to_final] << endl;
- result.push_back(digits[number % to_final]);
- number /= to_final;
- } while (number > 0);
- reverse(result.begin(), result.end());
- return result;
- }
- void translation() {
- string number;
- cout << "Number: ";
- getline(cin, number);
- for (int i = 0; i < number.size(); i++) {
- if ((int)number[i] < 0) {
- cout << "¬вод произведен на русской раскладке клавиатуры.\nƒопустимы только числа и буквы англиского алфавита:" << endl;
- cout << digits;
- return;
- }
- }
- if (number.find("-") != -1) {
- cout << "Error: исходное число ¤вл¤етс¤ отрицательным";
- return;
- }
- int base;
- cout << "in ";
- cin >> base;
- for (int i = 0; i < number.size(); i++) {
- if (base > 10) {
- if (!(number[i] >= 'A' && number[i] <= base - 10 + 'A' || isdigit(number[i]) || number[i] == '.')) {
- validation(base);
- return;
- }
- }
- else {
- if (!(number[i] - '0' >= 0 && number[i] - '0' < base || number[i] == '.')) {
- validation(base);
- return;
- }
- }
- }
- if ((base < 2 || base > 36)) {
- cout << "Error: основание исходной системы должны быть в диапазоне от 2 до 36.";
- return;
- }
- int to_final;
- cout << "to ";
- cin >> to_final;
- if ((to_final < 2 || to_final > 36)) {
- cout << "Error: основание конечной системы должны быть в диапазоне от 2 до 36.";
- return;
- }
- int digit;
- if (base == 10) {
- digit = atoi(number.c_str());
- cout << endl << "Result: " << DecToAny(digit, to_final);
- return;
- }
- }
- int main() {
- //setlocale(LC_ALL, "Russian");
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- translation();
- cout << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement