prac48.cpp

来自「this program is good for C++ learner」· C++ 代码 · 共 70 行

CPP
70
字号
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>
#include<alloc.h>
class R1{
  public:
   float a,b,c,del;
      //int *m;
   R1(){
   a=c=1;
   b=2;
   }

   R1(float a1){
   a=a1;
   b=2;
   c=1;
   }

  R1(float a1,float b1){
   a=a1;
   b=b1;
   c=1;
   }

  R1(float a1,float b1,float c1){
   a=a1;
   b=b1;
   c=c1;
   }

   float delta(float a,float b,float c){
     del= (pow(b,2)-(4*a*c));
   }


};

class EQ:public R1{

 public:
   float x1,x2;

   void read(){
     cin>>a>>b>>c;
   }

   EQ():R1(){}
   EQ(float a):R1(a){}
   EQ(float a,float b):R1(a,b){}
   EQ(float a,float b,float c):R1(a,b,c){}

   void root(){
     delta( a,b,c);
     if (del>=0){
       x1= ((-b)+sqrt(del))/(2*a);
       x2= ((-b)-sqrt(del))/(2*a);
       cout<<"x1 = "<<x1<<"\n"<<"x2 = "<<x2;
     }
     if (del<0)
       cout<<"no real roots!";
   }
};
void main(){
  EQ eq;
  eq.read();
  eq.root();
  getch();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?