Skip to main content

OOP

23.Problem statement

    C++ Program to Implement Deque in Stl

     Program

    #include <iostream>

    #include <deque>

    #include <string>

    #include <cstdlib>

    using namespace std;

    int main()

    {

        deque<int> dq;

        deque<int>::iterator it;

        int choice, item;

        while (1)

        {

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

            cout<<"Deque Implementation in Stl"<<endl;

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

            cout<<"1.Insert Element at the End"<<endl;

            cout<<"2.Insert Element at the Front"<<endl;

            cout<<"3.Delete Element at the End"<<endl;

            cout<<"4.Delete Element at the Front"<<endl;

            cout<<"5.Front Element at Deque"<<endl;

            cout<<"6.Last Element at Deque"<<endl;

            cout<<"7.Size of the Deque"<<endl;

            cout<<"8.Display Deque"<<endl;

            cout<<"9.Exit"<<endl;

            cout<<"Enter your Choice: ";

            cin>>choice;

            switch(choice)

            {

            case 1:

                cout<<"Enter value to be inserted at the end: ";

                cin>>item;

                dq.push_back(item);

                break;

            case 2:

                cout<<"Enter value to be inserted at the front: ";

                cin>>item;

                dq.push_front(item);

                break;

            case 3:

                item = dq.back();

                dq.pop_back();

                cout<<"Element "<<item<<" deleted"<<endl;

                break;

            case 4:

                item = dq.front();

                dq.pop_front();

                cout<<"Element "<<item<<" deleted"<<endl;

                break;

            case 5:

                cout<<"Front Element of the Deque: ";

                cout<<dq.front()<<endl;

                break;

            case 6:

                cout<<"Back Element of the Deque: ";

                cout<<dq.back()<<endl;

                break;

            case 7:

                cout<<"Size of the Deque: "<<dq.size()<<endl;

                break;

            case 8:

                cout<<"Elements of Deque:  ";

                for (it = dq.begin(); it != dq.end(); it++)

                    cout<<*it<<"  ";

                cout<<endl;

                break;

            case 9:

                exit(1);

                break;

            default:

                cout<<"Wrong Choice"<<endl;

            }

        }

        return 0;

    }

Comments

Popular posts from this blog

DSL

9: Program Setatement A palindrome is a string of character that‘s the same forward and backward. Typically, punctuation, capitalization, and spaces are ignored. For example, ‖Poor Dan is in a droop‖ is a palindrome, as can be seen by examining the characters ―poor danisina droop‖ and observing that they are the same forward and backward. One way to check for a palindrome is to reverse the characters in the string and then compare with them the original-in a palindrome, the sequence will be identical. Write C++ program with functions- 1. to check whether given string is palindrome or not that uses a stack to determine whether a string is a palindrome. 2. to remove spaces and punctuation in string, convert all the Characters to lowercase, and then call above Palindrome checking function to check for a palindrome 3. to print string in reverse order using stack Program: #include<iostream> #include<string.h> #define MAX 100 using namespace std;  struct stack ...

OOP

6.Problem statement 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. Program #include<iostream> #include<stdio.h> #include<cstring> using namespace std; class personal; static int count; class person {       char *name;       int *rollno,*classno;       char *bloodgroup,*div;                   public:person()              {     ...

DSL

13: Problem Statement: Pizza parlor accepting maximum M orders. Orders are served in first come first served basis. Order once placed cannot be cancelled. Write C++ program to simulate the system using circular queue using array. Program Code: #include <iostream> using namespace std; #define size 5 class pizza {     int porder[size];     int front,rear; public:     pizza()     {      front=rear=-1;     }     int qfull()     {      if((front==0)&&(rear==(size-1))||(front==(rear+1)%size))          return 1;      else          return 0;     }     int qempty()     {         if(front==-1)             return 1;         else             return 0;    ...