(27) Write a program that reads a text file and creates another file that is...
Share This Program..
send it gtumca@gmail.com
with your name - college name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
Shared By :your name Show/Hide Program
(28) Use Employee and EmpCollection classes. Employee class...
Share This Program..
send it gtumca@gmail.com
with your name - college name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
Shared By :your name Show/Hide Program
(29) Define a class Person. Have data members as name of the person,..
Share This Program..
send it gtumca@gmail.com
with your name - college name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
Shared By :your name Show/Hide Program
(30) Write a template function called find(). This function searches an...
Shared By : MAYANK DUDHATRA(SUN SHINE - RAJKOT)Show/Hide Program
/* gtu30
*/
# include <conio.h>
# include <iostream.h>
# define MAYANK 5
template <class T>
class vector
{
private:
T arr[MAYANK];
public:
void getvector();
void putvector();
int find(T);
};
template <class T>
void vector<T>::getvector()
{
for(int i=0;i<MAYANK;i++)
{
cout <<endl<<"\t Enter data=> ";
cin >> arr[i];
}
}
template <class T>
void vector<T>::putvector()
{
for(int i=0;i<MAYANK;i++)
cout <<arr[i] << " ";
}
template <class T>
int vector<T>::find(T a)
{
for(int i=0;i<MAYANK;i++)
{
if(arr[i]==a)
return i;
}
return -1;
}
void main()
{
vector<int>iarr;
clrscr();
iarr.getvector();
iarr.putvector();
cout <<"\n\t Enter element to find=> ";
int a;
cin >> a;
if(iarr.find(a)!=-1)
cout <<"\n\t Element found at=> "<<iarr.find(a);
else
cout <<"\n\tSorry, element is not found in Vector..";
getch();
clrscr();
vector<float>farr;
farr.getvector();
farr.putvector();
cout <<"\n\t Enter element to find=> ";
float b;
cin >> b;
if(farr.find(b)!=-1)
cout <<"\n\t Element found at=> "<<farr.find(b);
else
cout <<"\n\tSorry, element is not found in Vector..";
getch();
}
Shared By :your nameShow/Hide Program
Share This Program..
send it gtumca@gmail.com
with your name - college name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
(31) Write a object oriented program to implement a generic Stack...
Shared By :bhautik sanghvi ,amar punatar(jvims - jamnagar) Show/Hide Program
//prg no-31
#include<iostream.h>
#include<conio.h>
#include<process.h>
static int stack[5],tos=-1,size=5,m,n,t;
class stac
{
public:
int push(int stack[],int tos,int size)
{
if(tos==size-1)
{
cout<<"\n@@ It is Full @@";
}
else
{
tos++;
cout<<"\n\nenter a vlaue :";
cin>>stack[tos];
}
return(tos);
}
int pop(int stack[],int tos)
{
if(tos==-1)
{
cout<<"\n@@ It is empty @@";
}
else
{
cout<<"element deletd :"<<stack[tos];
tos--;
}
return(tos);
}
int peep(int stack[],int tos,int m)
{
int i;
for(i=0;i<=tos;i++)
{
if(stack[i]==m)
{
cout<<"\n\n:: Element found ::";
break;
}
}
if(i>tos)
cout<<"\n\n:: Element not found ::";
}
void print(int stack[],int tos)
{
int i;
cout<<"\n\n@@ All data in Stack @@\n\n";
for(i=0;i<=tos;i++)
{
cout<<"\n\n"<<stack[i];
}
}
};
main()
{
int ch;
stac s;
clrscr();
while(1)
{
cout<<"\n\n1=push \n2=pop \n3=peep\n5=print \n6=exit";
cin>>ch;
switch(ch)
{
case 1:tos=s.push(stack,tos,size);
break;
case 2:tos=s.pop(stack,tos);
break;
case 3: cout<<"\n\nenter search value :";
cin>>m;
s.peep(stack,tos,m);
break;
case 5:s.print(stack,tos);
break;
case 6:exit(0);
break;
}
}
}
Shared By :Your Name Show/Hide Program
Share This Program..
send it gtumca@gmail.com
with your name - college name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
(32) Write a program to create template class called "Safearray". Rules...
Shared By :solanki paresh(JVIMS-JAMNAGAR) Show/Hide Program
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
template <class t,int s>
class safearray
{
t a[s];
public:
int & operator [] (int idx)
{
if((idx<0) || (idx>s-1))
{
cout<<"\nOut Of Range";
}
else
{
cout<<"Array="<<a[s];
return a[s];
}
}
};
void main()
{
clrscr();
safearray<int,100> sintarray;
int i;
cout<<"\nEnter the array:";
cin>>i;
sintarray[i];
getch();
}
Shared By :bhautik sanghvi ,amar punatar(jvims - jamnagar) Show/Hide Program
//prog no 32
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
template<class array>
class safearray
{
public:
array a[100];
int index;
safearray()
{
index=-1;
}
void safeput(array val)
{
if(index==99)
{
cout<<"\narray is full";
exit(0);
}
else
{
index++;
a[index]=val;
}
}
array safeget()
{
if(index==-1)
{
return NULL;
}
else
{
array val=a[index];
index--;
return val;
}
}
};
void main()
{
clrscr();
safearray<int> sa;
int ch,num;
cout<<"\n\nvalues going to store in array\n\n";
for(int i=0,j=1,k=1;i<100;i++,j++)
{
cout<<" "<<((i+1)*10);
if(j==(k*10))
{
cout<<"\n";
k++;
}
}
cout<<"\n\n values retrived from array\n\n";
for(int x=0,y=1,z=1;x<100;x++,y++)
{
cout<<" "<<sa.safeget();
if(y==(z*10))
{
cout<<"\n";
z++;
}
}
getch();
}
(33) Use Time class to provide overloaded -. Here the time query is also...
Share This Program..
send it gtumca@gmail.com
with your name - college name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
Shared By :Your Name Show/Hide Program
(34) Design a manipulator to provide the following output specifications...
Shared By :Lukka Bhavin M. (J.V.I.M.S. - Jamnagar) Show/Hide Program
//w. a p. for manipuilator
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<iomanip.h>
void main()
{
float no;
clrscr();
cout<<"\n\n\tEnter float no:-";
cin>>no;
//show trailing zeros
cout.setf(ios::showpoint);
//15 cloumn width
cout<<setw(15);
//filling unused space with +
cout<<setfill('+');
//right justified
cout<<setiosflags(ios::right);
//set precision
cout<<setprecision(3);
cout<<no;
getch();
}
Shared By :Pandya Chaitanya N. (J.V.I.M.S. - Jamnagar) Show/Hide Program
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
ostream &manip2(ostream &output)
{
output<<setiosflags(ios::showpoint);
output<<setiosflags(ios::left);
output<<setfill('+');
output<<setiosflags(ios::right);
output<<setw(15);
output<<setprecision(2);
return output;
}
void main()
{
float pi=3.1428;
clrscr();
cout<<endl<<"Float Value = ";
cout<<manip2<<pi<<endl;
getch();
}
Shared By :bhautik sanghvi ,amar punatar(jvims - jamnagar) Show/Hide Program
//p34
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
float b;
clrscr();
cout << "Enter the value";
cin >> b;
cout<<b;
cout<<"\n\n";
cout<<setw(15);
cout<<setprecision(2);
cout<<setfill('$');
cout.setf(ios :: right,ios :: adjustfield);
cout.setf(ios :: showpoint);
cout<<b;
cout << "\n\nans is = " << b;
getch();
}
(35) Create an input manipulator called skipchar() that reads...
Shared By :Modh Rutika( LECTURER - NSVKMS - Visnagar ) Show/Hide Program
#include<iostream.h>
#include<string.h>
#include<iomanip.h>
#include<conio.h>
istream & skipchar(istream & stream)
{
stream.ignore(5);
return stream;
}
ostream & sethex(ostream & stream)
{
stream.setf(ios::hex | ios::uppercase | ios::showbase);
return stream;
}
ostream & rest(ostream & stream)
{
stream<<hex<<endl;
stream.unsetf(ios::hex | ios::uppercase | ios::showbase);
return stream;
}
void main()
{
char pw[20];
cout<<"enter string"<<endl;
cin>>skipchar>>pw;
cout<<pw<<endl;
cout<<sethex<<15<<endl<<rest<<0XF<<endl;
getch();
}
Shared By :Your Name Show/Hide Program
Share This Program..
send it gtumca@gmail.com
with your name - college name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
(36) Write a C++ program to demonstrate creation of user defined manipulator...
Shared By :Lukka Bhavin M. (J.V.I.M.S. - Jamnagar) Show/Hide Program
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<iomanip.h>
//No argument
ostream &manip(ostream &out)
{
int no;
out<<endl<<"Enter No.:";
cin>>no;
out<<"You Entered:";
out<<no;
return out;
}
//one argument
ostream &manip1(ostream &out,int no1)
{
out<<"With One Parameter Entered:";
out<<no1;
return out;
}
//Two arguments
ostream &manip1(ostream &out,int no1,float no2)
{
out<<"With Two Parameter Entered:";
out<<no1+no2;
return out;
}
//Three arguments
ostream &manip1(ostream &out,int no1,float no2,char *c)
{
out<<"With Three Parameter Entered:";
out<<no1+no2;
out<<"\t";
out<<c;
return out;
}
void main()
{
clrscr();
cout<<manip<<endl;
cout.setf(ios::unitbuf);
cout<<setw(2);
manip1(cout,2);
cout<<"\n\n";
manip1(cout,2,15.5);
cout<<"\n\n";
manip1(cout,2,15.5,"Bhavin");
getch();
}
Shared By :Pandya Chaitanya N. (J.V.I.M.S. - Jamnagar) Show/Hide Program
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<iomanip.h>
ostream &manip(ostream &out)
{
int no;
out<<endl<<"Enter No.:";
cin>>no;
out<<"You Entered:";
out<<no;
return out;
}
ostream &manip1(ostream &out,int no1)
{
out<<"With One Parameter Entered:";
out<<no1;
return out;
}
ostream &manip1(ostream &out,int no1,float no2)
{
out<<"With Two Parameter Entered:";
out<<no1+no2;
return out;
}
ostream &manip1(ostream &out,int no1,float no2,char *c)
{
out<<"With Three Parameter Entered:";
out<<no1+no2;
out<<"\t";
out<<c;
return out;
}
void main()
{
clrscr();
cout<<manip<<endl;
cout.setf(ios::unitbuf);
cout<<setw(2);
manip1(cout,2);
cout<<"\n\n";
manip1(cout,2,15.5);
cout<<"\n\n";
manip1(cout,2,15.5,"Bhavin");
getch();
}
Shared By :Your Name Show/Hide Program
Share This Program..
send it gtumca@gmail.com
with your name - college name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
(37) Write C++ program to test the following...
Share This Program..
send it gtumca@gmail.com
with your name - college name..
and share what you want ... at same mail id...
Thanx in advance...
Be connected...
D_i_Z
Shared By :Your Name Show/Hide Program
(38) Write a C++ program to demonstrate use of all the string function...
Shared By :Mr.S.K.Patel (Lecturer, AITS, Rajkot) Show/Hide Program
/* Program no. (38) Write a C++ program to demonstrate use of all the string function provided in
inbuilt String class of C++.
Developed in :- Microsoft Visual C++ 6.0
Reference taken from :- Object-Oriendted Programming with C++, E Balagurusamy, 2nd Edition
*/
#include<iostream>
#include<string>
using namespace std;
void display(string &str)
{
cout << "Size = " << str.size() << "\n";
cout << "Length = " << str.length() << "\n";
cout << "Capacity = " << str.capacity() << "\n";
cout << "Maximum Size = " << str.max_size() << "\n";
cout << "Empty = " << (str.empty() ? "yes" : "no");
cout << "\n\n";
}
void main()
{
// creating string objects
string s1; // empty string objects
string s2(" New"); // using string constant
string s3(" Delhi");
// assigning value to string objects
s1 = s2; // using string object
cout << "S1 = " << s1 << "\n";
// using a string constant
s1 = "Standard C++";
cout << "S1 = " << s1 << "\n";
// using another object
string s4(s1);
cout << "S4 = " << s4 << "\n\n";
// reading through keyboard
cout << "Enter a string-> ";
cin >> s4;
cout << "Now S4 = " << s4 << "\n\n";
// concatenating strings
s1 = s2 + s3;
cout << "S1 finally contains: = " << s1 << "\n";
// manipulating string objects
string sk1("12345");
string sk2("abcde");
cout << "\n\nOriginal String are: \n";
cout << "SK1: " << sk1 << "\n";
cout << "SK2: " << sk2 << "\n\n";
// inseerting a stirng into another
cout << "Place SK2 inside SK1 \n";
sk1.insert(4,sk2);
cout << "Modified SK1: " << sk1 << "\n\n";
// removing characters in a string
cout << "Remove 5 characters from SK1 \n";
sk1.erase(4,5);
cout << "Now SK1: " << sk1 << "\n\n";
// replacing character in a string
cout << "Replace middle 3 characters in SK2 with SK1 \n";
sk2.replace(1,3,sk1);
cout << "Now SK2: " << sk2 << "\n\n\n";
// relational operations
s1="ABC";
s2="XYZ";
s3 = s1+s2;
if(s1!=s2)
cout << "s1 is not equal to s2 \n";
if(s1>s2)
cout << "s1 greater than s2 \n";
else
cout << "s2 greate than s1 \n";
if(s3 == s1+s2)
cout << "s3 is equal to s1+s2 \n\n";
int x = s1.compare(s2);
if(x == 0)
cout << "s1 == s2\n";
else if(x > 0)
cout << "s1 > s2\n";
else
cout << "s1 < s2\n\n\n";
// string characteristics
string str1;
cout << "Initial status: \n";
display(str1);
cout << "Enter a string (one word) \n";
cin >> str1;
cout << "Status now: \n";
display(str1);
str1.resize(15);
cout << "Status after resizing: \n";
display(str1);
cout << "\n\n\n";
// accessing characters in strings
string s("ONE TWO THREE FOUR");
cout << "The string contains : \n";
for(int i=0; i<s.length(); i++)
cout << s.at(i); // display one character
cout << "\n String is shown again: \n";
for(int j=0; j<s.length(); j++)
cout << s[j];
int x1 = s.find("TWO");
cout << "\n\nTwo is found at: " << x1 << "\n";
int x2 = s.find('T');
cout << "\n\nT is found at: " << x2 << "\n";
int x3 = s.find_last_of('R');
cout << "\n\nR is last found at: " << x3 << "\n";
cout << "\nRetrieve and print substring TWO \n";
cout << s.substr(x1,3);
cout << "\n\n";
// comparing and swapping
s1 = "Road";
s2 = "Read";
s3 = "Red";
cout << "s1 = " << s1 << "\n";
cout << "s2 = " << s2 << "\n";
cout << "s3 = " << s3 << "\n";
x = s1.compare(s2);
if(x==0)
cout << "s1 == s2" << "\n";
else if(x>0)
cout << "s1 > s2" << "\n";
else
cout << "s1 < s2" << "\n";
int a = s1.compare(0,2,s2,0,2);
int b = s2.compare(0,2,s1,0,2);
int c = s2.compare(0,2,s3,0,2);
int d = s2.compare(s2.size()-1,1,s2,s3.size()-1,1);
cout << "a = " << a << "\n" << "b = " << b << "\n";
cout << "c = " << c << "\n" << "d = " << d << "\n";
cout << "\nBefore swap: \n";
cout << "s1 = " << s1 << "\n";
cout << "s2 = " << s2 << "\n";
s1.swap(s2);
cout << "\nAfter swap: \n";
cout << "s1 = " << s1 << "\n";
cout << "s2 = " << s2 << "\n";
}
<<Previous