Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************
- * Copyright (C) 2008 by Šabart Otto *
- * seberm@gmail.com *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
- ***************************************************************************/
- //...> quadratic.cpp
- #ifdef HAVE_CONFIG_H
- #include <config.h>
- #endif
- #include <iostream>
- #include <cmath>
- #include "quadratic_class.h"
- using namespace std;
- //...Konstruktor
- Quadratic::Quadratic () {
- //...Zatim nepotrebna deklarace
- }
- //...Welcome message
- void Quadratic::welcome () {
- cout << "Vitejte v programu na pocitani kvadratickych rovnic\n"
- << "---------------------------------------------------\n";
- }
- //...Discriminant
- void Quadratic::f_disc (double* f_a, double* f_b, double* f_c) {
- this->discriminant = ((*f_b) * (*f_b)) - (4 * (*f_a) * (*f_c));
- cout << this->discriminant;
- }
- //...Zobrazi vysledek a pocet reseni rovnice
- void Quadratic::result (double* f_a, double* f_b, double* f_c) {
- this->f_disc (f_a, f_b, f_c);
- if ((this->discriminant == 0) && (*f_a && *f_b && *f_c != 0)) { //...opravittt!!!!!
- cout << "Rovnice ma jedno reseni.\n";
- cout << "Vysledek je: " << (-*f_b) / (2 * (*f_a)) << "\n";
- }
- if (this->discriminant > 0) {
- cout << "Rovnice ma dve reseni.\n";
- cout << "Prvni vysledek je: " << ((-*f_b) - (sqrt(this->discriminant))) / (2 * (*f_a)) << "\nDruhy vysledek je: " << ((-*f_b) + (sqrt(this->discriminant))) / (2 * (*f_a)) << "\n";
- }
- if (this->discriminant < 0)
- cout << "Rovnice nema reseni!\n";
- }
- //...Destruktor
- Quadratic::~Quadratic () {
- //...Zatim nepotrebna deklarace
- }
- //...The Main Function...//
- //## vyuzit predani parametru pri startu programu.....
- int main(int argc, char *argv[])
- {
- double a = 0.0, b = 0.0, c = 0.0;
- char vstup;
- //...The instance of class Quadratic
- Quadratic q_rovnice;
- //...User welcome
- q_rovnice.welcome ();
- do {
- cout << "\nZadejte hodnotu a:\n";
- cin >> a;
- cout << "Zadejte hodnotu b:\n";
- cin >> b;
- cout << "Zadejte hodnotu c:\n";
- cin >> c;
- //...Show the quadratic roots
- q_rovnice.result (&a, &b, &c);
- cout << "\nChcete pocitat dalsi rovnici?\n";
- cout << "'y' pro 'Ano' ........ 'n' pro 'Ne': ";
- cin >> vstup;
- cout << "\n";
- }
- while (vstup == 'y' || vstup == 'Y');
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement