C++ programming language - Part 86 - assign the content of two string
assign the content of two string
Program Ex_21_5
//assign
the content of two string (arraydemo.c)
#include
#include
void main()
{
clrscr(); // To clean the screen
char
a1[10],a2[10]; //array of size 10
defined
int i,j;
cout<<"type
string1"<<"\n";
cin>>a1;
cout<<"type
string2"<<"\n";
cin>>a2;
for(i=0,j=0;a1[i]!='\0';i++,j++)
{
a1[i]=a2[j];
}
cout<<"first is changed as "
<
}
Write a program to read two string “
NOVA” & “Dhaka” but prints backward Suppose
Dhaka NOVA.
Program Ex_22_2
#include
void main()
{
char a1[10]; char a2[10]; char a3[10];
int I, j;
cout<<"type string1"<
cin>>a1;
cout<<"type string2"<
cin>>a2;
for(I=0;a2[I]!='\0';I++)
a3[I]=a2[I];
for(j=0;a1[j]!='\0';j++,I++)
a3[I]=a2[j];
a3[I]='\0';
cout<<"this is "<
Write a program to compare two stringusing string
handle
Program Ex 33_1
//structure.demo
#include
#include
void main()
{
char
str1[20],str2[20];
int x;
cout<<"Type
string1 "<
cin>>str1;
cout<<"Type string2 "<
cin>>srt2;
x=strcmp(str1,str2);
if(x!=0)
cout<<"not
equal "<
else
cout<<"equal
"<
}
2. Write a program to marge two stringusing string
handle
program Ex 33_2
//structure.demo
#include
#include
#include
void main()
{
char
str1[20],str2[20];
int x;
cout<<"Type
string1 "<
cin>>str1;
cout<<"Type string2 "<
cin>>str2;
//x=strcat(str1,str2);
// if(x!=0)
//cout<<"not
equal "<
//else
cout<<"marged
=
"<
}
dynamic pointer
PPPPP Ex 41_1
//dynamic
pointer.demo
//file
output
#include
#include
#include
class word
{
private:
char
w[20];
public:
void
store_word(char *cstr)
{
strcpy(w,cstr);
}
void
add_word(char *cstr)
{
strcat(w,cstr);
}
void
display(void)
{
cout<<" string is
"<
}
word(char
*cstr)
{
strcpy(w,cstr);
}
word()
{
strcpy(w,NULL);
}
~word()
{
w[0],'\0';
}
};
void main()
{
word w1,w2;
w2.store_word("Bangladesh");
//
w1.display();
cout<<"Test line........
"<
w2.display();
cout<
w2.add_word(" &
America"); //
w2.display();
w1.store_word(" China
alon"); //
cout<
w1.display();
getch();
}
inherit.demo
PPPPP 47_92
ex 7.1
//inherit.demo
#include
#include
#include
//Scope resulation with overidden
class
customer //class defined
{
char
cname[21];
int no_people;
char ccat;
float fcost;
char cstart_date[9];
public:
void data_in()
{
cout<<"Type name \t";
cin>>cname;
cout<<" Type number of people
\t";
cin>>no_people;
cout<<"Type catagory(N/S)
\t"; // Normal or Special
cin>>ccat;
cout<<"Type the cost \t";
cin>>fcost;
cout<<"Type start date \t";
cin>>cstart_date;
}
void data_out()
{
cout<<"name is=
"<
cout<<"No of people are =
"<
cout<<"catagory is = "<
cout<<"cost is = "<
cout<<"start date is =
"<
}
};
void main()
{
char choice;
customer c1;
do
{
cout<<"\n1: Query 2:Accept
3: Display 4: Exit ";
cout<<"\n\nType choice: ";
cin>>choice;
if(choice=='1')
{
fstream
fill("customer.txt",ios::in); //ios::app
int
pos,n;
cout<
cin>>n;
pos=(sizeof(customer))*(n-1);
fill.seekg(pos,ios::beg);
fill.read((char*)&c1,sizeof(c1)); //type cast
c1.data_out();
fill.close();
getch();
}
else if(choice=='2')
{
fstream
fill("customer.txt",ios::app);
c1.data_in();
fill.write((char*)&c1,
sizeof(c1)); // type cast
fill.close();
}
else if(choice=='3')
{
fstream
fill("customer.txt",ios::in);
fill.read((char*)&c1,sizeof(c1));
while(fill)
{
c1.data_out();
fill.read((char*)&c1,sizeof(c1));
getch();
}
fill.close();
}
}while(choice!='4');
}