Sunday 23 October 2016

Generic Vector Using Template

/* AIM : Create a class template to represent a generic vector. Include following
member functions:
1]To create the vector.
2]To modify the value of a given element
3]To multiply by a scalar value
4]To display the vector in the form (10,20,30)
*/

#include<iostream>
using namespace std;

template<class T>
class vector
{
T *v;
int size;
public:
vector(int m) // parameterized constructor to create NULL vector
{
v=new T[size=m];
for(int i=0;i<size;i++)
v[i]=0;
}

void create()
{
for(int i=0;i<size;i++)
{
cout<<"v["<<i<<"] = ";
cin>>v[i];
}
}

void modify()
{
int pos;
cout<<"enter position to make changes :";
cin>>pos;
cout<<"Enter new Value :";
cin>>v[pos];
}

void multiply()
{
T sc;
cout<<"Enter scaler Number to multiply with vector : ";
cin>>sc;
for(int i=0;i<size;i++)
v[i]=v[i]*sc;
}

void display()
{
int i;
cout<<"(";
for(i=0;i<size-1;i++)
{
cout<<v[i]<<",";
}
cout<<v[i]<<")\n";
}


};

int main()
{
int size;
cout<<"enter size of vector: ";
cin>>size;
vector<int> vi(size); //creates int vector
vi.create();
vi.display();
vi.modify();
vi.display();
vi.multiply();
vi.display();

}

Selection Sort Function Template

/*
TITLE:
Write a function template selection Sort. Write a program that inputs, sorts and outputs an integer array and a float array.
*/
#include<iostream>
using namespace std;
template<class T>
class sort
{
public:
T a[50];
int n;
void accept()
{
cout<<"Enter no. of elements:\n";
cin>>n;
cout<<"enter a elements\n";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}
void selection_sort()
{
T temp;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
void display()
{
for(int i=0;i<n;i++)
{cout<<a[i]<<"\n";
}
}
};

int main()
{
int v;char ch;
sort<int>s1;
sort<float>s2;

cout<<"*****SELECTION SORT*******\n";
do
{
cout<<"sorting of integer and float array"<<"\n";
cout<<"1.for int array\n";
cout<<"2.for float array\n";
cout<<"enter your choice\n";
cin>>v;
switch(v)
{
case 1:
s1.accept();
cout<<"\nElements are:\n";
s1.display();
s1.selection_sort();
cout<<"\nSorted elements are:\n";
s1.display();
break;
case 2:
s2.accept();
cout<<"\nElements are:\n";
s2.display();
s2.selection_sort();
cout<<"\nSorted elements are:\n";
s2.display();
break;
}
cout<<"\n do you want to continue";
cin>>ch;
}while(ch=='y'||ch=='Y');
return 0;
}

Addition of Binary numbers using Standard Template Library

/*
TITLE:
Write C++ program using STL to add binary numbers ; use STL stack.
*/
#include<iostream>
#include<stack>
using namespace std;
stack<int> read()
{
stack<int> s;
int x,n,i;
n=4;
cout<<"\nEnter 4 bit binary number : ";
for(i=0;i<n;i++)
{
cin>>x;
s.push(x);
}
return s;
}

void display(stack<int> &s)
{
cout<<" ";
while(!s.empty())
{
cout<<s.top()<<" ";
s.pop();
}
}

stack<int> add(stack<int> &s1,stack<int> &s2)
{
stack<int> s;
int sum,carry=0,b1,b2;
while(!s1.empty()||!s2.empty())
{
b1=b2=0;
if(!s1.empty())
{
b1=s1.top();
s1.pop();
}
if(!s2.empty())
{
b2=s2.top();
s2.pop();
}
sum=(b1+b2+carry)%2;
carry=(b1+b2+carry)/2;
s.push(sum);
}
if(carry==1)
s.push(1);
return s;
}

int main()
{
stack<int> s1,s2,s3;
int c;
char ch;
do
{
cout<<"Binary Addition\n";
cout<<"1.accept a numbers(give space after each bit)\n";
cout<<"2.Display addtion of two numbers\n";
cout<<"Enter your choice..:\n";
cin>>c;
switch(c)
{
case 1:
s1=read();
s2=read();
break;
case 2:
cout<<"\nThe result of addition is : ";
s3=add(s1,s2);
display(s3);
break;
}
cout<<"\ndo you want to continue?\n";
cin>>ch;
}while(ch=='y'||ch=='Y');
return 0;
}

Dequeue Using Standard Template Library

/*
TITLE:Write C++ program using STL for Dequeue (Double ended queue)
*/

#include<iostream>
#include<deque>
using namespace std;

int main()
{
int v,a;
deque<int>dq;
deque<int>::iterator it;
cout<<"1.insert from front\n";
cout<<"2.insert from back\n";
cout<<"3.delete from front\n";
cout<<"4.delete from back\n";
cout<<"5.front element\n";
cout<<"6.last element\n";
cout<<"7.size of dequeue\n";
cout<<"8.display\n";
cout<<"9.exit\n";
while(1)
{
cout<<"\nenter choice\n";
cin>>v;
switch(v)
{
case 1: cout<<"enter element\n";
cin>>a;
dq.push_front(a);
break;
case 2: cout<<"enter element\n";
cin>>a;
dq.push_back(a);
break;
case 3: a=dq.front();
dq.pop_front();
cout<<"\n"<<a<<" is deleted";
break;
case 4: a=dq.back();
dq.pop_back();
cout<<"\n"<<a<<" is deleted";
break;
case 5: a=dq.front();
cout<<"front element is "<<a<<"\n";
break;
case 6: a=dq.back();
cout<<"last element is "<<a<<"\n";
break;
case 7: cout<<"size of deque is "<<dq.size();
break;
case 8:
for(it=dq.begin();it!=dq.end();it++)
{
cout<<*it<<"\t";
}
break;
case 9:
return 0;
}
}
}

Phonebook using File Handling

****To run this code Succesfully****
create phone.txt file in home directory of ubuntu  and then run this code

#include <iostream>
#include <fstream>
#include <cstring>
#include <iomanip>
using namespace std;

class phoneBook
{
char name[20],phno[15];
public:
void getdata();
void showdata();
 char *getname(){ return name; }
    char *getphno(){ return phno; }
    void update(char *nm,char *telno){
        strcpy(name,nm);
        strcpy(phno,telno);
    }
};

void phoneBook :: getdata(){
    cout<<"\nEnter Name : ";
    cin>>name;
    cout<<"Enter Phone No. : ";
    cin>>phno;
}

void phoneBook :: showdata(){
    cout<<"\n";
    cout<<setw(20)<<name;
    cout<<setw(15)<<phno;
}


int main(){
    phoneBook rec;
    fstream file;
    file.open("phone.txt", ios::ate | ios::in | ios::out | ios::binary );
    char c,ch,nm[20],telno[6];
    int choice,cnt,found=0;
    do{
        cout<<"\n*****Phone Book*****\n";
        cout<<"1) Add New Record\n";
        cout<<"2) Display All Records\n";
        cout<<"3) Search Telephone No.\n";
        cout<<"4) Search Person Name\n";
        cout<<"5) Update Telephone No.\n";
        cout<<"6) Exit\n";
        cout<<"Choose your choice : ";
        cin>>choice;
        switch(choice){
            case 1 : //New Record
                 rec.getdata();
                 file.write((char *) &rec, sizeof(rec));
cout<<"Record Added Succesfully\n";
                 break;

            case 2 : //Display All Records
                 file.seekg(0,ios::beg);
                 cout<<"\n\nRecords in Phone Book\n";
                 while(file){
                    file.read((char *) &rec, sizeof(rec));
                    if(!file.eof())
                        rec.showdata();
                 }
                 file.clear();
break;

            case 3 : //Search Tel. no. when person name is known.
                 cout<<"\n\nEnter Name : ";
                 cin>>nm;
                 file.seekg(0,ios::beg);
                 found=0;
                 while(file.read((char *) &rec, sizeof(rec)))
                 {
                    if(strcmp(nm,rec.getname())==0)
                    {
                        found=1;
                        rec.showdata();
                    }
                 }
                 file.clear();
                 if(found==0)
                    cout<<"\n\n---Record Not found---\n";
                    break;

            case 4 : //Search name on basis of tel. no
                 cout<<"\n\nEnter Telephone No : ";
                 cin>>telno;
                 file.seekg(0,ios::beg);
                 found=0;
                 while(file.read((char *) &rec, sizeof(rec)))
                 {
                    if(strcmp(telno,rec.getphno())==0)
                    {
                        found=1;
                        rec.showdata();
                    }
                 }
                 file.clear();
                 if(found==0)
                    cout<<"\n\n---Record Not found---\n";
                    break;

            case 5 : //Update Telephone No.
                 cout<<"\n\nEnter Name : ";
                 cin>>nm;
                 file.seekg(0,ios::beg);
                 found=0;
                 cnt=0;
                 while(file.read((char *) &rec, sizeof(rec)))
                 {
                    cnt++;
                    if(strcmp(nm,rec.getname())==0)
                    {
                        found=1;
                        break;
                    }
                 }
                 file.clear();
                 if(found==0)
                    cout<<"\n\n---Record Not found---\n";
                 else
                 {
                    int location = (cnt-1) * sizeof(rec);
                    cin.get(ch);
                    if(file.eof())
                        file.clear();

                    cout<<"Enter New Telephone No : ";
                    cin>>telno;
                    file.seekp(location);
                    rec.update(nm,telno);
                    file.write((char *) &rec, sizeof(rec));
                    file.flush();
                 }
                 break;
case 6:
break;
              }
cout<<"do you want to exit(y/n): ";
cin>>c;
    }while(c=='n'||c=='N');

file.close();
}

Friday 21 October 2016

Book shop (simple)

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//author:rushikesh sanjay palke
//class : SE comp
//roll no: 237
//subject: object oriented programming
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/*
A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies book details and requests for the number of copies required. If the   requested   copies   are   available,   the   total   cost   of   the   requested   copies   is displayed; otherwise the message  ― Required copies not in stock ‖  is displayed.
Design a system using a class called books with suitable member functions and Constructors.   Use   new   operator   in   constructors   to   allocate   memory   space required. Implement C++ program for the system.
*/
#include <iostream>
#include<string>
#include<cstring>
#include <iomanip>
using namespace std;
typedef struct b_shop
{
char author[20],title[20],pub[20];
int price,copies;
}b_shop;

class bookshop
{
int sum,count;
b_shop *B;

public:

bookshop()
{
B=new b_shop[1000];
sum=0;count=0;
}

void initial()
{
char ch;

      cout<<"\n\nEnter Author of Book:-";
      cin>>B[count].author;
      cout<<"Enter Title of Book:-";
      cin>>B[count].title;
      cout<<"Enter Publication of Book:-";
      cin>>B[count].pub;
      cout<<"Enter Price of Book:-";
      cin>>B[count].price;
      cout<<"Enter no. of copies of Book:-";
      cin>>B[count].copies;
      sum=sum+B[count].copies*B[count].price;
      count++;
   
   
}



int search()
{
char author[20],title[20];
cout<<"Enter Book title and its Author name respectively to Search in stock\n";
cin>>title>>author;
   for(int i=0;i<count;i++)
   {
    int j=strcmp(B[i].title,title);
    int k=strcmp(B[i].author,author);  
     if(!j&&!k)
      {
            cout<<"\n\nBook is In Stock\n";
            cout<<"It Cost Rs  "<<B[i].price<<endl;
            return i;
       
      }
   
    }
cout<<"\n\nSEARCH IS NOT IN STOCK\n";
return 0;
}

void display()
{
cout<<setw(10)<<"Book Title"<<setw(25)<<"Author of Book"<<setw(25)<<"Publication"<<setw(20)<<"Price"<<setw(10)<<"Copies"<<endl<<endl;
for(int i=0;i<45;i++)
cout<<"=*";
cout<<endl;
for(int i=0;i<count;i++)
{
cout<<setw(10)<<B[i].title<<setw(25)<<B[i].author<<setw(25)<<B[i].pub<<setw(20)<<B[i].price<<setw(10)<<B[i].copies<<endl;
}
}

void stock()
{
cout<<"\n\n\n\tTotal Number of Books in Stock is  "<<count<<endl;
cout<<"\tPurchase Price of Total Stock is  "<<sum<<endl;
}



void purchase()
{
int copies;
 int i=search();
if(i!=0)
{
cout<<"enter no of copies you want to purcase: ";
cin>>copies;
if(B[i].copies>copies)
{
cout<<"copies are available\n";
B[i].copies=B[i].copies-copies;
}
else
cout<<copies<<" are not available\n";
}
}



};


int main()
{
int c;
char ch;
bookshop o;
do
{
cout<<"^^^^^^^^^^^BookStore^^^^^^^^^^^^\n";
cout<<"1]New entry\n";
cout<<"2]Display\n";
cout<<"3]search book\n";
cout<<"4]Purchase book\n";
cout<<"5]stock\n";
cout<<"6]Exit\n";
cin>>c;
switch(c)
{
case 1:
o.initial();
break;
case 2:
o.display();
break;
case 3:
o.search();
break;
case 4:
o.purchase();
break;
case 5:
o.stock();
break;
case 6:
break;
}
cout<<"do you want to continue(y/n): ";
cin>>ch;
}while(ch=='y'||ch=='Y');

return 0;
}

Thursday 20 October 2016

Exception Handling

/*
CREATE A USER DEFINED EXEPTION TO CHECK THE EXEPTION AND CHECK THE FOLLOWING CONDITIONS AND THROW EXEPTION IF CRITERIA DOES NOT MATCH
A] USER HAS AGE BETWEEN 18 AND 55
B]USER STAYS IN PUNE ,MUMBAI ,BANGLORE ,CHENNAI.
C]USER HAS INCOME BETWEEN 50000 AND 100000
D] USER HAS 4 WHEELER
*/



#include<iostream>
using namespace std;


class sample
{
public:
int age,income;
char ch;
string city;
public:
void getage()
{
cout<<"enter age\n";
cin>>age;
}
void getincome()
{
cout<<"enter income\n";
cin>>income;
}
void getcity()
{
cout<<"enter city\n";
cin>>city;
}
void getveh()
{
cout<<"do you have a 4 wheeler ? (y/n)\n";
cin>>ch;
}
};


int main()
{
sample p;
p.getage();
p.getcity();
p.getincome();
p.getveh();


try
{
if((p.age<18) || (p.age>55))
{
throw p;
}
else
{
cout<<"the age is "<<p.age<<endl;
}
}
catch(sample p)
{
cout<<" age exception caught"<<endl;
}


try
{
if(p.city=="mumbai"||p.city=="pune"||p.city=="delhi"||p.city=="banglore"||p.city=="chennai")
{
cout<<"user stays in the given city"<<endl;
}
else
{
throw p;
}
}
catch(sample p)
{
cout<<"exception for city occured"<<endl;
}


try
{
if((p.income<50000)||(p.income>100000))
{
throw p;
}
else
{
cout<<"the income is "<<p.income<<endl;
}
}
catch(sample p)
{
cout<<"exception for income caught"<<endl;
}


try
{
if(p.ch=='y')
{
cout<<"the user has four wheeler"<<endl;
}
else
{
throw p;
}
}
catch(sample p)
{
cout<<"exception for vehicle cuaght"<<endl;
}
}

student database using Dynamic Memory Allocation

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//author:rushikesh sanjay palke
//class : SE comp
//roll no: 237
//date: 05 july 2016
//subject: object oriented programming
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/*                          

Develop an object oriented program in C++ to create a database of student information
system containing the following information: Name, Roll number, Class, division, Date of
Birth, Blood group, Contact address, telephone number, driving license no. etc Construct the
database with suitable member functions for initializing and destroying the data viz
constructor, default constructor, Copy constructor, destructor, static member functions, friend
class, this pointer, inline code and dynamic memory allocation operators-new and delete.*/


#include<iostream>
#include<unistd.h>
#include<cstring>
#include<string>
using namespace std;
int cnt=0;
class student
{
public:
int roll_no,age;
long int mob_no;
string b_g,clas,div;
string name,adr;
student()
{
name=" ";
roll_no=0;
clas="SE";
div="A";
adr="PCCOE HOSTEL";
b_g="A+";
mob_no=7777777777;
age=19;
}

void enter(student list[20])
{
char temp[30];
student *ptr=new student();
cout<<"enter name:\n";
cin.clear();
cin.ignore();
cin.getline(temp,30);
ptr->name=temp;
cout<<"enter roll no:\n";
cin>>ptr->roll_no;
cout<<"enter class :\n";
cin>>ptr->clas;
cout<<"enter division:\n";
cin>>ptr->div;
cout<<"enter address:\n";
cin.clear(); //used to clear input buffer
cin.ignore(); //used to clear input buffer
cin.getline(temp,30);
ptr->adr=temp;
cout<<"enter mobile number:\n";
cin>>ptr->mob_no;
cout<<"enter blood group:\n";
cin>>ptr->b_g;
cout<<"enter age:\n";
cin>>ptr->age;
list[cnt]=*ptr;
cnt++;
}
void update(student list[20])
{int r;
cout<<"enter roll no for updation";
cin>>r;
for(int i=0;i<20;i++)
{
if(r==list[i].roll_no)
{cout<<"OLD DATA\n";
cout<<"name: "<<list[i].name<<"\n";
cout<<"age: "<<list[i].age<<"\n";
cout<<"ENTER NEW DATA\n";
cout<<"Name:\n";
cin>>list[i].name;
cout<<"class :\n";
cin>>list[i].clas;
cout<<"division:\n";
cin>>list[i].div;
cout<<"address:\n";
cin>>list[i].adr;
cout<<"mobile number:\n";
cin>>list[i].mob_no;
cout<<"blood group:\n";
cin>>list[i].b_g;
cout<<"age:\n";
cin>>list[i].age;
usleep(30000);
cout<<"data updated succesfully";
}
else
cout<<"No data found\n";
break;
}

}

void display(student list[20])
{int r;
cout<<"enter students roll no";
cin>>r;
for(int i=0;i<20;i++)
{
if(r==list[i].roll_no)
{
cout<<"name: "<<list[i].name<<"\n";
cout<<"age: "<<list[i].age<<"\n";
cout<<"class:"<<list[i].clas<<endl;
cout<<"division:"<<list[i].div<<endl;
cout<<"address:"<<list[i].adr<<endl;
cout<<"mobile number:"<<list[i].mob_no<<endl;
cout<<"blood group:"<<list[i].b_g<<endl;
}
}

}


~student(){};

};

int main()
{
int ch;
student s;
student list[20];
char c;
do
{
cout<<"############STUDENT DATABASE#############\n";
cout<<"1] enter data\n";
cout<<"2] update data\n";
cout<<"3] display data\n";
cout<<"4] delete data\n";
cout<<"5] Exit student database\n";
cout<<"enter your choise:";
cin>>ch;
switch (ch)
{
case 1:
   
      s.enter(list);
      break;
   
case 2:
      s.update(list);
      break;
case 3:
      s.display(list);
      break;
case 4:
      cout<<"deleting memory..............\n";
      s.~student();
      usleep(300000);
      cout<<"memory cleaned\n";
      break;                

}
if(ch==5)
c='n';
else{
cout<<"do you want to continue (y/n)";
cin>>c;
}
}while(c=='y'||c=='Y');

cout<<"Googby Have a nice day.....\n";


}


/*
output:
############STUDENT DATABASE#############
1] enter data
2] update data
3] display data
4] delete data
5] Exit student database
enter your choise:1
enter name:
rushikesh phalke
enter roll no:
32
enter class :
SE
enter division:
B
enter address:
PCCOE Hostel
enter mobile number:
7775910607
enter blood group:
A+
enter age:
19
do you want to continue (y/n)y
############STUDENT DATABASE#############
1] enter data
2] update data
3] display data
4] delete data
5] Exit student database
enter your choise:3
enter students roll no32
name: rushikesh phalke
age: 19
class:SE
division:B
address:PCCOE Hostel
mobile number:7775910607
blood group:A+
do you want to continue (y/n)
*/

calculator using Switch Case

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//developer:rushikesh sanjay palke
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

/*Write a C++ program create a calculator for an arithmetic operator (+,-,*,/).The program should take two operands from user and performs the operation on those two operands  depending upon the operator entered by user.
Use a switch statement to select the operation. Finally, display the result.
Some sample interaction with the program might look like this:
Enter first number, operator, second number: 10 / 3
Answer = 3.333333
Do another (y/n)? y
Enter first number, operator, second number: 12 + 100
Answer = 112
Do another (y/n)? n
*/

# include <iostream>
using namespace std;
class calci
{
char o;
float num1,num2;
public:
void calculator()
{
cout << "Enter first number, operator, second number: ";
cin >>num1>>o>>num2;
cout<<"Answer =";
switch(o) {
case '+':
cout << num1+num2<<endl;
break;
case '-':
cout << num1-num2<<endl;
break;
case '*':
cout << num1*num2<<endl;
break;
case '/':
cout << num1/num2<<endl;
break;
default:
/* If operator is other than +, -, * or /, error message is shown */
cout << "Error! operator is not correct\n";
break;
}
}
};
int main()
{
calci o;
char ch;
do
{
cout<<">>>>>>>>CALCULATOR<<<<<<<<<\n";
o.calculator();
cout<<"do you want to run calculator again (y/n) ";
cin>>ch;
}while(ch=='y');
return 0;
}


/*output:

>>>>>>>>CALCULATOR<<<<<<<<<
Enter first number, operator, second number: 10/3
Answer =3.33333
do you want to run calculator again (y/n) y
>>>>>>>>CALCULATOR<<<<<<<<<
Enter first number, operator, second number: 10+2
Answer =12
do you want to run calculator again (y/n) y
>>>>>>>>CALCULATOR<<<<<<<<<
Enter first number, operator, second number: 1-1
Answer =0
do you want to run calculator again (y/n) y
>>>>>>>>CALCULATOR<<<<<<<<<
Enter first number, operator, second number: 4*1.2
Answer =4.8
do you want to run calculator again (y/n) y
>>>>>>>>CALCULATOR<<<<<<<<<
Enter first number, operator, second number: 4&4
Answer =Error! operator is not correct
do you want to run calculator again (y/n) ^C

*/

Polynomial Operations using Operator overloading

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//developer:rushikesh sanjay palke
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/*Implement a class Quadratic that represents    two degree polynomials i.e.,  polynomials of type ax2+bx+c.
Your class will require three data member corresponding to a, b and c.
Implement the following operations:
1.A constructor(including a default constructor which creates the 0 polynomial).
2.Overloaded operator+ to add two polynomials of degree 2.
3.Overloaded << and >> to print and read polynomials.
To do this, you will need to decide what you want your input and output format to look like.
4.A function eval that computes the value of a polynomial for a given value of x.
5.A function that computes the two solutions of the equation ax 2 +bx+c=0
*/


#include<iostream>
#include<cmath>
using namespace std;
class polynomial
{ int a,b,c;
public:
polynomial() //default constructor
{
a=0;
b=0;
c=0;

        }
        polynomial(int x,int y,int z) //parameterized constructor
        { a=x;b=y;c=z;    
     
        }


friend istream &operator >> (istream &IN, polynomial &T) //operator >> overloaded
{
IN>>T.a>>T.b>>T.c;
return IN;
}
friend ostream &operator << (ostream &OUT, polynomial &T) //operator << overloaded
{
OUT<<T.a<<"x^2+"<<T.b<<"x+"<<T.c;
return OUT;
}

polynomial operator +(polynomial T) //opeartor + overloaded
{
polynomial R;
R.a=a+T.a;
R.b=b+T.b;
R.c=c+T.c;
return R;
}
void eval(polynomial T,int x) //eval fn to evaluate the polynomial for given value of x
       {int z;
        z=T.a*x*x+T.b*x+T.c;
        cout<<" for x ="<<x<<" is :"<<z<<"\n";
       }
     
