SHARE
TWEET

seberm

seberm Oct 15th, 2008 28 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***************************************************************************
  2.  *   Copyright (C) 2008 by Šabart Otto                                     *
  3.  *   seberm@gmail.com                                                      *
  4.  *                                                                         *
  5.  *   This program is free software; you can redistribute it and/or modify  *
  6.  *   it under the terms of the GNU General Public License as published by  *
  7.  *   the Free Software Foundation; either version 2 of the License, or     *
  8.  *   (at your option) any later version.                                   *
  9.  *                                                                         *
  10.  *   This program is distributed in the hope that it will be useful,       *
  11.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  12.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  13.  *   GNU General Public License for more details.                          *
  14.  *                                                                         *
  15.  *   You should have received a copy of the GNU General Public License     *
  16.  *   along with this program; if not, write to the                         *
  17.  *   Free Software Foundation, Inc.,                                       *
  18.  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  19.  ***************************************************************************/
  20.  
  21.  
  22. //...> quadratic.cpp
  23.  
  24. #ifdef HAVE_CONFIG_H
  25. #include <config.h>
  26. #endif
  27.  
  28. #include <iostream>
  29. #include <cmath>
  30. #include "quadratic_class.h"
  31.  
  32. using namespace std;
  33.  
  34. //...Konstruktor
  35. Quadratic::Quadratic () {
  36. //...Zatim nepotrebna deklarace
  37. }
  38.  
  39.  
  40. //...Welcome message
  41. void Quadratic::welcome () {
  42.   cout << "Vitejte v programu na pocitani kvadratickych rovnic\n"
  43.        << "---------------------------------------------------\n";
  44. }
  45.  
  46.  
  47. //...Discriminant
  48. void Quadratic::f_disc (double* f_a, double* f_b, double* f_c) {
  49.   this->discriminant = ((*f_b) * (*f_b)) - (4 * (*f_a) * (*f_c));
  50.   cout << this->discriminant;
  51. }
  52.  
  53.  
  54. //...Zobrazi vysledek a pocet reseni rovnice
  55. void Quadratic::result (double* f_a, double* f_b, double* f_c) {
  56.   this->f_disc (f_a, f_b, f_c);
  57.  
  58.  
  59.   if ((this->discriminant == 0) && (*f_a && *f_b && *f_c != 0)) { //...opravittt!!!!!
  60.     cout << "Rovnice ma jedno reseni.\n";
  61.     cout << "Vysledek je: " << (-*f_b) / (2 * (*f_a)) << "\n";
  62.   }
  63.  
  64.   if (this->discriminant > 0) {
  65.     cout << "Rovnice ma dve reseni.\n";
  66.     cout << "Prvni vysledek je: " << ((-*f_b) - (sqrt(this->discriminant))) / (2 * (*f_a)) << "\nDruhy vysledek je: " << ((-*f_b) + (sqrt(this->discriminant))) / (2 * (*f_a)) << "\n";
  67.   }
  68.  
  69.   if (this->discriminant < 0)
  70.     cout << "Rovnice nema reseni!\n";
  71.  
  72.  
  73.  
  74. }
  75.  
  76.  
  77. //...Destruktor
  78. Quadratic::~Quadratic () {
  79. //...Zatim nepotrebna deklarace
  80. }
  81.  
  82.  
  83. //...The Main Function...//
  84. //## vyuzit predani parametru pri startu programu.....
  85. int main(int argc, char *argv[])
  86. {
  87.   double a = 0.0, b = 0.0, c = 0.0;
  88. char vstup;
  89.   //...The instance of class Quadratic
  90.   Quadratic q_rovnice;
  91.  
  92.   //...User welcome
  93.   q_rovnice.welcome ();
  94.  
  95.   do {
  96.     cout << "\nZadejte hodnotu a:\n";
  97.     cin >> a;
  98.     cout << "Zadejte hodnotu b:\n";
  99.     cin >> b;
  100.     cout << "Zadejte hodnotu c:\n";
  101.     cin >> c;
  102.  
  103.     //...Show the quadratic roots
  104.     q_rovnice.result (&a, &b, &c);
  105.  
  106.     cout << "\nChcete pocitat dalsi rovnici?\n";
  107.     cout << "'y' pro 'Ano' ........ 'n' pro 'Ne': ";
  108.     cin  >> vstup;
  109.     cout << "\n";
  110.   }
  111.   while (vstup == 'y' || vstup == 'Y');
  112.  
  113.   return EXIT_SUCCESS;
  114. }
RAW Paste Data
Want to get better at C++?
Learn to code C++ in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top