Friday, September 26, 2014

Linear Algebra toolkit

This Linear Algebra Toolkit is composed of the modules listed below. Each module is designed to help a linear algebra student learn and practice a basic linear algebra procedure, such as Gauss-Jordan reduction, calculating the determinant, or checking for linear independence.
=====================================================
One of the most Important Tool used for solving Matrix and Matrix operations:

"Matrix Calculator"

Click Here-                             2 Click Here-                   3  Click Here-
=====================================================
Systems of linear equations and matrices
Row operation calculatorInteractively perform a sequence of elementary row operations on the given m x n matrix A.
Transforming a matrix to row echelon formFind a matrix in row echelon form that is row equivalent to the given m x n matrix A.
Transforming a matrix to reduced row echelon formFind the matrix in reduced row echelon form that is row equivalent to the given m x n matrix A.
Solving a system of linear equationsSolve the given system of m linear equations in n unknowns.
Calculating the inverse using row operationsFind (if possible) the inverse of the given n x n matrix A.
Determinants
Calculating the determinant using row operationsCalculate the determinant of the given n x n matrix A.



Tuesday, September 23, 2014

Pointers To Arrays in C++

Under Standing The concept of Pointer to array how the point any location in an array

#include<iostream.h>
void main()
{
int word[5]={2,6,4,7,8};
int *ptr;
ptr=word;

// For Values of array
cout<<" There are three way to print the value of this array "<<endl;
for(int i=0;i<5;i++)
{
cout<<endl<<" Value of word["<<i<<"] by simple index: "<<word[i];
cout<<endl<<" Value of word["<<i<<"] by *word:        "<<*(word+i);
cout<<endl<<" Value of word["<<i<<"] by *(ptr):       "<<*(ptr+i);
 }
// For Adresses of Array
cout<<"\n\t\tAdresses of Arrays\nThere are also three ways to find the adresses of this array"<<endl;
for(int k=0;k<5;k++)
{
cout<<endl<<" Adress of word["<<k<<"] by & operator   "<<&word[k];
cout<<endl<<" Adress of word["<<k<<"] by word:        "<<(word+k);
cout<<endl<<" Adress of word["<<k<<"] by (ptr):       "<<(ptr+k);
}
}

Monday, September 22, 2014

Pointers in C++

Pointer To Integers & Pointer To Pointer

**************************************************************************************
#include<iostream.h>
void main()
{
int var1=11;
int *ptr;
// pointer to integer
// dealing with pointer *ptr and integer vriable var1
ptr=&var1;
// Errors
//      *ptr=&var1;
//       ptr=var1;
//       var1=&ptr;
cout<<"Adress that pointer ptr is holding=                                      "<<ptr;
cout<<endl<<"Value of integer variable var=                                   "<<var1;
cout<<endl<<"Adress of var1 vriable using adress operator=              "<<&var1;
cout<<endl<<"Value of that variable for those this pointer is assign=  "<<*ptr;
cout<<endl<<"Own Address of pointer ptr=                                      "<<&ptr;

//dealing with pointer to pointer
int **ptr1;

//   Errors
// ptr1=var1;
// ptr1=ptr;
// ptr1=&var1;
// ptr1=&*ptr;
ptr1=&ptr;
cout<<endl<<"Adress that pointer** ptr1 is holding=            "<<ptr1;
cout<<endl<<"Adress that pointer* ptr is holding=               "<<*ptr1;
cout<<endl<<"Own adress of pointer** ptr1=                       "<<&ptr1;
cout<<endl<<"Adress that pointer* ptr is holding=                "<<&ptr;
cout<<endl<<"Value of variable that adress is saved in ptr*= "<<**ptr1;

//  Derefrencing addresses
var1=3;
*ptr=4;        // use all these three one by one and see the change in output
**ptr1=5;
 cout<<endl<<"\n\t var1=3 *ptr=4 **ptr1=5\n";
cout<<endl<<"Adress that pointer ptr is holding=                             "<<ptr;
cout<<endl<<"Value of integer variable var=                                  "<<var1;
cout<<endl<<"Adress of var1 vriable using adress operator=              "<<&var1;
cout<<endl<<"Value of that variable for those this pointer is assign= "<<*ptr;
cout<<endl<<"Own Address of pointer ptr=                                   "<<&ptr;
cout<<endl<<"Adress that pointer** ptr1 is holding=                      "<<ptr1;
cout<<endl<<"Adress that pointer* ptr is holding=                         "<<*ptr1;
cout<<endl<<"Own adress of pointer** ptr1=                                "<<&ptr1;
cout<<endl<<"Adress that pointer* ptr is holding=                         "<<&ptr;
cout<<endl<<"Value of variable that adress is saved in ptr*=          "<<**ptr1;

}

Sunday, September 21, 2014

C Program to find the Inverse of the Matrix

    #include<stdio.h> #include<math.h> float detrminant(float[][], float); void cofactors(float[][], float); void trans(float[][], float[][], float); void main() { float a[25][25], n, d; int i, j; printf("Enter the order of the matrix:\n"); scanf("%f", &n); printf("Enter the elemnts into the matrix:\n"); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%f", &a[i][j]); } } d = detrminant(a, n); printf("\nTHE DETERMINANT IS=%2f", d); if (d == 0) printf("\nMATRIX IS NOT INVERSIBLE\n"); else cofactors(a, n); } float detrminant(float a[25][25], float k) { float s = 1, det = 0, b[25][25]; int i, j, m, n, c; if (k == 1) { return (a[0][0]); } else { det = 0; for (c = 0; c < k; c++) { m = 0; n = 0; for (i = 0; i < k; i++) { for (j = 0; j < k; j++) { b[i][j] = 0; if (i != 0 && j != c) { b[m][n] = a[i][j]; if (n < (k - 2)) n++; else { n = 0; m++; } } } } det = det + s * (a[0][c] * detrminant(b, k - 1)); s = -1 * s; } } return (det); } void cofactors(float num[25][25], float f) { float b[25][25], fac[25][25]; int p, q, m, n, i, j; for (q = 0; q < f; q++) { for (p = 0; p < f; p++) { m = 0; n = 0; for (i = 0; i < f; i++) { for (j = 0; j < f; j++) { b[i][j] = 0; if (i != q && j != p) { b[m][n] = num[i][j]; if (n < (f - 2) n++; else { n = 0; m++; } } } } fac[q][p] = pow(-1, q + p) * detrminant(b, f - 1); } } trans(num, fac, f); } void trans(float num[25][25], float fac[25][25], float r) { int i, j; float b[25][25], inv[25][25], d; for (i = 0; i < r; i++) { for (j = 0; j < r; j++) { b[i][j] = fac[j][i]; } } d = detrminant(num, r); inv[i][j] = 0; for (i = 0; i < r; i++) { for (j = 0; j < r; j++) { inv[i][j] = b[i][j] / d; } } printf("\nTHE INVERSE OF THE MATRIX:\n"); for (i = 0; i < r; i++) { for (j = 0; j < r; j++) { printf("\t%2f", inv[i][j]); } printf("\n"); } }

Saturday, September 20, 2014

Data Structure Programs

Read Also:  


"All Data Structure Programs up-till now"

To get code Click on that program heading :) ☺ ☻ 

 ALL Type Of Sorting Click here :: most important :: 

-------------------

`Queues 

----------------

`Single Link-List:

*  How to create single Link-list in C++

*  Insertion at any point in link-list in C++

*  Concatenate or Merge two Link-lists in C++

Deletion At any point in Circular Link List in C++
------------------------------------

`Double Link-list:

=================

Stacks Data Structure:


Decimal to binary conversion using stack in c++
============ 

How to add two matrix size is define by use






Program to print counting 10 to 1 using Recursion

--------------------------------------------------



Program to print counting 1 t0 10 using Recursion

#include<iostream.h>
#include<conio.h>
void myfuntion(int);
void main()
{
clrscr();
myfuntion(1);
}
void myfuntion(int counter)
{
if(counter==11)
return;
else
{
cout<<"\ncounter= "<<counter;
myfuntion(++counter);
return;
}
}

C++ Program to find Fibonacci sequence

#include<iostream.h>
#include<conio.h>
int fib(int);
void main()
{
clrscr();
int a=0;
cout<<"\nEnter a no that u want to know fibnocci sequense of: ";
cin>>a;
cout<<fib(a);
}
int fib(int no)
{
if(no==0)
return 0;
else if(no==1)
return 1;
else
return fib(no-1)+fib(no-2);
}

Saturday, September 13, 2014

Insertion And Deletion in array at any point

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c=0,d,no,j;
cout<<"\nenter the size af array :";
cin>>a;
int *x=new int[a];
cout<<"\n Now the size of array is= "<<a; x[a]=NULL;
cout<<"\n first enter a no of values u want enter: ";
cin>>b;

for(int q=1;q<=b;q++)
{
cout<<"\n enter a value for x["<<q<<"] =";
cin>>x[q]; c++;
}
{
for(int w=1;w<=b;w++)
cout<<"\n The value u enter at "<<w<<"is "<<x[w];
}
cout<<"\n Displaing whole array :";
for(int i=1;i<=a;i++)
cout<<"\n the value at index "<<i<<" is "<<x[i];
cout<<"\n Total values u enter right now are \"counter=\""<<c;
cout<<"\n\n----________-----_-----__---_-_--------_---_-_-_--_-__-_-_-__-";
cout<<"\n\t INSERTION\n\n enter index u want to insert value";
cin>>d;
if(c>a)
cout<<"\n sorry no space in array";
else
{{
for(j=c;j>=d;j--)
x[j+1]=x[j];

}
cout<<"\n Enter value at index "<<d;
cin>>no;
x[d]=no;c++;
}
  cout<<"\n Displaing whole array :";
for(int r=1;r<=a;r++)
cout<<"\n the value at index "<<r<<" is "<<x[r];
cout<<"\n Total values u enter right now are \"counter=\""<<c;
 clrscr();
  cout<<"\n\n----________-----_-----__---_-_--------_---_-_-_--_-__-_-_-__-";
cout<<"\n\t DELETION\n\n enter index u want to delet value";
cin>>d;
{{
for(j=d;j<=c;j++)
x[j]=x[j+1];

} c--;
cout<<"\n Displaing whole array :";
for(int r=1;r<=a;r++)
cout<<"\n the value at index "<<r<<" is "<<x[r];
cout<<"\n Total values u enter right now are \"counter=\""<<c;
} }

Wednesday, September 10, 2014

Saturday, September 6, 2014

CONSOLE COLOUR CHANGING IN C++

Structure of the Problem Requirements 

In this problem we will learn about the color changing in Console in C++ Program. For changing colour of text or background we include the windows.h class in C++ program. Windows library deal with such a events. In our program we make an instance of handle class and then use it to change the colour of the required lines. Here is the source code of this problem which help you in better understanding.


SOURCE CODE


#include<iostream>
#include<windows.h>
using namespace std;
int main ()
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute(h,FOREGROUND_RED | FOREGROUND_INTENSITY);
cout<<"\t \t \t \t LEP \n \n \n ";
SetConsoleTextAttribute(h,FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout<<" CEO & Founders  :" <<" Usman Siddique \n " <<endl;
SetConsoleTextAttribute(h,FOREGROUND_BLUE | FOREGROUND_INTENSITY);
cout<<"  Developers      :" <<" Hafiz muhammad usman siddique \n " <<endl;
SetConsoleTextAttribute(h,FOREGROUND_RED | FOREGROUND_INTENSITY);
cout<<"  Website         :" <<" pcphunt.blogspot.com \n " <<endl;
SetConsoleTextAttribute(h,FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout<<"  Facebook Address:" <<" https://www.facebook.com/usman.siddique.7771 \n " <<endl;
SetConsoleTextAttribute(h,FOREGROUND_BLUE | FOREGROUND_INTENSITY);
cout<<"   Address :" <<"Comsats  \n " <<endl;
}

Difference between char a[]="string"; and char *p="string";

What is the difference between char a[]="string"; and char *p="string";?


The first one is array the other is pointer.
The array declaration "char a[6];" requests that space for six characters be set aside, to be known by the name "a." That is, there is a location named "a" at which six characters can sit. The pointer declaration "char *p;" on the other hand, requests a place which holds a pointer. The pointer is to be known by the name "p," and can point to any char (or contiguous array of chars) anywhere.
The statements
char a[] = "hello";
char *p = "world";
would result in data structures which could be represented like this:
   +---+---+---+---+---+---+
a: | h | e | l | l | o |\0 |
   +---+---+---+---+---+---+
   +-----+     +---+---+---+---+---+---+
p: |  *======> | w | o | r | l | d |\0 |
   +-----+     +---+---+---+---+---+---+
It is important to realize that a reference like x[3] generates different code depending on whether x is an array or a pointer. 
Given the declarations above, when the compiler sees the expression a[3], it emits code to start at the location "a," move three past it, and fetch the character there. When it sees the expression p[3], it emits code to start at the location "p," fetch the pointer value there, add three to the pointer, and finally fetch the character pointed to.
 In the example above, both a[3] and p[3] happen to be the character 'l', but the compiler gets there differently.

Difference Between char a[]; and char[] a;

Difference Between char a[]; and char[] a;

you know is there any difference between above of two Array deceleration ... or it is right or wrong 
.
so the answer is its right and have a little difference

char a[]; 

means the variable 'a' is an array of character type of undefined size ..

char[] a; 

 also means the same but the difference is that if v put some other variable after a like

char[] a,b,c;

 then all of them are declare as an array of undefined size ..that's simple :)

Also see: File Handling in C language

Monday, September 1, 2014

MEDICAL LAB MANAGEMENT SYSTEM Code in C++

Read Also:  


MEDICAL LAB MANAGEMENT SYSTEM Code in C++

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<dos.h>
#include<fstream.h>
#include<iomanip.h>
/*
 PATIENT CLASS
 */
class patient{
private:
char f_name[10],m_test[20],c_report[30];
int id;
public:
char name[10];
/*
CONSTRUCTOR
*/
patient()
{
strcpy(name,NULL);
strcpy(f_name,NULL);
strcpy(m_test,NULL);
strcpy(c_report,NULL);
id=0;
}
/*
EDITING FUNTION
*/
void edit(int i)
{              id=i;
cout<<"\t\tEnter Data About Patient\n";
cout<<"\nPatient ID number is: "<<id;
cout<<"\nEnter the name of patient: ";
cin>>name;
cout<<"\nEnter father name of patient: ";
cin>>f_name;

cout<<"\nEnter name of medical test: ";
cin>>m_test;
cout<<"\nEnter patient complete report: ";
cin>>c_report;
}
/*
DISPLAY FUNTION
*/
void show(int i)
{                  id=i;
cout<<"\n\t\tPatient Detail\n";
cout<<"\nPatient ID no is: "<<i;
cout<<"\nPatient name is: "<<name;
cout<<"\nPatient father name is: "<<f_name;
cout<<"\nPatient Medical test name is: "<<m_test;
cout<<"\nPatient Complete report: "<<c_report;
}
/*
DELETE FUNTION
*/
void delet(int i)
{
id=i;
strcpy(name,"deleted...");
strcpy(f_name,"deleted...");
strcpy(m_test,"deleted...");
strcpy(c_report,"deleted...");
cout<<"\n\nRecord of patient with ID no "<<id<<" has ben deleted.";
cout<<"\n\nName:   "<<name;
cout<<"\nFather name: "<<f_name;
cout<<"\nMedical test: "<<m_test;
cout<<"\nComplete Report: "<<c_report;
strcpy(name,NULL);
strcpy(f_name,NULL);
strcpy(m_test,NULL);
strcpy(c_report,NULL);
id=0;
     }
};
void delete_patient();
void creat_data();
void pass();
void intro();
/*
MAIN FUNTION
*/
void main()
{
intro();
pass();
int choice,i1;
char m,q;
patient a[500];
a:clrscr();
 cout<<"\t\tSELECT A MODE\n\n";
 cout<<"\nEdit   01\nSearch       02\nDelete 03\nExit 04\n";
 cin>>choice;
 switch(choice) {
 /*
CASE 1 EDIT
*/
 case 1:
s:clrscr();
cout<<"\nEnter ID no Of Patient: ";
 cin>>i1;
 a[i1].edit(i1);
 cout<<"\nEnter another Patient data ?   Press A";
 cin>>q;
 if(q=='a'||q=='A')
 goto s;
 else{
a1: cout<<"\n\n\t\tBack to main menu press M\n";
 cin>>m;
 if(m=='m'||m=='M')
 goto a;
 else
 clrscr();
 goto a1; }

 /*
CAES 2 SEARCH
*/
 case 2:  char s;
z: clrscr();
 cout<<"\n\tSearch by  name:  Press N";
 cout<<"\n\tSearch by ID no:  Press I";
 cin>>s;
 /*
MULTI OPTION SEARCH
*/
 if(s=='i')               //BY ID NO..
 {
 cout<<"\nEnter ID no Of Patient: ";
 cin>>i1;
 a[i1].show(i1);
 a2: cout<<"\n\n\t\tBack to main menu press M\n";
 cin>>m;
 if(m=='m'||m=='M')
 goto a;
 else
 clrscr();
 goto a2; }
 else if(s=='n')                      //BY NAME
 {
 char name1[10];
 cout<<"\nEnter Patient name: ";
 cin>>name1;
 cout<<"\nSearching for Patient Name: =>  "<<name1<<"   > > > Wait....";
 for(int x=1;x<=500;x++)
{
 if(strcmp(name1,a[x].name)==0)
 a[x].show(x);

 }
 cout<<"\nRecord not found...";
 }
 else
 goto z;


    break;
    /*
  CASE 3  DELETE DATA
*/
 case 3:
 cout<<"\nEnter ID no Of Patient: ";
 cin>>i1;
 a[i1].delet(i1);
 a3: cout<<"\n\n\t\tBack to main menu press M\n";
 cin>>m;
 if(m=='m'||m=='M')
 goto a;
 else
 clrscr();
 goto a3;

 /*
 CASE 4 EXIT
 */
 case 4:
 exit(0);

 default:
 clrscr();
 goto a;

}
 }
////////////////////////
fstream file1,file2;
patient bk;

void creat_data()
{


char ch;
file1.open("patient.dat",ios::out|ios::app);
do
{
clrscr();
bk.edit(0);
file1.write((char*)&bk,sizeof(patient));
cout<<"\n\nDo you want to add more record..(y/n?)";
cin>>ch;
}while(ch=='y'||ch=='Y');
file1.close();
}

void delete_patient()
{
char n[6];
int flag=0;
clrscr();
cout<<"\n\n\n\tDELETE Patient...";
cout<<"\n\nEnter The ID no. of the Patient You Want To Delete : ";
cin>>n;
file1.open("patient.dat",ios::in|ios::out);
fstream file2;
file2.open("Temp.dat",ios::out);
file1.seekg(0,ios::beg);
while(file1.read((char*)&bk,sizeof(patient)))
{
if(strcmp(n,n)==0)
file2.write((char*)&bk,sizeof(patient));
else
flag=1;
}

file2.close();
file1.close();
remove("patient.dat");
rename("Temp.dat","patient.dat");
    if(flag==1)
      cout<<"\n\n\tRecord Deleted ..";
    else
      cout<<"\n\nRecord not found";
    getch();
}
//////////////////////
void pass()
{
char u[]={"usman"},pass[20],awe[20];
f:clrscr();
gotoxy(30,15);
cout<<char(3)<<char(3)<<"  AUTHENTICATION REQUIRED  "<<char(3)<<char(3);
gotoxy(26,17);
cout<<"User Name= ";
cin>>awe;
gotoxy(26,19);
cout<<"Pass Word= ";
cin>>pass;
cout<<"\n\nChecking for Username and Password...........\n\n";
{
if(strcmp(pass,u)==0)
h:{
delay(1500);
cout<<"\n\n\t\t\t"<<char(1)<<" LOGIN SUCCESFULY "<<char(1);
cout<<"\n\n\n\n\n\n\t\t\" PRESS ANY KEY TO CONTINUE\"";
getch();
}

else {

cout<<"\n\n\n\n\n\n\n\n\n\t\t\"SORY WORNG USERNAME OR PASSWORD\"\n\n\t\t TRY AGIAN ";
delay(1800);
goto f;}
}}
////////////////////////// INTRO//
void intro()
{
clrscr();
gotoxy(20,10);
cout<<"MADICAL  LAB   MANEGMENT  SYSTEM";
gotoxy(5,20);
cout<<"\n Usman Siddique from Comsats wah";
getch();
}