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)

Program to store family members details, Program to store family members de...

Program to store family members details in C++: #include #include #include struct record {   char name[30];   int age;   char state[40]; }x; //cal

Explain the new and delete operators, The new and delete operators The ...

The new and delete operators The C language has explained library functions- malloc() and free() for dynamic allocation and de-allocation of memory. C++ gives yet another appro

Write a program to illustrate array, Write a Program to illustrate Array? ...

Write a Program to illustrate Array? int x[100]; char text[80]; float temp[30]; static int marks[5]; We are able to use symbolic constants instead of expression. The valu

Determining the monthly payment on a mortgage loan, The following is the fo...

The following is the formula that can be used to complete that calculation: Monthly Payment = Monthly Interest Rate / (1 - (1 + Monthly Interest Rate) -Payment Interval )) *

Want an ea project for jack bsher, Want an EA project for Jack Bsher Pro...

Want an EA project for Jack Bsher Project Description: New EA game Skills required   Android, C++ Programming, PHP, Metatrader, SQL

C assignment , 1. Create text a file with the name "myemail" that has a sin...

1. Create text a file with the name "myemail" that has a single line in it, consisting of your email address. Something like "[email protected]" (or your hotmail or gm

Write a procedure to add and subtract-money, Money is immutable and is asso...

Money is immutable and is associated with a currency. When two money entities are added or subtracted be sure to consider currency conversion. You must create a money object result

Assignment problem, how to write c code to solve assignment problem?

how to write c code to solve assignment problem?

Explain about inheritance, Inheritance and Reuse Consider a car manufac...

Inheritance and Reuse Consider a car manufacturing company. When they require building a new car, they have two choices. They can start from the scratch, or they can change an

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