Advertisement
anhkiet2507

Giải Phương Trình Bậc II

Sep 7th, 2018
38,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. // Khai bao cac bien, ham can su dung
  5. double a{ 0 };
  6. double b{ 0 };
  7. double c{ 0 };
  8. double delta{ 0 };
  9. void loop();
  10. int main();
  11. string USERNAME("admin");
  12. string PASSWORD("123456@abc");
  13. string username;
  14. string password;
  15. // Ham tinh nghiem
  16. int nghiem()
  17. {
  18.     double d{ 0 };
  19.     double nghiem1{ 0 };
  20.     double nghiem2{ 0 };
  21.     d = sqrt(delta);
  22.     nghiem1 = ((-b + d) / (2 * a));
  23.     nghiem2 = ((-b - d) / (2 * a));
  24.     if (nghiem1 == nghiem2)
  25.     {
  26.         cout << "Nghiem kep la:" << nghiem2 << endl;
  27.         loop();
  28.     }
  29.     else
  30.     {
  31.         cout << "Nghiem 1 la:" << nghiem1 << endl;
  32.         cout << "Nghiem 2 la:" << nghiem2 << endl;
  33.         loop();
  34.     }
  35.     return 0;
  36. }
  37. // Ham tiep tuc hoac dung chuong trinh
  38. void loop()
  39. {
  40.     int check{ 0 };
  41.     cout << "Tiep tuc nhap 1. Thoat chuong trinh nhap 0: ";
  42.     cin >> check;
  43.     switch (check)
  44.     {
  45.     case 1:
  46.         main();
  47.         break;
  48.     case 0:
  49.         cout << "Dang Thoat \n";
  50.         exit(0);
  51.         break;
  52.     default:
  53.         cout << "Nhap sai \n";
  54.         loop();
  55.         break;
  56.  
  57.     /* int check{ 0 };
  58.     cout << "Tiep tuc nhap 1. Thoat chuong trinh nhap 0: ";
  59.     cin >> check;
  60.     if (check == 1)
  61.     {
  62.         main();
  63.     }
  64.     else if (check == 0)
  65.     {
  66.         cout << "Dang Thoat \n";
  67.         exit(0);
  68.     }
  69.     else
  70.     {
  71.         cout << "Nhap Sai \n";
  72.         loop(); */
  73.     }
  74. }
  75. // Ham Login
  76. int login()
  77. {
  78. /* do
  79. {
  80. system("cls");
  81.  
  82. cout << "Nhap Username: ";
  83. getline(cin, username);
  84.  
  85. cout << "Nhap Password: ";
  86. getline(cin, password);
  87. while (username != USERNAME || password != PASSWORD);
  88. } */
  89.     return 0;
  90. }
  91. // Chuong trinh chinh
  92. int main()
  93. {
  94.     // Login
  95.    
  96.     // Intro
  97.     cout << "Chuong trinh giai phuong trinh bac hai" << endl;
  98.     cout << "Phuong trinh bac 2 co dang ax^2+bx+c" << endl;
  99.     // Nhap he so
  100.     cout << "Nhap a:";
  101.     cin >> a;
  102.     cout << "Nhap b:";
  103.     cin >> b;
  104.     cout << "Nhap c:";
  105.     cin >> c;
  106.     cout << "Bo so a b c cua ban la " << "a=" << a << ";" << "b=" << b << ";" << "c=" << c << endl;
  107.     // Tinh Delta
  108.     delta = (b * b) - (4 * a * c);
  109.     cout << "Delta tinh duoc la " << delta << endl;
  110.     if (delta >= 0)
  111.     {
  112.         cout << "Phuong trinh co nghiem\n";
  113.         nghiem();
  114.     }
  115.     else
  116.         cout << "Phuong trinh vo nghiem\n";
  117.     loop();
  118.     system("pause");
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement