Converting base type to class type (char to string), C/C++ Programming

Converting Base Type to Class Type (char to string)

 

class String

{ char *name;

int length;

public:

String(void)

{length =0;

name = new char[length+1];

}

String(char *s)

{length = strlen(s);

name = new char[length+1];//for null terminator strcpy(name,s);

}

void display(void)

{cout<

}

void join(String &a, String &b);

friend String operator+(String &a, String &b);

};

String operator+(String &a, String &b)

{String temp;

delete temp.name;

temp.length = a.length+b.length; temp.name = new char[temp.length+1]; strcpy(temp.name,a.name); strcat(temp.name,b.name);

return temp;

}

 

void String::join(String &a, String &b)

{length = a.length+b.length;

delete name;

name = new char[length+1];

strcpy(name,a.name);

strcat(name,b.name);

};

void main()

{

char *first="Electronic ";

String name1(first); String name2("and Communication ");String name3("Engineering");

String s1,s2; s1.join(name1,name2); s2.join(s1,name3); s1=name1+name2; s2=s1+name3;

name1.display();name2.display();name3.display();

s1.display();

s2.display();

}

 

Posted Date: 9/20/2012 8:19:55 AM | Location : United States







Related Discussions:- Converting base type to class type (char to string), Assignment Help, Ask Question on Converting base type to class type (char to string), Get Answer, Expert's Help, Converting base type to class type (char to string) Discussions

Write discussion on Converting base type to class type (char to string)
Your posts are moderated
Related Questions
Constructor public class ListNode {    // package access members; List can access these directly private E data; // data for this node privateListNode nextNode; /

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

a program that declares and prompts the user to enter two integer and performs the five arithmetic operations

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

what is the difference between call by reference and call by pointer method?

#include void func(int num, b=5) { auto int total=0; static int sum=0; for ( int i=num; i>0 ; i--) total+=i; sum+=total; cout


superposition of two waves

Reusability  Reusability means reusing code written earlier, may be from some earlier project or from the library. Reusing old code not only saves development time, but also sa

Prepare a script for providing Instagram Followers/Likes I need to prepare a panel where my customer able to get Instagram followers or likes automatically. - A panel where I