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

Assignment Help:

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();

}

 


Related Discussions:- Converting base type to class type (char to string)

Minimum shelves, Write a program that finds the minimum total number of she...

Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

Explain polymorphism, Polymorphism C++ supports this idea - that differ...

Polymorphism C++ supports this idea - that different objects do "the right thing "- by function polymorphism and class polymorphism. Poly means many, while morph means form.

If/else statement, to compute the net pay of an emplyee, given his/her pay ...

to compute the net pay of an emplyee, given his/her pay rate, number of hours and tax rate

Explain the functions strlen ( ), Question 1 Consider you have to find out...

Question 1 Consider you have to find out average marks of 100 students in a class. Write simple program(s) using different iteration statements to accomplish it Question 2 Expla

Encryption/Decryption, I need to include files so you can understand easier...

I need to include files so you can understand easier.

Define variable declaration in c++, Variable Declaration This declarati...

Variable Declaration This declaration of variables in the C language is permitted only in the starting of their block, prior to executable program statements. In C++ declaratio

M--commerce, Project Description: We are aiming to prepare an industry f...

Project Description: We are aiming to prepare an industry first in the m-commerce world. M-commerce payment processing programmers required Skills required are C Programmi

Bouncing Ball, Create an applet that bounces a blue ball inside an applet u...

Create an applet that bounces a blue ball inside an applet using Thread. The ball (diameter is 10) will start at position (0,0). When the ball hits the edge of the applet, the ba

Explain external variables, External Variables Different functions of t...

External Variables Different functions of the similar program can be written in different source files and can be compiled together. The scope of a global variable is not limit

Design a car management system application, 1) Database: The database nee...

1) Database: The database needs to be used for persistent storage of cars. For details of what information should be stored in the database, please see the description above. You

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd