Posts

Showing posts from October, 2019

Write a function template selection Sort. Write a program that inputs, sorts and outputs an integer array and a float array.

Image
Write a function template selection Sort. Write a program that inputs, sorts and outputs an integer array and a float array. #include<iostream> OUTPUT FOR THE PROGRAM using namespace std; #define size 10 int n; template<class T> void selection(T a[size]) { int i,j,k; T temp; for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(a[j]<a[i]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } cout<<"\nAfter pass"<<i+1<<" :"; for(k=0;k<n;k++) { cout<<a[k]; } } for(i=0;i<n;i++) { cout<<"\nAfter sorting is:"<<a[i]; } } int main() { int i; int a[size]; float b[size]; cout<<"\nHow many integers: "; cin>>n; cout<<"\nEnter the values: \n"; for(i=0;i<n;i++) { cin>>a[i]; } selection(a); cout<<"\nHow many floats: "; cin>>n; cout<<&q

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

Image
Create 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. OUTPUT FOR THE PROGRAM #include<iostream> #include<string.h> using namespace std; int main() { int age; double income; char city[10]; long int vehicle; cout<<"\nEnter the age: "; cin>>age; cout<<"\nEnter the income: "; cin>>income; cout<<"\nEnter the city: "; cin>>city; cout<<"\nEnter the vehicle(2/4): "; cin>>vehicle; try { if(age<18 || age>55) throw age; else cout<<"

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

Image
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. OUTPUT FOR THE PROGRAM #include<iostream> #include<string.h&g

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

Image
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 OUTPUT FOR THE PROGRAM #include<iostream> using namespace std; int main() { int i,j,ans; float div; char ch,con; cout<<"\nEnter first number: "; cin>>i; cout<<"\nEnter second number: "; cin>>j; do { cout<<"\nEnter the operator(+,-,/,*): "; cin>>ch; switch(ch) { case '+': { ans=i+j; cout<<"\nAddition

Write a c++ program to implement deque using STL

Image
Write a c++ program to implement deque using STL. OUTPUT FOR THE PROGRAM #include <iostream> #include <deque> 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;         co

Write c++ program using stl for implementation of stack & queue using STL

Image
Write c++ program using stl for implementation of stack & queue using STL. OUTPUT OF THE PROGRAM #include<iostream> #include<stack> #include<queue> using namespace std; int main() { int item,item1,choice; char con; stack<int> st; queue<int> q; do { cout<<"\n1)insert an element\n2)delete an element\n3)size of element\n4)display top & front element\n5)Back element"; cout<<"\nEnter your choice: "; cin>>choice; switch(choice) { case 1: { cout<<"\nEnter the element: "; cin>>item; item1=item; st.push(item); q.push(item1); break; }  case 2: { item = st.top(); item1=q.front();                 st.pop();                 q.pop(); cout<<"\nElement "<<item<<" has been deleted"; cout<<"\nElement "<<item1<<" has been deleted&

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.

Image
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<iostream> using namespace std; void quick_sort(float a[],int low,int high) OUTPUT FOR THE PROGRAM { int i,j; float pivot,temp; pivot=a[low]; i=low; j=high; while(i<j) { while(a[i]<=pivot) i++; while(a[j]>pivot && i<=j) j--; if(i<=j) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } temp=a[j]; a[j]=a[low]; a[low]=temp; cout <<"\n\n Pass"<<" : ";       for(i=0; i<5; i++)   cout <<a[i]<<"   ";           quick_sort(a, low , j-1); // Recursive Calls....for partition before pivot           quick_sort(a, j+1 , high); } int main() {    int i, size = 5;    float a[10];      cout<<"\n\n Enter the Percentages of 5 students : ";    for(i=0;

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 c) Insertion Sort and display top five scores.

Image
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 c) Insertion Sort and display top five scores. #include<iostream> using namespace std; OUTPUT FOR THE PROGRAM int n; float A[50]; int i,j; void input() { cout<<"Enter the No. of students: "; cin>>n; for(i=0;i<n;i++) { cout<<"\nEnter Data : "; cin>>A[i]; } } void display() { for(i=0;i<n;i++) cout<<"\n Data Is : "<<A[i]; } void bubble_sort() { int i,j,temp; input(); for(i=0;i<n-1;i++) { cout<<"Pass "<<i+1; for(j=0;j<n-1;j++) { if(A[j]>A[j+1]) { temp = A[j]; A[j] = A[j+1]; A[j+1] = temp; } } display(); cout<<"\n\n"; } display(); } void selection_sort() { int i,j,temp;

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 b) Searching whether particular student attended training program or not using binary search.

Image
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 b) Searching whether particular student attended training program or not using binary search. #include<iostream> using namespace std; int List[10]; int size; void input() { cout<<"Enter the No. of students"; cin>>size; cout<<"Enter the Roll no. of Students attending training program \n"; for(int i=0; i<size; i++) OUTPUT FOR THE PROGRAM { cin>>List[i]; } } void linearSearch() {     int i, Key, cnt = 0;       cout<<"\n\n Enter the Key to Search: ";     cin>>Key;       for(i=0; i<size; i++)     {         cnt++;         if(Key == List[i])         {             cout<<"\n\n Key Found.....!!!";             cout<<"\n\n No of Comparison

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.

Image
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. #include<iostream> #include<string> OUTPUT FOR THE PROGRAM using namespace std; char que[10]; int size=10; int front = -1, rear = -1; int que_empty() { if(front == rear || front == rear == -1) return 1; else return 0; } int que_full() { if(rear == size-1) return 1; else return 0; } char del_que() { front ++; return que[front]; } void insert(char ch) { rear ++; que[rear] = ch; } void display() { for(int i = front+1 ; i<=rear ; i++) cout<<"|"<<que[i]<<"|"; } int main() { char ch; int cnt; cout<<"Enter the No. of jobs