Assembla home | Assembla project page
 

root/Mathe/C++QuadGleichung/QuadratischeGleichung.cpp

Revision 256, 2.7 kB (checked in by Rappi, 2 years ago)

long double bla blubb geändert mal probieren usw.

+ Funktion zum Check if(ergebnis1==ergebnis2)

+ Rev5
+ Rev6

Line 
1 // QuadratischeGleichung.cpp : Definiert den Einstiegspunkt f� Konsolenanwendung.
2 //
3
4 #include "stdafx.h"
5 #include <iostream>
6 #include <cmath>
7
8
9 using namespace std;
10
11 int main(void)
12 {
13         system("TITLE Quadratische Gleichung in C++");
14         system("COLOR 7");
15         char cDoagain;
16         long double p; //int = ganze Zahl..
17         long double q; //double = 5 Stellen hinter dem Komma (oder insgesamt 6 ?)
18         long double p2; // float = keine Ahnung oO
19         long double wurzel1; // double long =  woher soll ich denn das wissen ?
20         long double wurzel2;
21         long double ergebnis1;
22         long double ergebnis2;
23         // Warnung: Konvertierung Double in Float -> Datenverlust
24         // ignorieren, sofern nicht mehr als 6 Stellen gew� sind
25
26         // TODO: test float
27
28         cout<<"*****************************************\n";
29         cout<<"*        Quadratische Gleichung          *\n";
30         cout<<"*         www.ralph-kokott.de            *\n";
31         cout<<"*          C++ Release Rev 6             *\n";
32         cout<<"*****************************************\n";
33        
34
35 do
36 {       
37         cout<<"\n";
38         cout<<"\n";
39         cout<<"\n";
40         cout<<"Formel:\n";
41         cout<<"x= P/-2 + [Wurzel von:]{(P/2) - Q}\n";
42         cout<<"\n";
43         cout<<"x^2 + Px + Q = 0\n";
44         cout<<"\n";
45         cout<<"Bitte P eingeben :\n";
46         cin>>p;
47         cout<<"Bitte Q eingeben :\n";
48         cin>>q;
49         cout<<"\n";
50         cout<<"\n";
51        
52         // Rechnung:
53         wurzel1 = p*0.5*p*0.5-q;
54         wurzel2 = sqrtf(wurzel1);
55         p2              = p*-0.5;
56         ergebnis1 = p2+wurzel2;
57         ergebnis2 = p2-wurzel2;
58
59         if(wurzel1 < 0) // Leere Menge -> Wurzeln durch eine negative Zahl
60         {
61                 cout<<"L = {  }\n";
62                 cout<<"\n";
63                 cout<<"\n";
64                 cout<<"Nochmal ? (Ja: j,y,Y,+ | Nein: alles andere)\n";
65                 cin>>cDoagain;
66
67         } else {
68        
69        
70
71         cout<<"x = -("<<p<<"/2) + Wurzel(("<<p<<"/2)^2 - "<<q<<")\n";
72     cout<<"x = -("<<p<<"/2) + Wurzel("<<wurzel1<<")\n";
73         cout<<"x = -("<<p<<"/2) + "<<wurzel2<<"\n";
74         cout<<"x = "<<p2<<" + "<<wurzel2<<"\n";
75         cout<<"x = "<<ergebnis1<<"\n";
76        
77         if(ergebnis1!=ergebnis2)
78         {
79
80         cout<<"\n";
81         cout<<"oder\n";
82         cout<<"\n";
83
84         cout<<"x = -("<<p<<"/2) - Wurzel(("<<p<<"/2)^2 - "<<q<<")\n";
85     cout<<"x = -("<<p<<"/2) - Wurzel("<<wurzel1<<")\n";
86         cout<<"x = -("<<p<<"/2) - "<<wurzel2<<"\n";
87         cout<<"x = "<<p2<<" - "<<wurzel2<<"\n";
88         cout<<"x = "<<ergebnis2<<"\n";
89
90         cout<<"\n";
91         cout<<"L = {"<<ergebnis1<<"; "<<ergebnis2<<"}\n";
92         cout<<"\n";
93         cout<<"\n";
94
95         } // Close-Tag f�clause (L�gen gleich)
96         else
97         {
98        
99         cout<<"\n";
100         cout<<"L = {"<<ergebnis1<<"}\n";
101         cout<<"\n";
102                
103         } // Close-Tag f�e-clause (L�gen gleich)
104         cout<<"Nochmal ? (Ja: j,y,Y,+ | Nein: alles andere)\n";
105         cin>>cDoagain;
106
107 //system("PAUSE");
108
109 } // Close-Tag f�clause (leere Menge)
110 }
111 while (cDoagain == 'j' || cDoagain == 'J' || cDoagain == 'y' || cDoagain == 'Y' || cDoagain == '+');
112
113 system("PAUSE");
114 return 0;
115
116 }
Note: See TracBrowser for help on using the browser.