Saturday, May 9, 2009

File structures lab program 1 (for 6th sem ISE)

#include stdio.h
#include conio.h
#include iostream.h
#include fstream.h
#include string.h
#include stdlib.h
class string
{
char str[30];
public:string()
{
strcpy(str,0);
}
void stringrev();
void read();
friend ostream & operator <<(ostream &s,string p)
{
s<< p.str<<"\n";
return s;
}
};

void string::read()
{
cout<<"enter the name:\n";
gets(str);
}
void string::stringrev()
{
strrev(str);
}

main()
{
string s[20];
int ch;
char str[20];
clrscr();
for(;;)
{
cout<<"\n1:standard i/o \n2:using a file \n3:exit";
cout<<"\n enter the choice\n";
cin>>ch;
switch(ch)
{
case 1:cout<<"enter the no. of names to insert\n";
int n;
cin>>n;
for(int i=0;i {
s[i].read();
}
cout<<"\n reversed strings\n";
for(i=0;i {
s[i].stringrev();
cout< }
break;

case 2:fstream ofile,ifile,ofile1;
ofile.open("in.txt",ios::out);
cout<<"enter the no. of strings:\n";
cin>>n;
for(i=0;i {
cout<<"enter the string\n";
cin>>str;
ofile< }
ofile.close();
ifile.open("in.txt",ios::in);
ofile1.open("out.txt",ios::out);
char buf[30];
while(!ifile.eof())
{
ifile.getline(buf,80,'\n');
strrev(buf);
cout< ofile1< }
break;

case 3:exit(0);
}
}
}

No comments:

Post a Comment