Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- // Khai bao cac bien, ham can su dung
- double a{ 0 };
- double b{ 0 };
- double c{ 0 };
- double delta{ 0 };
- void loop();
- int main();
- string USERNAME("admin");
- string PASSWORD("123456@abc");
- string username;
- string password;
- // Ham tinh nghiem
- int nghiem()
- {
- double d{ 0 };
- double nghiem1{ 0 };
- double nghiem2{ 0 };
- d = sqrt(delta);
- nghiem1 = ((-b + d) / (2 * a));
- nghiem2 = ((-b - d) / (2 * a));
- if (nghiem1 == nghiem2)
- {
- cout << "Nghiem kep la:" << nghiem2 << endl;
- loop();
- }
- else
- {
- cout << "Nghiem 1 la:" << nghiem1 << endl;
- cout << "Nghiem 2 la:" << nghiem2 << endl;
- loop();
- }
- return 0;
- }
- // Ham tiep tuc hoac dung chuong trinh
- void loop()
- {
- int check{ 0 };
- cout << "Tiep tuc nhap 1. Thoat chuong trinh nhap 0: ";
- cin >> check;
- switch (check)
- {
- case 1:
- main();
- break;
- case 0:
- cout << "Dang Thoat \n";
- exit(0);
- break;
- default:
- cout << "Nhap sai \n";
- loop();
- break;
- /* int check{ 0 };
- cout << "Tiep tuc nhap 1. Thoat chuong trinh nhap 0: ";
- cin >> check;
- if (check == 1)
- {
- main();
- }
- else if (check == 0)
- {
- cout << "Dang Thoat \n";
- exit(0);
- }
- else
- {
- cout << "Nhap Sai \n";
- loop(); */
- }
- }
- // Ham Login
- int login()
- {
- /* do
- {
- system("cls");
- cout << "Nhap Username: ";
- getline(cin, username);
- cout << "Nhap Password: ";
- getline(cin, password);
- while (username != USERNAME || password != PASSWORD);
- } */
- return 0;
- }
- // Chuong trinh chinh
- int main()
- {
- // Login
- // Intro
- cout << "Chuong trinh giai phuong trinh bac hai" << endl;
- cout << "Phuong trinh bac 2 co dang ax^2+bx+c" << endl;
- // Nhap he so
- cout << "Nhap a:";
- cin >> a;
- cout << "Nhap b:";
- cin >> b;
- cout << "Nhap c:";
- cin >> c;
- cout << "Bo so a b c cua ban la " << "a=" << a << ";" << "b=" << b << ";" << "c=" << c << endl;
- // Tinh Delta
- delta = (b * b) - (4 * a * c);
- cout << "Delta tinh duoc la " << delta << endl;
- if (delta >= 0)
- {
- cout << "Phuong trinh co nghiem\n";
- nghiem();
- }
- else
- cout << "Phuong trinh vo nghiem\n";
- loop();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement