Skip to content

Instantly share code, notes, and snippets.

@gilapo
Created July 12, 2021 17:26
Show Gist options
  • Save gilapo/e6e0772f9eb86f46d42a9494f04b9023 to your computer and use it in GitHub Desktop.
Save gilapo/e6e0772f9eb86f46d42a9494f04b9023 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
class perskuadrat{
friend ostream& operator<<(ostream&, perskuadrat&);
friend istream& operator>>(istream&, perskuadrat&);
private:
int a, b, c;
float x1, x2, D;
public:
}k;
istream& operator>>(istream&nilai, perskuadrat&kuadrat){
cout<<"Masukkan nilai a = "; nilai>>kuadrat.a;
cout<<"\nMasukkan nilai b = "; nilai>>kuadrat.b;
cout<<"\nMasukkan nilai c = "; nilai>>kuadrat.c;
system("CLS");
return nilai;
}
ostream& operator<<(ostream&nilai, perskuadrat&persamaan){
persamaan.D=((persamaan.b*persamaan.b)-4*(persamaan.a*persamaan.c));
if (persamaan.a==0){
nilai<<"Bukan Persamaan Kuadrat";
}
else if (persamaan.D>0){
persamaan.x1=((-persamaan.b)+(sqrt(persamaan.D)))/(2*persamaan.a);
persamaan.x2=((-persamaan.b)-sqrt(persamaan.D))/(2*persamaan.a);
nilai<<"persamaan kuadrat ("<<persamaan.a<<"x^2 + "<<persamaan.b<<"x +"<<persamaan.c<<" mempunyai akar-akar yang berbeda yaitu : \n\n";
nilai<<"X1 = "<<persamaan.x1<<endl;
nilai<<"X2 = "<<persamaan.x2<<endl;
}
else if (persamaan.D==0){
persamaan.x1=(-persamaan.b)/(2*persamaan.a);
persamaan.x2=persamaan.x1;
nilai<<"persamaan kuadrat "<<persamaan.a<<"x^2 + "<<persamaan.b<<"x +"<<persamaan.c<<" mempunyai akar-akar kembar yaitu : \n\n";
nilai<<"X1 = "<<persamaan.x1<<endl;
nilai<<"X2 = "<<persamaan.x2<<endl;
}
else { nilai<<"Akar Imaginer";
}
}
int main() {
system("color f1");
cout<<"=========================================\n";
cout<<"| PROGRAM PERSAMAAN KUADRAT |\n";
cout<<"=========================================\n\n";
cin>>k;
cout<<k;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment