Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <Windows.h>
- #include <fstream>
- using namespace std;
- void typing();
- void reading();
- double chkdsk();
- int choice;
- int n;
- double x;
- double y;
- double a, b, h;
- double greater();
- void main()
- {
- next:
- bool
- {
- cout << endl
- << "1. Input data from keyboard and calculate result\n"
- << "2. Input data from file and calculate result\n"
- << "3. Save result to file\n"
- << "4. Help!\n"
- << "5. Exit program\n"
- << "\n" << "Make your choice and press 'Enter': "
- };
- cin >> choice;
- switch (choice)
- {
- case 1: /* A line to input data from keyboard and calculate result */
- {
- typing();
- chkdsk();
- goto next;
- }
- case 2: /* Input data from file and calculate result */
- {
- reading();
- chkdsk();
- goto next;
- }
- case 3: /* That what lets you to output your data to a certain directory */
- {
- ofstream file("output.txt", ios::app);
- file << "x = " << x << "\n" << "y = " << y << endl;
- cout << "Writing this to a file..." << endl;
- Sleep(1000);
- file.close();
- }
- goto next;
- case 4: /* Just some additional information – FAQ and Credits */
- int choice_2;
- bool
- {
- cout << "\n" << "1. FAQ\n" << "2. Author credits\n"
- };
- cout << "\n";
- cin >> choice_2;
- cout << "\n";
- switch (choice_2)
- {
- case 1: /* FAQ */
- cout << "\t\t\tFAQ for the main menu\n"
- << "1. To make input from keyboard and calculate your result, please, press '1'. \n"
- << "2. To make input from file and calculate the result, press '2'. \n"
- << "3. To save the result into file, press '3'. \n"
- << "4. To see some additional information and author credits, press '4'. In the following menu, choose between '1' and '2'. \n"
- << "5. Press '5' if you want to exit the program. \n";
- cout << endl;
- system("pause");
- goto next;
- case 2: /* Author Credits */
- cout << "The program was written and compiled by Maidebura D., group CS-36zh, 2016.\n";
- cout << endl;
- system("pause");
- goto next;
- }
- case 5: /* Exit from program */
- {
- cout << "\nE"; Sleep(100); cout << "n"; Sleep(100); cout << "d"; Sleep(100);
- cout << " o"; Sleep(100); cout << "f"; Sleep(100);
- cout << " p"; Sleep(100); cout << "r"; Sleep(200); cout << "o"; Sleep(200); cout << "g"; Sleep(200); cout << "r"; Sleep(200); cout << "a"; Sleep(200); cout << "m";
- Sleep(500);
- cout << ".";
- Sleep(500);
- cout << ".";
- Sleep(500);
- cout << ".";
- break;
- }
- default:
- cout << "\nNot a valid choice \n" << "Choose again \n";
- goto next;
- system("pause");
- }
- }
- double chkdsk()
- {
- try
- {
- if (n < 4)
- {
- throw "error";
- }
- else
- {
- for (x = a; x <= b; x = x + h)
- {
- if (x >= 0)
- {
- y = 0;
- greater();
- for (int i = 0; i <= n - 1; i++)
- {
- double z = 1;
- for (int j = 0; j <= n - 1; j++)
- {
- z = z*(x + i + j*j);
- }
- y = y + z;
- }
- }
- if (x < 0)
- {
- y = 1;
- for (int j = 2; j <= n - 2; j++)
- {
- y = y*(j + 1);
- }
- }
- cout << "x = " << x << endl;
- cout << "y = " << y << endl;
- }
- }
- cout << endl;
- system("pause");
- return (0);
- }
- catch (double)
- {
- string c = "the value of n must be greater than or equal to 4\n";
- throw c;
- }
- return 0;
- }
- double greater()
- {
- try
- {
- if (a > b)
- throw a;
- }
- catch (double)
- {
- cout << "\nA must be greater than B\n";
- return 0;
- }
- }
- void reading()
- {
- ifstream file("input.txt", ios::app);
- file >> a >> b >> h >> n;
- }
- void typing()
- {
- cout << "Type a, b, h, n: " << endl;
- cin >> a >> b >> h >> n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement