Create a string class as shown below

A

ahdz10

class string
{ private:
.....
public:

//Constructor
//overloading constructor

//Destructor
friend function for accepting input
friend fuction for display output

}

a constructor which will initialize the string as the first line and
size with corresponding string length.


Another overloading constructor which will accept a string and
initialize it and its length to the class

Write a friend function which will read a string for the objext from
the keyboard
 
O

osmium

class string
{ private:
....
public:

//Constructor
//overloading constructor

//Destructor
friend function for accepting input
friend fuction for display output

}

a constructor which will initialize the string as the first line and
size with corresponding string length.


Another overloading constructor which will accept a string and
initialize it and its length to the class

Write a friend function which will read a string for the objext from
the keyboard

I hope that makes a lot more sense in the language in which you are
communicating with your instructor. In English as presented here it has all
kinds of problems in interpretation.

Start by making a wild guess that a string is a collection of characters of
*any* variety and the minimal data are a datum and a size. Figure out a
way to put some data in the two data members. Realize that you will have
no way to figure out whether what you write is correct and actually works.
 
R

.rhavin grobert

class string
{ private:
....
 public:

      //Constructor
     //overloading constructor

     //Destructor
friend function for accepting input
friend fuction for display output

}

a constructor which will initialize the string as the first line and
size with corresponding string length.

Another overloading constructor which will accept a string and
initialize it and its length to the class

Write a friend function which will read a string for the objext from
the keyboard

just a hint to let you start:



class string
{
private:

// the lenght of the string
unsigned int m_nLenght;

// the pointer to the allocated data
void* m_pData;

public:

// Constructor
string()
: m_pData(NULL), m_nLenght(0) {};

// copy constructor
string(string const& string s)
: m_nLenght(s.m_nLenght)
{
if (m_nLenght)
{
m_pData = NULL;
return;
}
m_pData = malloc(m_nLenght);
::memcpy(m_pData, s.m_pData, m_nLenght);
};

// Destructor
~string() {free(m_pData);};
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,138
Messages
2,570,799
Members
47,347
Latest member
RebekahStu

Latest Threads

Top