Program to multiply two polynomials
Posted on August 7, 2008
(Last modified on August 7, 2020)
| 3 minutes
| Kinshuk Chandra
Program to multiply two polynomials(Source Code)
// Program Ch02pr06
// Program to multiply two polynomials
#include
#include
using namespace std;
const int MAX = 10 ;
class poly
{
private :
struct term
{
int coeff ;
int exp ;
} t[MAX] ;
int noofterms ;
public :
poly( ) ;
void polyappend ( int c, int e ) ;
void polyadd ( poly &p1, poly &p2 ) ;
[Read More]Program to Add two polynomials
Posted on August 7, 2008
(Last modified on August 7, 2020)
| 3 minutes
| Kinshuk Chandra
Program to Add two polynomials(Source Code)
// Program Ch02pr05
// Program to Add two polynomials
#include <iostream\> #include <conio.h\> using namespace std; const int MAX \= 10 ; class poly { private : struct term { int coeff ; int exp ; } t\[MAX\] ; int noofterms ; public : poly( ) ; void polyappend ( int c, int e ) ; void polyadd ( poly &p1, poly &p2 ) ; void display( ) ; } ; // initializes data members of class poly poly :: poly( ) { noofterms \= 0 ; for ( int i \= 0 ; i < MAX ; i++ ) { t\[i\].
[Read More]Program for matrix operations like determinant, singular, etc.
Posted on August 7, 2008
(Last modified on August 7, 2020)
| 3 minutes
| Kinshuk Chandra
Program for matrix operations like determinant, singular, etc.(Source Code)
#include
#include
#include
using namespace std;
const int MAX = 3 ;
class matrix
{
private :
int mat[MAX][MAX] ;
public :
matrix( ) ;
void create( ) ;
void display( ) ;
matrix matmul ( matrix &m ) ;
matrix transpose( ) ;
int determinant( ) ;
int isortho( ) ;
} ;
// initializes the matrix mat with 0
[Read More]Program to perform operations like addition, multiplicaton, etc. on matrix
Posted on August 7, 2008
(Last modified on August 7, 2020)
| 3 minutes
| Kinshuk Chandra
Program to perform operations like addition, multiplicaton, etc. on matrix(Source Code)
// Program Ch02pr03
// Program to perform operations like addition, multiplicaton, etc. on matrix
#include
#include
using namespace std;
const int MAX = 3 ;
class matrix
{
private :
int **mat ;
int sz1, sz2;
public :
matrix( int siz1, int siz2) ;
void create( ) ;
void display( ) ;
void matadd ( matrix &m1, matrix &m2 ) ;
[Read More]Program to merge two 1-D arrays
Posted on August 7, 2008
(Last modified on August 7, 2020)
| 3 minutes
| Kinshuk Chandra
Here is the program in cpp:
#include <iostream.h> #include <conio.h> using namespace std; const int MAX1 = 5 ; const int MAX2 = 7 ; class array { private : int \*arr ; int size ; public : void create ( int sz ) ; void sort( ) ; void display( ) ; void merge ( array &a , array &b ) ; } ; // creates array of given size sz, dynamically void array :: create ( int sz ) { size = sz ; arr = new int\[size\] ; int n ; for ( int i = 0 ; i < size ; i++ ) { cout << "\\nEnter the element no.
[Read More]Representing Arrays as a class in cpp
Posted on August 6, 2008
(Last modified on August 7, 2020)
| 3 minutes
| Kinshuk Chandra
Program to implement an array.(Source Code)
// Program Ch02pr01
// Program to implement an array.
#include using namespace std; const int MAX \= 100 ; class array { private : int arr\[MAX\] ; int N; int pos; public : void create(int i) { N\=i; int arr\[N\]; pos\=0; } void add(int n); void insert ( int pos, int num) ; void del ( int pos ) ; void reverse( ) ; void display( ) ; void search ( int num ) ; } ; void array::add(int n) { arr\[pos++\]\=n; } // inserts an element num at given position pos void array :: insert ( int pos, int num ) { // shift elements to right int i; for ( i \= N \- 1 ; i >\= pos ; i\-\- ) { arr\[i\] \= arr\[i \- 1\] ; } arr\[i\] \= num ; } // deletes an element from the given position pos void array :: del ( int pos ) { // skip to the desired position int i; for ( i \= pos ; i < N ; i++ ) arr\[i \- 1\] \= arr\[i\] ; arr\[i \- 1\] \= 0 ; } // reverses the entire array void array :: reverse( ) { for ( int i \= 0 ; i < N / 2 ; i++ ) { int temp \= arr\[i\] ; arr\[i\] \= arr\[N \- 1 \- i\] ; arr\[N \- 1 \- i\] \= temp ; } } // searches array for a given element num void array :: search ( int num ) { // Traverse the array int i; for ( i \= 0 ; i < N ; i++ ) { if ( arr\[i\] \=\= num ) { cout << "\\n\\nThe element " << num << " is present at "<< ( i + 1 ) << "th position" ; return ; } } if ( i \=\= N ) cout << "\\n\\nThe element " << num << " is not present in the array" ; } // displays the contents of a array void array :: display( ) { cout<< endl ; // traverse the entire array for ( int i \= 0 ; i < N ; i++ ) cout << " " << arr\[i\] ; } int main( ) { array a ; a.
[Read More]Why
Posted on August 6, 2008
(Last modified on August 7, 2020)
| 1 minutes
| Kinshuk Chandra
I forget everything in studies and my things get misplaced so I decided to keep them safe on blogger.
So I decided to blog on it.