Posts

Showing posts from October, 2016

Fibonacci Search in C++.

#include <iostream> #include<cstring> #include<cstdio> #include<cstdlib> using namespace std; int n; struct person {     char name[20];     long ph;; }p[20]; void getdata(struct person p[],int n) {     for(int i=0;i<n;i++)     {         cout<<"Enter name\n";         cin>>p[i].name;         cout<<"enter cntact\n";         cin>>p[i].ph;     } } void putdata(struct person p[],int n) {     for(int i=0;i<n;i++)     {         cout<<"name: "<<p[i].name<<endl;         cout<<"contact: "<<p[i].ph<<endl;     } } void sort(struct person p[],int n) {     int i,j,k;     struct person q; ...

Develop an object oriented program in C++ to create a database of student information.

#include<iostream> #include<cstring> using namespace std; class Studdb1 { private:     long mo_no;     string lno;             public:     int roll_no,cls;     string add,bldgrp,dob;     char div;     //void end();     Studdb1()         {         roll_no=0;         dob="null";         mo_no=0000;         lno="null";         cls=0;         add="null";         bldgrp="null";         div='\0';     }         Studdb1(int roll_no,int cls,char div,string dob,string bldgrp,string add,long mo_no,string lno)   ...

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

#include<iostream> #include<limits> using namespace std; template<class T>                                T selection_sort()        //Template function         {         T a[10];         T temp;         for(int i=0;i<10;i++)        //Accepting elements             {                 cout<<"a["<<i<<"]=";                 cin>>a[i];             }                     ...

Using standard template library (STL) list container implement following member functions of list class: empty, insert, merge, reverse, sort, Unique, using iterator.

#include<iostream> #include<algorithm> #include<list> using namespace std; int main() {     char ans;     list<int>l1,l2;     int ch;     int temp;     list<int>::iterator v;     cout<<"\n1: Accept";     cout<<"\n2: Display";     cout<<"\n3:Merging list";     cout<<"\n4:Sorting lists";     cout<<"\n 5:Unique lists";     cout<<"\n6:Reverse list";     cout<<"\n7: Clear lists"; do {     cout<<"\nEnter the choice";     cin>>ch;     switch(ch)     {         case 1:            //Accept list         {             cout<<"\...

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.

#include<fstream> #include<iostream> #include<cstring> #include<iomanip> using namespace std; int main() { int n,cnt=0; char name[10],aname[10]; char id[10],findid[10]; int ch; char ans; ofstream fout; ifstream fin;         // Writing data into file.......             fout.open("data1.txt");         if(!fout)         {             cout<<"Error in opening file ";             return 0;         }         cout<<"File created successfully...\n";                 cout<<"How many no of records you want to insert: ";         cin>>n;         for(int i...

Implement a class CppArray which is identical to a one-dimensional C++ array (i.e., the index set is a set of consecutive integers starting at 0) except for the following : 1. It performs range checking. 2.It allows one to be assigned to another array through the use of assignment operator. 3.It supports a function that returns the size of the array.

#include<iostream> #include<math.h> using namespace std; class array {      int a[10],b[10],i,j,temp,n;           public:             void accept();             void display();             void range();             void sort();             void exchange();             int size(); }; void array::accept() {     cout<<"How many Elements you want to insert into the array=\n";     cin>>n;     cout<<"Enter the array Elements=\n";     for(i=0;i<n;i++)        {             cout<<...

Title : = 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.

/*Title : = 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.*/ #include<iostream> using namespace std; int main() { int a,c,b; char ch; cin>>a; cin>>ch; cin>>b; switch(ch) {     case '+':        //Addition                 c=a+b;         cout<<c;         break;     case '-':        //Subtraction                 c=a-b;         cout<<c;         break;     case '*':        //Multiplication      ...