       void compute(polynomial T) //compute fn to find roots of polynomial
       {
       float x,y1,y2;
       x= T.b*T.b-4*T.a*T.c;
       if(x>0)
       {
       cout<<"Roots are real & not equal\n";
       y1 = (-T.b+sqrt(x))/(2*T.a);
       y2 = (-T.b-sqrt(x))/(2*T.a);
       cout<<y1<<"\n";
       cout<<y2<<"\n";
       }
       else if(x==0)
       {cout<<"roots are real & equal\n";
       y1= -T.a/(2*T.a);
       cout<<y1<<"\n";
       }
       else if(x<0)
       {
       cout<<"complex Roots\n";

       }


       }
};
int main()
{
int x,ch;
char p;
polynomial s1(5,6,10),s2,s3;
                        do
                        {
                        cout<<"######################MENU##################\n";
                        cout<<"1]display default polynomial\n";
                        cout<<"2]accept & display polynomial\n";
                        cout<<"3]add two polynomial\n";
                        cout<<"4]find f(x) for given x\n";
                        cout<<"5]find roots of give polynomial\n";
                        cout<<"enter your choise\n";
                        cin>>ch;
                        switch(ch)
                        {
                        case 1:
                        cout<<"display stored polynomial\n";
cout<<s1<<endl;
                        break;
                     
                        case 2:
cout<<"accept & display\n";
cout<<"enter the  polynomial :";
cin>>s2;
cout<<s2<<endl;
                        break;
                     
                        case 3:
                        cout<<"addition of two polynomials\n";
                        cout<<"enter the 1st polynomial :";
cin>>s1;
                        cout<<s1<<endl;
                        cout<<"enter the 2nd polynoimial:";
                        cin>>s2;
                        cout<<s2<<endl;
                        s3=s1+s2;
                        cout<<"addition is:";
cout<<s3<<endl;
                        break;
                 
                        case 4:
                        cout<<"calculate f(X) fo hiven x\n";
                        cout<<"enter the polynomial :";
cin>>s1;
cout<<"enter the value for x = ";
cin>>x;
s2.eval(s1,x);
                        break;

                        case 5:
                        cout<<"find roots of polynomial\n";
                        cout<<"enter the polynomial :";
cin>>s2;
                        s2.compute(s2);
                        break;
                        }
                        cout<<"do you want to continue(y/n)";
                        cin>>p;

                       }while(p=='y'||P=='Y');
                cout<<"goodby have a nice day\n";
               return 0;
}

/*
output:

######################MENU##################
1]display default polynomial
2]accept & display polynomial
3]add two polynomial
4]find f(x) for given x
5]find roots of give polynomial
enter your choise
1
display stored polynomial
5x^2+6x+10
do you want to continue(y/n)y
######################MENU##################
1]display default polynomial
2]accept & display polynomial
3]add two polynomial
4]find f(x) for given x
5]find roots of give polynomial
enter your choise
2
accept & display
enter the  polynomial :1 2 3
1x^2+2x+3
do you want to continue(y/n)y
######################MENU##################
1]display default polynomial
2]accept & display polynomial
3]add two polynomial
4]find f(x) for given x
5]find roots of give polynomial
enter your choise
3
addition of two polynomials
enter the 1st polynomial :1 2 3
1x^2+2x+3
enter the 2nd polynoimial:10 20 30
10x^2+20x+30
addition is:11x^2+22x+33do you want to continue(y/n)y
######################MENU##################
1]display default polynomial
2]accept & display polynomial
3]add two polynomial
4]find f(x) for given x
5]find roots of give polynomial
enter your choise
4
calculate f(X) fo hiven x
enter the polynomial :1 2 3
enter thevalue for x = 1
 for x =1 is :6
do you want to continue(y/n)y
######################MENU##################
1]display default polynomial
2]accept & display polynomial
3]add two polynomial
4]find f(x) for given x
5]find roots of give polynomial
enter your choise
5
find roots of polynomial
enter the polynomial :1 2 3
complex Roots
do you want to continue(y/n)n

*/

Complex number Operations using Operator Overloading

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//author:rushikesh sanjay palke
//subject: object oriented programming
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/*                                        
Implement a class Complex which represents the Complex Number data type. Implement the following operations:
1. A constructor (including a default constructor which creates the complex number 0+0i).
2. Overloaded operator+ to add two complex numbers.
3. Overloaded operator* to multiply two complex numbers.
4. Overloaded << and >> to print and read Complex Numbers.
To do this, you will need to decide what you want your input and output format to look like.
*/

#include<iostream>
using namespace std;
class complex
{
float  real,imag;
public:
complex(float x1,float x2)//parametrrised consructor
{real=x1;
imag=x2;}

complex()//default consructor
{real=imag=0;}

friend istream &operator>>(istream &in,complex &t) //operator >> overloaded
{
in>>t.real>>t.imag;
return in;
}

complex operator+(complex t) //operator + overloaded
{
complex z;
z.real=this->real+t.real;
z.imag=this->imag+t.imag;
return z;
}

complex operator*(complex t) //operator * overloaded
{
complex z;
z.real=this->real*t.real-this->imag*t.imag;
z.imag=this->imag*t.real+this->real*t.imag;
return z;
}


friend ostream &operator<<(ostream &op,complex &t) //operator << overloaded
{
op<<t.real<<"+i"<<t.imag;
return op;
}

};
int main()
{complex c1/*creates complex no 0+i0(default)*/,c2(3,5)/*creates complex no 3+i5(parameterized)*/,c3,c4;
int c;
char ch;
do
{
cout<<"%%%%%%%%%%%%%%polynimial operations%%%%%%%%%%%%%\n";
cout<<"1]addition of two complex no\n";
cout<<"2]multiplication of two complex no\n";
cout<<"enter your choise :";
cin>>c;
switch(c)
{
case 1:
cout<<"enter real & img  part of complex no. 1\n";
cin>>c1;
cout<<"enter real & img  part of complex no. 2\n";
cin>>c2;
c3=c1+c2;
cout<<"addition is : ";
cout<<c3<<"\n";
break;

case 2:
cout<<"enter real & img  part of complex no. 1\n";
cin>>c1;
cout<<"enter real & img  part of complex no. 2\n";
cin>>c2;
cout<<"multiplication is :";
c4=c1*c2;
cout<<c4<<"\n";
break;
}
cout<<"do you want to continue";
cin>>ch;
}while(ch=='y'||ch=='Y');

}

/*output :
*%%%%%%%%%%%%%%polynimial operations%%%%%%%%%%%%%
1]addition of two complex no
2]multiplication of two complex no
enter your choise :1
enter real & img  part of complex no. 1
1
2
enter real & img  part of complex no. 2
4
5
addition is : 5+i7
do you want to continue: y
%%%%%%%%%%%%%%polynimial operations%%%%%%%%%%%%%
1]addition of two complex no
2]multiplication of two complex no
enter your choise :2
enter real & img  part of complex no. 1
1
2
enter real & img  part of complex no. 2
4 5
multiplication is :-6+i13
do you want to continue: n
rushikeshsp25@rushikeshsp25-Aspire-E1-571:~$
/

Saturday 15 October 2016

C++ program using stack to check whether given expression is well parenthesized or not

In any language program mostly syntax error occurs due to unbalancing delimiter such as (),{},[].
So today we are going to see a program which checks whether the given expression is well parenthesized or not.
lets take an example:
{c-[(a+b)*c]} is well parenthesized expression
but
{c-[a+b)*c] is not

how to code
use stack data structure
scan the expression from left to right
if element of expression is opening paranthesis  push it in stack
if element of expression is closing paranthesis  the pop the top most element of stack
if match found repeat the loop
else return false

so lets see the implementation of this problem using c++

#include<iostream>
#include<cstring>
using namespace std;

class stack_
{
char stack[10];  //stack is created using array
int top;
public:
stack_():top(-1){} //initialization of top using constructor

void push(char x)  //push function to insert element in stack
{
if(top==9)
cout<<"overflow";
else
{
top++;
stack[top]=x;
}
}

char pop() //pop function to remove the element from stack
{
if(top!=-1)
{

return(stack[top--]);

}
else
cout<<"underflow";

}

bool is_empty() //is_empty function to check whether the stack is empty or not
{
if(top==-1)
return true;
else
return false;
}

bool is_full() //is_full function to check whether the stack is full or not
{
if(top==9)
return true;
else
return false;
}

bool balence(string ex) // main logic starts from here
{
int j=0;
char c[10];
for(int i=0;i<ex.size();i++)
{
if(ex[i]=='('||ex[i]=='{'||ex[i]=='[')
push(ex[i]);
else if(ex[i]==')'||ex[i]=='}'||ex[i]==']')
{
if(is_empty()||!pair(stack[top],ex[i]))
return false;
else
{

c[j]=pop();
j++;
}
}
}
for(int i=0;i<j;i++)
{
cout<<c[i];
}
for(int i=j-1;i>=0;i--)
{
if(c[i]=='(')
cout<<")";
else if(c[i]=='[')
cout<<"]";
else if(c[i]=='{')
cout<<"}";
}
cout<<endl;
return is_empty()?true:false;
}


bool pair(char ope,char cls)
{
if(ope=='('&& cls==')')
return true;
else if(ope=='['&& cls==']')
return true;
else if(ope=='{'&& cls=='}')
return true;
return false;
}

};

int main()
{
stack_ o;
bool b;
int m;
string s="]";
b=o.balence(s);
if(b==true)
cout<<"expression is well parenthesise\n";
else
cout<<"expression is not well parenthesise\n";
return 0;
}

Expression Conversion using stack

Infix->Postfix || Infix->Prefix || Postfix->Infix || Postfix->Prefix || Prefix->Infix || Prefix->Postfix

This program is implemented using stack. Stack is FILO or LIFO structure this property of stack is used to convert the expression from one form to another

code:

#include<iostream>
#include<string>
#include<cstring>
#include<stack>
using namespace std;

int getWeight(char ch) {
switch (ch) {
case '^':return 3;
case '/':
case '*': return 2;
case '+':
case '-': return 1;
default : return 0;
}
}


void infix2postfix(char infix[], char postfix[], int size) {
stack<char> s;
int weight;
int i = 0;
int k = 0;
char ch;
   
while (i < size) 
{
ch = infix[i];
if (ch == '(') 
{
s.push(ch);
i++;
continue;
}
if (ch == ')') 
{
while (!s.empty() && s.top() != '(') 
{
postfix[k++] = s.top();
s.pop();
}
        
if (!s.empty()) 
{
s.pop();
}
i++;
continue;
}
weight = getWeight(ch);
if (weight == 0) {
         
postfix[k++] = ch;

}
else {
         
if (s.empty()) {
       
s.push(ch);
}
else {
            
while (!s.empty() && s.top() != '(' && weight <= getWeight(s.top())) 
{
postfix[k++] = s.top();
s.pop();
}
            
s.push(ch);
}
}

i++;
}
   
while (!s.empty()) {
postfix[k++] = s.top();
s.pop();
}
postfix[k] = 0; 
}

void infix2prefix(char infix[], char prefix[], int size) {
stack<char> s;
int weight;
int i = 0;
int k = 0;
char ch;
char infix0[size];
int m=0,n=size-1;
while(m<size)
{
if(infix[n]=='(')
infix0[m]=')';
else if(infix[n]==')')
infix0[m]='(';
else
infix0[m]=infix[n];
m++;
n--;
}
infix0[m]=0;
while (i < size) {
ch = infix0[i];
if (ch == '(') {
   
s.push(ch);
i++;
continue;
}
if (ch == ')') {
        
while (!s.empty() && s.top() != '(') {
prefix[k++] = s.top();
s.pop();
}
        
if (!s.empty()) {
s.pop();
}
i++;
continue;
}
weight = getWeight(ch);
if (weight == 0) {
       
prefix[k++] = ch;

}
else {
         
if (s.empty()) {
        
s.push(ch);
}
else {
            
while (!s.empty() && s.top() != '(' && weight < getWeight(s.top())) 
{
prefix[k++] = s.top();
s.pop();
}
            
s.push(ch);
}
}
i++;
}
  
while (!s.empty()) {
prefix[k++] = s.top();
s.pop();
}
prefix[k] = 0; 
}


string postfix2infix(char postfix1[],int size)
{
string infix1;
stack<string> s;
int k=0;
while(k<size)
{
char ch=postfix1[k];
int weight=getWeight(ch);
if(weight==0)
{
string e;
e=ch;
s.push(e);
}
else
{

string operand_2=s.top();
s.pop();
string operand_1=s.top();
s.pop();
s.push("("+operand_1+ch+operand_2+")");

}
k++;
}
infix1=s.top();
s.pop();
return infix1;
}


string postfix2prefix(char postfix1[],int size)
{
string prefix1;
stack<string> s;
int k=0;
while(k<size)
{
char ch=postfix1[k];
int weight=getWeight(ch);
if(weight==0)
{
string e;
e=ch;
s.push(e);
}
else
{

string operand_2=s.top();
s.pop();
string operand_1=s.top();
s.pop();
s.push(ch+operand_1+operand_2);

}
k++;
}
prefix1=s.top();
s.pop();
return prefix1;
}



string prefix2infix(char prefix1[],int size)
{
string infix1;
stack<string> s;
int k=size-1;
while(k>=0)
{
char ch=prefix1[k];
int weight=getWeight(ch);
if(weight==0)
{
string e;
e=ch;
s.push(e);
}
else
{

string operand_1=s.top();
s.pop();
string operand_2=s.top();
s.pop();
s.push("("+operand_1+ch+operand_2+")");

}
k--;
}
infix1=s.top();
s.pop();
return infix1;
}

string prefix2postfix(char prefix1[],int size)
{
string postfix1;
stack<string> s;
int k=size-1;
while(k>=0)
{
char ch=prefix1[k];
int weight=getWeight(ch);
if(weight==0)
{
string e;
e=ch;
s.push(e);
}
else
{

string operand_1=s.top();
s.pop();
string operand_2=s.top();
s.pop();
s.push(operand_1+operand_2+ch);

}
k--;
}
postfix1=s.top();
s.pop();
return postfix1;
}


// main
int main() 
{
char ch;
int c,size;
char infix[20],postfix[20],prefix[20],postfix1[20],prefix1[20];
string infix1,prefix2,postfix2;
do{
cout<<">>>>>>>>>>EXPRESSION CONVERSION<<<<<<<<<<<<\n";
cout<<"1]infix to other\n";
cout<<"2]postfix to other\n";
cout<<"3]prefix to other\n";
cout<<"4]Exit\n";
cout<<"\nENTER YOUR CHOISE :";
cin>>c;
if(c!=4){
switch(c)
{
case 1:
   
   cout<<"insert Infix Expression: ";
   cin>>infix;
   size = strlen(infix);
   infix2postfix(infix,postfix,size);
   infix2prefix(infix,prefix,size);
   cout<<"\nInfix Expression :: "<<infix;
   cout<<"\nPostfix Expression :: "<<postfix;
   cout<<"\nPrefix Expression :: ";
   
   for(int i=strlen(prefix)-1;i>=0;i--)
   {
   cout<<prefix[i];
   }
   cout<<endl<<endl;
   break;
case 2:
   
   cout<<"insert postfix Expression: ";
   cin>>postfix1;
   size = strlen(postfix1);
   infix1 = postfix2infix(postfix1,size);
   prefix2=postfix2prefix(postfix1,size);
   cout<<"\nPostfix Expression :: "<<postfix1;
   cout<<"\nInfix Expression :: "<<infix1;
   cout<<"\nPrefix Expression :: "<<prefix2;
   cout<<endl<<endl;
break;
case 3:
   
   cout<<"insert pretfix Expression: ";
   cin>>prefix1;
   size = strlen(prefix1);
   infix1 = prefix2infix(prefix1,size);
   postfix2=prefix2postfix(prefix1,size);
   cout<<"\nPrefix Expression :: "<<prefix1;
   cout<<"\nInfix Expression :: "<<infix1;
   cout<<"\nPostfix Expression :: "<<postfix2;
   cout<<endl<<endl;
break;
case 4:

   break;

}
cout<<"do you want to continue :";
cin>>ch;}
}while(ch=='y');
   
   return 0;
}

C++ Projects: Theater Seat Booking system

Ticket Booking System in c++

This program is a implementation of Ticket Booking System using Doubly Circular Linked List. Data structures used in the program- Doubly Circular Linked List.
Why Dcll?
We know that in theatres more than 200 seats are there, Now if our head pointer points to the seat number ‘A1’ & user want to perform some operation with seat number ‘J1’ then it will be very much time consuming task ,as we need to traverse whole linked list from A1 to J7.








































Now when we use Doubly circular Linked List all seats are connected in a ring fasion so we can directly move from seat A1 to J7 using previous pointer as in previous pointer of head node address of seat J7 is stored.
















So lots of time gets saved which increases efficiency of the system.
FUNCTIONS USED : -
1] create() :- To create 70 nodes internally ( in memory ), each node represent one seat.Each node has 6 parameters
1) previous pointer of node* type to store address of previous node;
2) next pointer of node* type to store address of next node;
3) seat_no- to store seat number (int type)
4) row_no- to store row no(char type)
5)booking status- to show wether seat is alredy booked or available for booking(char type)
6)pin- different pin for each seat(int type)
So this function will create 70 nodes in memory locations & it will assign each node a
seat_no,booking_status and pin.
2] display() :- To display the seating arrangement ie to display the linked list.
The display will show row number followe by seat no followe by booking status (‘a’ or ‘b’ -> available/booked) of each seat/node.
“In display additional lines of codes are added to make display more powerful for LINUX TERMINAL”

inux terminal output of display function
3] book_seat() :- it will take input from user as seat no. If booking status of that seat is ‘a’  then avaibility status of that seat will change from (a) to (b) . else it will show an error message. If Seat is booked succesfully the it will display pin for each seat.


Linux terminal output of book_seat function

4] cancle_seat() :- the purpose of assigning pin to each seat is only one who has booked the seat can cancle it. So at the time of cancelation pins are required .
Now at cancelation time it wil ask for seat number and pin if seat number and pin combination matches and the avaibility status of that seat is booked then that seat will be cancled. Else it will give an error message.


Linux terminal output of cancle_seat() function

“RUN THIS CODE IN LINUX TERMINAL FOR BETTER OUTPUT EXPIRENCE”

CODE(for linux environment)

/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
DEVELOPER: RUSHIKESH SANJAY PHALKE
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
#include<iostream>
using namespace std;

typedef struct node
{
char row_no;
int seat_no,pin;
char book;
struct node *next,*prev;
}node;

class dcll
{
public:
node *hn;
dcll()
{
hn=NULL;
}
public:
void create()
{
node *nn,*cn;
int j=1;
volatile int k=2;
char c ='A';

do
{
int i=1;
do
{
k=(k*k)/10+100-k/2;
nn=new node();
nn->next=nn->prev=NULL;
nn->row_no=c;
nn->seat_no=i;
nn->pin=k;
nn->book='a';
if(hn==NULL)
{
hn=nn;
nn->next=nn->prev=hn;
}
else
{
cn=hn;

while(cn->next!=hn)
cn=cn->next;

cn->next=nn;
nn->prev=cn;
nn->next=hn;
hn->prev=nn;
}
i++;
}while(i<=7);
j++;
c++;
}while(j<=10);
}

void display()
{
node *cn;
cn=hn;
cout<<"------------------------------------------------------------------\n";
cout<<"|                            Platinum                            |\n";
while(cn->next!=hn)
{
if((cn->prev)->row_no!=cn->row_no)
cout<<"| ";
cout<<cn->row_no;
cout<<cn->seat_no;
if(cn->book=='a')
cout << "\033[32;40m -> a  \033[0m";  //green text with black background
else
cout << "\033[1;31;43m -> b  \033[0m";  //red text
if((cn->next)->row_no!=cn->row_no)
cout<<"|\n";
if(cn->row_no=='C'&&cn->seat_no==7)
{
cout<<"------------------------------------------------------------------\n";
cout<<"|                             gold                               |\n";
}
if(cn->row_no=='H'&&cn->seat_no==7)
{
cout<<"------------------------------------------------------------------\n";
cout<<"|                            Silver                              |\n";
}
cn=cn->next;
}
cout<<cn->row_no;
cout<<cn->seat_no;
if(cn->book=='a')
cout << "\033[32;40m -> a  \033[0m";  //green text with black background

else
cout << "\033[1;31;43m -> b  \033[0m";  //red text
cout<<"|\n";

cout<<"------------------------------------------------------------------\n\n";
cout<<"\033[1;33;49mPLATINUM-> 150              GOLD-> 100                  SILVER->60\033[0m\n";
}

void display1(node *tmp[20],int n)
{
if(n!=1)
{
cout<<"------------------------------------------------------------------\n";
cout<<"THANK YOU!\nYOU HAVE SUCCESFULLY BOOKED THE SEATS\n";
for(int i=1;i<n;i++)

cout<<tmp[i]->row_no<<tmp[i]->seat_no<<"    PIN : "<<tmp[i]->pin<<"\n";

cout<<"!!!!!!!!!!!!!!!!!!KEEP PIN SAFELY!!!!!!!!!!!!!!!!!!!\n";
cout<<"PINS ARE REQUIRED AT THE TIME OF CANCELATION OF SEATS\n";
cout<<"------------------------------------------------------------------\n";
}
}
void book_seat()
{
node *cn,*temp[20];
int n,z,flag;
char row;
int seat;
char ch;
do
{
z=1;
cout<<"\nEnter No Of Tickets u Want To Buy: ";
cin>>n;

cout<<"\nEnter Seat Number(s): \n";

for(int i=1;i<=n;i++)
{
cout<<"NO "<<i<<" = "; 
cin>>row>>seat;
cn=hn;
while(cn->next!=hn)
{
if(cn->row_no==row && cn->seat_no==seat)
{
if(cn->book=='a')
{
cn->book='b';
temp[z]=cn;
z++;
}
else
{
cout<<"INVALID CHOISE!\n";
cout<<cn->row_no<<cn->seat_no<<" Seat is alredy reserved \n";

}
}
cn=cn->next;
}
if(cn->row_no==row && cn->seat_no==seat)
{
if(cn->book=='a')
{
cn->book='b';
temp[z]=cn;
z++;
}
else
{
cout<<"INVALID CHOISE!\n";
cout<<cn->row_no<<cn->seat_no<<" Seat is alredy reserved\n";
}
}
}

display1(temp,z);
cout<<"\n\nPRESS 1 To check Seat Status\n";
cout<<"PRESS 2 To book other seat\n";
cout<<"PRESS 3 To Exit BOOKING PORTAL\n";
cout<<"\ninput: ";
cin>>ch;
if(ch==1)
display();
}while(ch=='2');
}

void cancle()
{
char row,ch;
int seat,pin;
node *cn;
do
{
ch='a';
cn=hn;
cout<<"SEAT NUMBRE :";
cin>>row>>seat;
cout<<"PIN :";
cin>>pin;
while(cn->next!=hn)
{
if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
{
cout<<"Are you sure u want to cancle the Seat (y/n) ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
cout<<"SEAT CANCELED SUCCESFULLY!\n";
cn->book='a';
}
}
else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
{
cout<<"invalid SEAT NUMBER && PIN combination!!!!\n";
}
cn=cn->next;
}
if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
{
cout<<"Are you sure u want to cancle (y/n) ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
cout<<"SEAT CANCELED SUCCESFULLY!\n";
cn->book='a';
}
}
else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
{
cout<<"invalid SEAT NUMBER && PIN combination!!!!\n";
}
cout<<"\n\nPRESS 1 To Check Seat Status\n"; 
cout<<"PRESS 2 To Cancle More Tickets\n";
cout<<"PRESS 3 To Exit CANCELATION PORTAL\n";
cout<<"\ninput: ";
cin>>ch;
if(ch==1)
display();
}while(ch=='2');
}
};


int main()
{
dcll o;
int ch;
char c;
cout<<"\n\n\n";
cout<<"                 @@@@@@   Cinemax  @@@@@@\n";
cout<<"                vvvvvv ARRANGEMENT vvvvvv\n\n";
o.create();
o.display();

do
{
cout<<"\n\n\n";
cout<<"PRESS 1-> BOOK TICKETS\n";
cout<<"PRESS 2-> CANCLE TICKETS\n";
cout<<"PRESS 3-> EXIT\n";
cout<<"\ninput: ";
cin>>ch;
switch(ch)
{
case 1:
o.book_seat();
o.display();
break;
case 2:
o.cancle();
o.display();
break;
}
if(ch!=3)
{
cout<<"\n\nPRESS 1 To Main Menu\n";
cout<<"PRESS 2 To Exit CINEMAX PORTAL\n";
cout<<"\ninput: ";
cin>>c;
}
}while(c=='1');
cout<<"\n\n\n";
return 0;
}

CODE(for windows+linux environment)


/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

DEVELOPER: RUSHIKESH SANJAY PHALKE

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/

#include<iostream>

using namespace std;



typedef struct node

{

char row_no;
int seat_no,pin;
char book;
struct node *next,*prev;
}node;

class dcll
{
public:
node *hn;
dcll()
{
hn=NULL;
}
public:
void create()
{
node *nn,*cn;
int j=1;
volatile int k=2;
char c ='A';

do
{
int i=1;
do
{
k=(k*k)/10+100-k/2;
nn=new node();
nn->next=nn->prev=NULL;
nn->row_no=c;
nn->seat_no=i;
nn->pin=k;
nn->book='a';
if(hn==NULL)
{
hn=nn;
nn->next=nn->prev=hn;
}
else
{
cn=hn;

while(cn->next!=hn)
cn=cn->next;

cn->next=nn;
nn->prev=cn;
nn->next=hn;
hn->prev=nn;
}
i++;
}while(i<=7);
j++;
c++;
}while(j<=10);
}

void display()
{
node *cn;
cn=hn;
cout<<"------------------------------------------------------------------\n";
cout<<"|                            Platinum                            |\n";
while(cn->next!=hn)
{
if((cn->prev)->row_no!=cn->row_no)
cout<<"| ";
cout<<cn->row_no;
cout<<cn->seat_no;
if(cn->book=='a')
cout << " -> a  ";  //green text with black background
else
cout << " -> b  ";  //red text
if((cn->next)->row_no!=cn->row_no)
cout<<"|\n";
if(cn->row_no=='C'&&cn->seat_no==7)
{
cout<<"------------------------------------------------------------------\n";
cout<<"|                             gold                               |\n";
}
if(cn->row_no=='H'&&cn->seat_no==7)
{
cout<<"------------------------------------------------------------------\n";
cout<<"|                            Silver                              |\n";
}
cn=cn->next;
}
cout<<cn->row_no;
cout<<cn->seat_no;
if(cn->book=='a')
cout << " -> a  ";  //green text with black background

else
cout << " -> b  ";  //red text
cout<<"|\n";

cout<<"------------------------------------------------------------------\n\n";
cout<<"PLATINUM-> 150              GOLD-> 100                  SILVER->60\n";
}

void display1(node *tmp[20],int n)
{
if(n!=1)
{
cout<<"------------------------------------------------------------------\n";
cout<<"THANK YOU!\nYOU HAVE SUCCESFULLY BOOKED THE SEATS\n";
for(int i=1;i<n;i++)

cout<<tmp[i]->row_no<<tmp[i]->seat_no<<"    PIN : "<<tmp[i]->pin<<"\n";

cout<<"!!!!!!!!!!!!!!!!!!KEEP PIN SAFELY!!!!!!!!!!!!!!!!!!!\n";
cout<<"PINS ARE REQUIRED AT THE TIME OF CANCELATION OF SEATS\n";
cout<<"------------------------------------------------------------------\n";
}
}
void book_seat()
{
node *cn,*temp[20];
int n,z,flag;
char row;
int seat;
char ch;
do
{
z=1;
cout<<"\nEnter No Of Tickets u Want To Buy: ";
cin>>n;

cout<<"\nEnter Seat Number(s): \n";

for(int i=1;i<=n;i++)
{
cout<<"NO "<<i<<" = "; 
cin>>row>>seat;
cn=hn;
if(row>='A'&&row<='E')
{
while(cn->next!=hn)
{
if(cn->row_no==row && cn->seat_no==seat)
{
if(cn->book=='a')
{
cn->book='b';
temp[z]=cn;
z++;
}
else
{
cout<<"INVALID CHOISE!\n";
cout<<cn->row_no<<cn->seat_no<<" Seat is alredy reserved \n";

}
}
cn=cn->next;
}
if(cn->row_no==row && cn->seat_no==seat)
{
if(cn->book=='a')
{
cn->book='b';
temp[z]=cn;
z++;
}
else
{
cout<<"INVALID CHOISE!\n";
cout<<cn->row_no<<cn->seat_no<<" Seat is alredy reserved\n";
}
}
}
else //
{
while(cn->prev!=hn)
{
if(cn->row_no==row && cn->seat_no==seat)
{
if(cn->book=='a')
{
cn->book='b';
temp[z]=cn;
z++;
}
else
{
cout<<"INVALID CHOISE!\n";
cout<<cn->row_no<<cn->seat_no<<" Seat is alredy reserved \n";

}
}
cn=cn->prev;
}
if(cn->row_no==row && cn->seat_no==seat)
{
if(cn->book=='a')
{
cn->book='b';
temp[z]=cn;
z++;
}
else
{
cout<<"INVALID CHOISE!\n";
cout<<cn->row_no<<cn->seat_no<<" Seat is alredy reserved\n";
}
}
}

}

display1(temp,z);
cout<<"\n\nPRESS 1 To check Seat Status\n";
cout<<"PRESS 2 To book other seat\n";
cout<<"PRESS 3 To Exit BOOKING PORTAL\n";
cout<<"\ninput: ";
cin>>ch;
if(ch==1)
display();
}while(ch=='2');
}

void cancle()
{
char row,ch;
int seat,pin;
node *cn;
cout<<"SEAT CANCELATION\n";
do
{
ch='a';
cn=hn;
cout<<"SEAT NUMBRE :";
cin>>row>>seat;
cout<<"PIN :";
cin>>pin;
if(row>='A'&&row<='E')
{
while(cn->next!=hn)
{
if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
{
cout<<"Are you sure u want to cancle the Seat (y/n) ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
cout<<"SEAT CANCELED SUCCESFULLY!\n";
cn->book='a';
}
}
else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
{
cout<<"invalid SEAT NUMBER && PIN combination!!!!\n";
}
cn=cn->next;
}
if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
{
cout<<"Are you sure u want to cancle (y/n) ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
cout<<"SEAT CANCELED SUCCESFULLY!\n";
cn->book='a';
}
}
else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
{
cout<<"invalid SEAT NUMBER && PIN combination!!!!\n";
}
}
else
{
while(cn->next!=hn)
{
if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
{
cout<<"Are you sure u want to cancle the Seat (y/n) ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
cout<<"SEAT CANCELED SUCCESFULLY!\n";
cn->book='a';
}
}
else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
{
cout<<"invalid SEAT NUMBER && PIN combination!!!!\n";
}
cn=cn->next;
}
if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
{
cout<<"Are you sure u want to cancle (y/n) ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
cout<<"SEAT CANCELED SUCCESFULLY!\n";
cn->book='a';
}
}
else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
{
cout<<"invalid SEAT NUMBER && PIN combination!!!!\n";
}
}
cout<<"\n\nPRESS 1 To Check Seat Status\n"; 
cout<<"PRESS 2 To Cancle More Tickets\n";
cout<<"PRESS 3 To Exit CANCELATION PORTAL\n";
cout<<"\ninput: ";
cin>>ch;
if(ch==1)
display();
}while(ch=='2');
}
};


int main()
{
dcll o;
int ch;
char c;
cout<<"\n\n\n";
cout<<"                 @@@@@@   Cinemax  @@@@@@\n";
cout<<"                vvvvvv ARRANGEMENT vvvvvv\n\n";
o.create();
o.display();

do
{
cout<<"\n\n\n";
cout<<"PRESS 1-> BOOK TICKETS\n";
cout<<"PRESS 2-> CANCLE TICKETS\n";
cout<<"PRESS 3-> EXIT\n";
cout<<"\ninput: ";
cin>>ch;
switch(ch)
{
case 1:
o.book_seat();
o.display();
break;
case 2:
o.cancle();
o.display();
break;
}
if(ch!=3)
{
cout<<"\n\nPRESS 1 To Main Menu\n";
cout<<"PRESS 2 To Exit CINEMAX PORTAL\n";
cout<<"\ninput: ";
cin>>c;
}
}while(c=='1');
cout<<"\n\n\n";
return 0;

}