Coding Discussions
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Constructos and Destructors assignment question:CD-3

Go down

Constructos and Destructors assignment question:CD-3 Empty Constructos and Destructors assignment question:CD-3

Post by Prateek Gupta Thu May 11, 2017 1:57 pm

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;
}

Prateek Gupta
Admin

Posts : 6
Join date : 2017-04-04

https://clanofcoders.board-directory.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum