Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "iostream"
- #include "fstream"
- #include "string"
- using namespace std;
- bool compareTwoLongNumbers(string first, char sign, string second);
- void input(string &first_number, char &sign, string &second_number);
- void output(bool result);
- int _tmain(int argc, _TCHAR* argv[])
- {
- string first_number, second_number;
- char sign;
- input(first_number, sign, second_number);
- output(compareTwoLongNumbers(first_number, sign, second_number));
- system("pause");
- }
- bool compareTwoLongNumbers(string first_number, char sign, string second_number){
- if (first_number == second_number){
- if (sign == '=') { return true; }
- return false;
- }
- else {
- int flag;
- if (first_number.length() > second_number.length()){ flag = true; }
- else if (first_number.length() < second_number.length()) { flag = false; }
- else {
- for (int i = 0; i < (int)first_number.length(); i++){
- if (first_number[i] > second_number[i]){
- flag = true;
- break;
- }
- else if (first_number[i] < second_number[i]){
- flag = false;
- break;
- }
- }
- }
- if ((flag && sign == '>') || (!flag && sign == '<')){ return true; }
- return false;
- }
- };
- void input(string &first_number, char &sign, string &second_number){
- string filename;
- cin >> filename;
- ifstream input(filename);
- ofstream errors("errors.txt");
- if (!input){
- errors << "Can't open the file" << endl;
- cout << "Can't open the file" << endl;
- exit(0);
- }
- input >> first_number >> sign >> second_number;
- input.close();
- }
- void output(bool result){
- ofstream output("output.txt");
- if (result) {
- output << "The expression is true." << endl;
- }
- else {
- output << "The expression is false." << endl;
- }
- output.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement