Posts

Write a menu driven program that will create a data file containing the list of telephoneUse a class object to store each set of data, access the file created and implement the following tasks Determine the telephone number of specified person Determine the name if telephone number is known Update the telephone number, whenever there is a change.

Write a menu driven program that will create a data file containing the list of telephone numbers in the following form John 23456 Ahmed 9876 Use a class object to store each set of data, access the file created and implement the following tasks Determine the telephone number of specified person Determine the name if telephone number is known Update the telephone number, whenever there is a change. #include<iostream> #include<iomanip> #include<fstream> using namespace std; #include<string.h> class Person {     public:                   char name[10];                   int PhNo;                          void input_data()                 {                        cout<<"Enter the Name:";                        cin>> name;                        cout<<"Enter the PhNo:";                        cin>>PhNo;                 }                 void put_data()                {                        cout<<setw(10)<<na

Write C++ program using STL for Sorting and searching

/* Write C++ program using STL for Sorting and searching with user-defined records such as Person Record (Name, birth date, telephone no), item record (item code, item name, quantity and cost) */ #include <iostream>    //standard input output stream header file #include <algorithm>    //The STL algorithms are generic because they can operate on a variety of data structures #include <vector>    //The header file for the STL vector library is vector. using namespace std; class Item        {       public:              char name[10];         int quantity;         int cost;         int code;         bool operator==(const Item& i1)    //Boolean operators allow you to                                                         create more complex conditional statements     {         if(code==i1.code)    //operator will return 1 if the comparison is true, or 0 if                                          the comparison is false         return 1;         re

Write C++ program using STL for Dqueue (Double ended queue)

/* Write C++ program using STL for Dqueue (Double ended queue) */ #include<iostream> #include<deque> using namespace std; int main() {     int x;     char ans;     int ch;         deque<int>dq;     deque<int>::iterator i;     do{         cout<<"\nMain Menu";         cout<<"\n1.Insert from rear";         cout<<"\n2.Insert from front";         cout<<"\n3.Delete front";         cout<<"\n4.Delete rear";         cout<<"\n5.Size of deque";         cout<<"\n6.Display elements";         cout<<"\n0.Exit";         cout<<"\nEnter the choice:";         cin>>ch;                 switch(ch)         {             case 1:                 cout<<"\nEnter element:";                 cin>>x;                 dq.push_back(x);                 break;                             case 2:                 cout<<&quo

Write C++ program using STL to add binary numbers use STL stack.

/* Write C++ program using STL to add binary numbers (assume one bit as one number); use STL stack. */ #include <iostream> #include<stack> using namespace std; int main() {     stack<int>A;     stack<int>B;     stack<int>C;         char first[10],sec[10];     int i;     int a,b;         cout<<"Enter 1st Binary number:";     cin>>first;     for(i=0;first[i]!='\0';i++)     {         if(first[i]==0)         {             A.push(0);         }         else         {             A.push(1);         }     }         cout<<"Enter 2nd Binary number:";     cin>>sec;     for(i=0;sec[i]!='\0';i++)     {         if(sec[i]==0)         {             B.push(0);         }         else         {             B.push(1);         }        }     int carry=0;         while(!A.empty()||!B.empty())     {         a=0,b=0;         if(!A.empty())         {             a=A.top();             A.pop();         }         if(!B.emp

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

  Write a function template selection Sort. Write a program that inputs, sorts and outputs an integer array and a float array. #include<iostream> using namespace std; int n; #define size 10 template<class T> void sel(T A[size]) {     int i,j,min;     T temp;     for(i=0;i<n-1;i++)     {         min=i;         for(j=i+1;j<n;j++)         {             if(A[j]<A[min])             min=j;         }         temp=A[i];         A[i]=A[min];         A[min]=temp;     }     cout<<"\nSorted array:";     for(i=0;i<n;i++)     {         cout<<" "<<A[i];     } } int main() {     int A[size];     float B[size];     int i;         cout<<"\nEnter total no of int elements:";     cin>>n;     cout<<"\nEnter int elements:";     for(i=0;i<n;i++)     {         cin>>A[i];     }     sel(A);         cout<<"\nEnter total no of float elements:";

C++ program that creates an output file, writes information to it, closes the file and open it again as an input file and read the information from the file.

Image
/* Write a C++ program that creates an output file, writes information to it, closes the file and open it again as an input file and read the information from the file. */ #include<iostream> #include<fstream> using namespace std; class Employee {     char Name[20];     int ID;     double salary;     public:         void accept()         {             cin>>Name;             cin>>ID;             cin>>salary;         }         void display()         {             cout<<"\n Enter Name:"<<Name;             cout<<"\n Enter Id:"<<ID;             cout<<"\n Enter Salary:"<<salary;         } };         int main() {     Employee o[5];     fstream f;     int i,n;         f.open("b16.txt");     cout<<"\n How many employee information do you need to store?";     cin>>n;     cout<<"\n Enter information of employee in this form

exception handling in c++

/* 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. */ #include<iostream> #include<stdexcept> #include<typeinfo>    //header file for type operation of RTTI(return type type                                        identification) #include<string> #include<cstring> using namespace std; int main() {     int i,j,n,age;     char car;     double income;     char city[20];         cout<<"\nEnter age:";     cin>>age;     try     {         if(age<18||age>55)         throw runtime_error("\nEnter proper age");