Skip to main content

Posts

DSL

14.Problem statement Write C++ program to store roll numbers of student in array who attended training program in random order. Write function for-  a) Searching whether particular student attended training program or not using linear search and sentinel search.  b) Searching whether particular student attended training program or not using binary search and Fibonacci search.    program #include<iostream> using namespace std; class search {  public:         int n,i,data[50],son[50],sortdata[50],s;  void intake() {     cout<<"Enter No. of Elements=";   cin>>n;   cout<<"\nEnter Elements=\n";   for(i=1;i<=n;i++)   {   cin>>data[i];       son[i]=data[i];   } } void search_lini(int item) {   s=0;   for(i=1;i<=n;i++)   {  if(data[i]==item) ...

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()              {     ...

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

OOP

21.Problem statement  Write C++ program using STL for implementation of stack & queue using SLL Program #include<iostream> #include<stack> #include<stdlib.h> using namespace std; void display(stack<int>s) { cout<<"\nElement in stack are:- "; while(!s.empty()) { cout<<s.top()<<"  "; s.pop(); } } int main() { stack<int>s; int choice,t; int x; while(1) { cout<<"\n\n*********************************"; cout<<"\n        STACK USING STL"; cout<<"\n*********************************"; cout<<"\n\n1.Push data"; cout<<"\n2.Pop data"; cout<<"\n3.Size of stack"; cout<<"\n4.First Element"; cout<<"\n5.Display Element in stack"; cout<<"\n6.Exit"; cout<<"\nEnter Your choice:- "; cin>>choice;...

OOP

14.Problem statement Crete User defined exception to check the following conditions and throw the exception if the criterion does not meet. a. User has age between 18 and 55 b. User stays has income between Rs. 50,000 – Rs. 1,00,000 per month c.  User stays in Pune/ Mumbai/ Bangalore / Chennai d. User has 4-wheeler  Accept age, Income, City, Vehicle from the user and check for the conditions mentioned above. If any of the condition not met then throw the exception. Program #include<iostream> #include<string.h> using namespace std; class user { public: char vehicle; int salary,age; string city; user() { age=0; vehicle=0; salary=0; } void getdata(); }; void user::getdata() { cout<<"Enter Age Of Person:- "; cin>>age; if(age<18 || age>55) { throw 1; } cout<<"Enter Salary For Permonth:- "; cin>>salary; if(...

DSL

17: Problem statement: Write C++ program to store second year percentage of students in array. Write function for sorting array of floating point numbers in ascending order using a) Insertion sort b) Shell Sort and display top five scores. Program: #include<stdio.h> void insertion(float [],int); void shell(float[],int); int main() {     int i, n,op;     float a[30];     do     {         printf("\n 1)Insertion Sort \n 2) Shell Sort  \n 3) Quit");         printf("Enter your choice :");         scanf("%d",&op);         if(op==1)         {             printf("\n Enter no. of elements :");             scanf("%d",&n);             printf("\n Enter Array elements :");             for(i=0;i...

DSL

16: Problem statement: Write C++ program to store first year percentage of students in array. Write function for sorting array of floating point numbers in ascending order using a) Selection Sort b) Bubble sort and display top five scores. Program: #include<stdio.h> void selection(float[],int); void bubble(float[],int); void main() {     int n,i,op;     float a[30];     do     {         printf("\n 1)Bubble sort \n 2)Selection sort \n 3)Quit");         printf("\n Enter your choice :");         scanf("%d", &op);         if(op==1)         {             printf("\n Enter no. of elements :");             scanf("%d",&n);             printf("\n Enter array elements :");             for(i=0;i<...

DSL

15: Problem statement: Write C++ program to store first year percentage of students in array. Sort array of floating point numbers in ascending order using quick sort and display top five scores. #include<stdio.h> void selection(float[],int); void bubble(float[],int); void main() {     int n,i,op;     float a[30];     do     {         printf("\n 1)Bubble sort \n 2)Selection sort \n 3)Quit");         printf("\n Enter your choice :");         scanf("%d", &op);         if(op==1)         {             printf("\n Enter no. of elements :");             scanf("%d",&n);             printf("\n Enter array elements :");             for(i=0;i<n;i++)               ...

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