0% found this document useful (0 votes)
23 views5 pages

Oop 2

The document discusses solving quadratic equations by defining a class to represent equations and functions to calculate and display the roots. It also discusses matrix addition by defining a class to represent matrices and functions to set, get and add matrices.

Uploaded by

esha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

Oop 2

The document discusses solving quadratic equations by defining a class to represent equations and functions to calculate and display the roots. It also discusses matrix addition by defining a class to represent matrices and functions to set, get and add matrices.

Uploaded by

esha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <iostream>

#include <math.h>

using namespace std;

class Equation{

private:

double a,b,c;

public:

Equation() // constructor

{cout<<"\t\t---------------------\n";

cout<<"\t\t Enter Values"<<'\n';

cout<<"\t\t---------------------\n";

cout<<"\t\ta = ";

cin>>a;

cout<<"\t\tb = ";

cin>>b;

cout<<"\t\tc = ";

cin>>c; }

friend void func(Equation); //friend function to determine proots and nroots

friend void display(Equation);//friend function to display proots and nroots

};

void func(Equation n)

{ double disc,proot,nroot;

disc=(n.b*n.b)-(4*n.a*n.c);

proot=(-n.b+sqrt(disc))/(2*n.a);

nroot=(-n.b-sqrt(disc))/(2*n.a);

cout<<"\t\tproot = "<<proot<<'\n';

cout<<"\t\tnroot = "<<nroot<<'\n'; }

void display(Equation n)
{ cout<<"\t\t---------------------\n";

cout<<"\t\t Display Roots"<<'\n';

cout<<"\t\t---------------------\n";

func(n);

cout<<"\t\t---------------------\n";}

int main() // main function

{ Equation q;

func(q);

display(q);

}
#include <iostream>

#include <math.h>

using namespace std;

class Matrix{ private:

int a[3][3],b[3][3],c[3][3];

public:

void set_Matrix()

{cout<<"Enter the elements of A matrix :\n";

for(int i=0; i<3; i++)

{ for(int j=0; j<3; j++)

{ cin>>a[i][j];

cout<<"Enter the elements of B matrix :\n";

for(int i=0; i<3; i++)

{ for(int j=0; j<3; j++)

{ cin>>b[i][j];

} }

void get_Matrix()

{cout<<"------------------\n";

cout<<"==> A matrix :\n";

for(int i=0; i<3; i++)

{ for(int j=0; j<3; j++)

{ cout<<a[i][j]<<'\t'; }

cout<<'\n';

} cout<<"------------------\n";

cout<<"==> B matrix :\n";

for(int i=0; i<3; i++)


{ for(int j=0; j<3; j++)

{ cout<<b[i][j]<<'\t'; }

cout<<'\n';

friend void func(Matrix);

};

void func(Matrix m)

{cout<<"------------------\n";

cout<<"C = A + B \n";

cout<<"------------------\n";

cout<<"==> C matrix :\n";

for(int i=0; i<3; i++)

{ for(int j=0; j<3; j++)

{ m.c[i][j]=m.a[i][j]+m.b[i][j];

cout<<m.c[i][j]<<'\t'; }

cout<<'\n';

} cout<<"------------------\n";

int main()

{ Matrix mat;

mat.set_Matrix();

mat.get_Matrix();

func(mat);

You might also like