Skip to main content

Posts

Showing posts from September, 2017

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

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

DSL

6: Problem Statement: Department of Computer Engineering has student's club named 'Pinnacle Club'. Students of Second, third and final year of department can be granted membership on request. Similarly one may cancel the membership of club. First node is reserved for president of club and last node is reserved for secretary of club. Write C++ program to maintain club member‘s information using singly linked list. Store student PRN and Name. Write functions to a)Add and delete the members as well as president or even secretary. b)Compute total number of members of club c)Display members d)Display list in reverse order using recursion e) Two linked lists exists for two divisions. Concatenate two lists. Program Code: #include <iostream> #include<stdlib.h> #include<string.h> using namespace std; //data structure for student information i:e node struct node {  int prn;  char name[20];  node *next; }; class panclub {     int n...

DSL

5: Problem Statement: Write C++ program for string operations- copy, concatenate, check substring, equal, reverse and length #include<iostream> #include<cstdio> using namespace std; int Length(char str[50]) { int count=0,i=0; while(str[i]!='\0') { count++; i++; } return count; } void Palindrome(char str[50]) { int k=Length(str)-1; int i,p=0; while(str[i]!='\0') { if(str[i++]==str[k--]){ p=1; break; } } if(p==1) { printf("Entered string is Palindrome\n"); } else{ printf("Entered string is not palindrome\n"); } } void copy_string(char str[50]) { char ch[50]; printf("Enter second string which you want to copy!!\n"); scanf("%s",ch); int i=0; while(str[i]!='\0') { str[i]=ch[i]; i++; } printf("copied string is : %s \n",str); } ...

DSL

4: Problem Statement: Write C/C++ program for storing matrix. Write functions for  a) Check whether given matrix is upper triangular or not  b) Compute summation of diagonal elements  c) Compute transpose of matrix  d) Add, subtract and multiply two matrices #include<iostream> #include<cstdio> void Upper_Triangular(int a[10][10],int n,int m) { for(int i=0;i<n;i++){ printf("\n"); for(int j=0;j<m;j++) if(i>=j) printf(" %d ",a[i][j]); else printf(" %d ",0); } } void Addition(int a[10][10],int b[10][10],int m,int n) { int c[10][10],i,j; for(i=0;i<m;++i) { for(j=0;j<n;++j) { c[i][j]=0; c[i][j]+=a[i][j]+b[i][j]; } } printf("\nAddition Of two Matrix is : \n"); for(i=0;i<m;++i) { for(j=0;j<n;++j) { printf(" %d ",c[i][j]); } printf("\n"); } } void Dif...

DSL

3: Problem Statement: Set A=(1,3, a, s, t, i} represent alphanumeric characters permitted to set the password of length 4. Write C/C++ program to generate all possible passwords. #include<iostream> using namespace std; class passowrd {  char setA[6]={'1','3', 'a', 's', 't', 'i'}; public :  void combinations(); }; void passowrd::combinations() {  for(int i=0;i<6;i++)  {   for(int j=0;j<6;j++)   {    for(int k=0;k<6;k++)    {     for(int l=0;l<6;l++)     {      cout<<setA[i]<<setA[j]<<setA[k]<<setA[l];      cout<<"\n";     }   }  }  } } int main() {  passowrd p;  p.combinations(); }

DSL

2. Problem Statement: Write C/C++ program to store marks scored for first test of subject 'Data Structures and Algorithms' for N students. Compute I. The average score of class ii. Highest score and lowest score of class iii. Marks scored by most of the students iv. list of students who were absent for the test Program Code: (Implementation) #include <iostream> using namespace std; class Test {     int dsa[30],i,j,n,sum,cnt[50],k,rn[30]; //data members     float av; public:     Test()  //default constructor     {         i=j=n=0;         av=sum=k=0;     }     void getdata(); //member functions     void show();     void avg();     void Ab_stud();     void HS_LS();     void MS_score(); }; //end of class declaration //Function name: getdata() //return type: void //Parame...

DSL

1: Problem Statement: In Second year Computer Engineering class of M students, set A of students play cricket and set B of students play badminton. Write C/C++ program to find and display- i. Set of students who play either cricket or badminton or both ii. Set of students who play both cricket and badminton iii. Set of students who play only cricket iv. Set of students who play only badminton v. Number of students who play neither cricket nor badminton  (Note- While realizing the set duplicate entries are to avoided) Program Code: //Title: Cricket & Badminton #include <iostream> using namespace std; class game {     int c,b,m,i,j,k,cnt;     int setA[10],setB[10],setC[20],setD[20],setAB[20];     public:     game()     {         c=b=m=0;         i=j=k=0;         cnt=0; ...