Skip to main content

Posts

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;    ...

DSL

12: Problem Statement: A double-ended queue(deque) is a linear list in which additions and deletions may be made at either end. Obtain a data representation mapping a deque into a one-dimensional array. Write C++ program to simulate deque with functions to add and delete elements from either end of the deque. #include<iostream> using namespace std; class Deque{ public: Deque(); void AddRight(int x); void AddLeft(int x); void DeleteLeft(); void DeleteRight(); void print(); private: int x[20]; int front; int rear; }; Deque::Deque() { front=-1; rear=-1; } void Deque::AddRight(int val) { if(front==-1 && rear==-1) { rear++; x[rear]=val; front=0; } else{ rear++; x[rear]=val; } } void Deque::AddLeft(int val) { if(front==-1 && rear==-1) { AddRight(val); } else{ rear++; int a[rear]={0,}; for(int i=front;i<=rear;++i) { a[i+1]=x[i]; } a[front]=val; for(int i=0;i<=rear;++i...

DSL

11: Problem Statement: Queues are frequently used in computer programming, and a typical example is the creation of a job queue by an operating system. If the operating system does not use priorities, then the jobs are processed in the order they enter the system. Write C++ program for simulating job queue. Write functions to add job and delete job from queue. Program Code: #include <iostream> using namespace std; #define size 5 class spq {     int f,r,job,djob;            //data members     int simpq[size],prioq[size]; public:     spq() //Default constructor     {      f=r=-1; //init front and rear to -1.      job=djob=0;      prioq[-1]=0;     }     //To check Q is full or not     int isQfull()     {         if(r==size-1)             return 1;   ...

DSL

10: Problem Statement: A classic problem that can be solved by backtracking is called the Eight Queens problem, which comes from the game of chess. The chess board consists of 64 square arranged in an 8 by 8 grid. The board normally alternates between black and white square, but this is not relevant for the present problem. The queen can move as far as she wants in any direction, as long as she follows a straight line, Vertically, horizontally, or diagonally. Write C++ program with recursive function for generating all possible configurations for 4-queen's problem. #include<iostream> using namespace std; class queen { int n; public: void read() { cout<<"Enter board size\n"; cin>>n; } bool place(int x[10],int k) { for(int i=1;i<k;i++) { if(x[i] == x[k] || i+x[i] == k+x[k] || i-x[i] == k-x[k]) return false; } return true; } void nqueen() { int x[10]; int k=1; x[k]=0; while(k!=0) { x[k]++; while(...

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 ...

DSL

8: Problem statement: Write C++ program for storing binary number using doubly linked lists. Write functions- a) to compute 1‘s and 2‘s complement b) add two binary numbers #include <iostream> #include<vector> using namespace std; struct node { int data; node* next; node* prev; }; node* Create(int x) { node* temp=new node; temp->data=x; temp->next=NULL; temp->prev=NULL; return temp; } void Insert(node** head,int x) { node *temp=Create(x); if(*head==NULL) { *head=temp; } else { (*head)->prev=temp; temp->next=*head; *head=temp; } } void print(node* head) { node* temp=head; cout<<"\ndata: "; while(temp!=NULL) { cout<<temp->data<<" "; temp=temp->next; } cout<<endl; } int sum(int a,int b,int c) { return a^b^c; } int carry(int a,int b,int c) { int x=a*b; int y=b*c; int z=c*a; int s=sum(x,y,z); return s; } ...

DSL

7: Program Statement Second year Computer Engineering class, set A of students like Vanilla Ice-cream and set B of students like butterscotch ice-cream. Write C/C++ program to store two sets using linked list. compute and display- i. Set of students who like either vanilla or butterscotch or both ii. Set of students who like both vanilla and butterscotch iii. Set of students who like only vanilla not butterscotch iv. Set of students who like only butterscotch not vanilla v. Number of students who like neither vanilla nor butterscotch Program: #include<stdio.h> #include<stdlib.h> typedef struct node {     int data;     struct node *next; }node; node *createnode() {     int n,i;     node *p,*head,*t;     head=NULL;     printf("enter the no of students");     scanf("%d",&n);     for(i=0;i<n;i++)     {         p=(node*)malloc(sizeof(node)...