Posts

Showing posts from October, 2018

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");    

create employee biodata using c++

/* Create employee biodata using following classes  i) Personal record ii)Professional record iii) Academic record  Assume appropriate data members and member function to accept required data & print bio data. Create biodata using multiple inheritance using C++. */ #include<iostream> using namespace std; class personal {   public:                   char name[20];          int age;          int date,month,year;          char gender;                     personal()          {            cout<<" Enter name :";            cin>>name;            cout<<" \n Enter age :";            cin>>age;            cout<<" \n Enter date of birth";            cin>>date>>month>>year;            cout<<"\n Enter gender(F/M)";            cin>>gender;          }          }; class professional {  public:          int id;          int d,m,y;                   professio

Write a function in C++ to count and display the number of lines not starting with alphabet 'A' present in a text file "STORY.TXT".

  Write a function in C++ to count and display the number of lines not starting with alphabet 'A' present in a text file "STORY.TXT". Example: If the file "STORY.TXT" contains the following lines, The roses are red. A girl is playing there. There is a playground. An aeroplane is in the sky. Numbers are not allowed in the password. The function should display the output as 3. #include<iostream> #include<fstream> using namespace std; int main() {     ifstream fin;     fin.open("Story.txt");         char str[100];     int count=0;     int count1=0;         while(!fin.eof())     {         fin.getline(str,100);         if(str[0]!='A')         {             count++;         }         else if(str[0]=='A'&&str[1]==' ')         {             count1++;         }     }         cout<<"The number of lines not starting with 'A' are:"<<count<<"\n";     cout<<"T

class template to represent a generic vector using c++

/* Create a class template to represent a generic vector. Include following member functions: 1. To create the vector. 2. To modify the value of a given element 3. To multiply by a scalar value 4. To display the vector in the form (10,20,30,...) */ #include<iostream> using namespace std; template<class T> class vector {     T v[20];     int size;         public:         void create();         void modify();         void mult();         void display(); }; template<class T> void vector<T>::create() {     int i;     T value;     char ans;     size=0;     do{         cout<<"\nEnter the index & value:";         cin>>i>>value;         v[i]=value;         size++;         cout<<"\nDo you want more elements?";         cin>>ans;     }while(ans=='y'||ans=='Y'); } template<class T> void vector<T>::modify() {     int key;     T newval;     cout<&

calculator using c++

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 #include<iostream> using namespace std; class calculator {     private:         float n1,n2,result;         char op;             public:         void get();         void calculate(); }; void calculator::get() {     cout<<"Enter 1st number"<<" "<<"operator"<<" "<<"Enter 2nd number:";     cin>>n1;     cin>>op;     cin>>n2; }

Operator Overloading (complex number) using c++

Implement a class Complex which represents the Complex Number data type. Implement the following operations: 1. Constructor (including a default constructor which creates the complex number 0+0i). 2. Overloaded operator+ to add two complex numbers. 3. Overloaded operator* to multiply two complex numbers. 4. Overloaded << and >> to print and read Complex Numbers. #include<iostream> using namespace std; class complex { public:     float real,img;     complex()     {     real=0;     img=0;     }     complex operator +(complex);     complex operator *(complex);     friend ostream &operator<<(ostream&,complex&);     friend istream &operator>>(istream&,complex&); }; complex complex::operator +(complex obj) {     complex temp;     temp.real=real+obj.real;     temp.img=img+obj.img;     return (temp); } complex complex::operator *(complex obj) {     complex temp;     temp.real=(real*obj.real)-(img*obj.img)