Constructos and Destructors assignment question:CD-3
Page 1 of 1
Constructos and Destructors assignment question:CD-3
- Code:
#include <bits/stdc++.h>
using namespace std;
class str
{
char *s;
int l;
public:
str()
{
s="/0";
}
str(int len)
{
l=len;
s=new char[l];
}
~str()
{
delete s;
cout<<"Memory deallocated"<<endl;
}
void get()
{
cout<<"Enter the string:"<<endl;
cin>>s;
}
void show()
{
cout<<"The string is: "<<s<<endl;
}
void reverse()
{
int i,c=0;
char r[l];
for(i=l-1;i>=0;i--)
r[c++]=s[i];
cout<<"The reverse string is:"<<r<<endl;
}
};
int main()
{
int l;
cout<<"Enter the string length:"<<endl;
cin>>l;
str s(l);
s.get();
s.show();
s.reverse();
return 0;
}
Similar topics
» class and objects assignment solutions.
» constructor and destructor assignment solutions
» in ipl question.the test case 2nd is wrong.my solution is correct.
» constructor and destructor assignment solutions
» in ipl question.the test case 2nd is wrong.my solution is correct.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|