KARNATAKA PUC COMPUTER SCIENCE STUDY MATERIALS (SECOND EDITION)

Image
VISIT MY WORDPRESS BLOG FOR REVISED AND LATEST STUDY MATERIALS FIRST PUC FIRST PUC LAB MAUAL CHAPTER 1 COMPUTER SYSTEM CHAPTER 2 ENCODING SCHEMES AND NUMBER SYSTEM CHAPTER 3  EMERGING TRENDS CHAPTER 4 INTRODUCTION TO PROBLEM SOLVING CHAPTER 5 GETTING STARTED WITH PYTHON CHAPTER 6 FLOW CONTROL CHAPTER 7 FUNCTIONS CHAPTER 8 STRINGS CHAPTER 9 LISTS CHAPTER 10 TUPLES AND DICTIONARIES CHAPTER 11 SOCIETAL IMPACT SECOND PUC SECOND PUC LAB MANUAL CHAPTER 1 EXCEPTION HANDLING IN PYTHON CHAPTER 2 FILE HANDLING IN PYTHON CHAPTER 3 STACK CHAPTER 4 QUEUE CHAPTER 5 SORTING CHAPTER 6 SEARCHING CHAPTER 7  UNDERSTANDING DATA CHAPTER 8 DATABASE  CONCEPTS CHAPTER 9 SQL NOTES CHAPTER 9 SQL Q&A CHAPTER 10 COMPUTER NETWORKS CHAPTER 11 DATA COMMUNICATION CHAPTER 12 SECURITY ASPECTS

C++ Program: Roots of a Quadratic Equation

 // 7 C++ program – Roots of a quadratic equation

/* 7

Write a C++ program to create a class with data members a, b, c andmember functions to input data, compute the discriminant based on the

following conditions and print the roots.

 If discriminant = 0, print the roots are equal and their value.

 If discriminant > 0, print the real roots and their values.

 If discriminant < 0, print the roots are imaginary and exit the program.

*/


#include<iostream.h>

#include<conio.h>

#include<math.h>


class Quadratic

{

private:

int a, b, c;

float disc, x, x1, x2;

public:

void readdata( );

void compute( );

void display( );

};


void Quadratic::readdata( )

{

cout<<"Enter the values for a, b, c (Co-efficeient)"<<endl;

cin>>a>>b>>c;

}


void Quadratic::compute( )

{

disc = b*b-4*a*c;

}


void Quadratic::display( )

{

compute( );

if(disc == 0)

{

cout<<"Equal Roots..."<<endl;

x=-b/(2*a);

cout<<"Root is...."<<x;

}

else if(disc>0)

{

cout<<"Real and Distinct Roots..."<<endl;

x1=(-b+sqrt(disc))/(2*a);

x2=(-b-sqrt(disc))/(2*a);

cout<<"Root 1 is "<<x1<<endl;

cout<<"Root 2 is "<<x2<<endl;

}

else

cout<<"Imaginary Roots..."<<endl;

}


void main( )

{


Quadratic q;

clrscr( );

q.readdata( );

q.display( );

getch( );

}

Comments

Popular posts from this blog

KARNATAKA PUC COMPUTER SCIENCE STUDY MATERIALS (SECOND EDITION)

Karnataka I PUC Computer Science 2024 Study Material | SECOND PUC HANDBOOK EXAM 2025