tag:blogger.com,1999:blog-69440110562337288882023-11-15T09:58:46.489-08:00Concatenate n number of strings (chars) passed without using string.h Unknownnoreply@blogger.comBlogger3125tag:blogger.com,1999:blog-6944011056233728888.post-27257379751986581742013-07-16T13:19:00.001-07:002013-07-16T13:19:10.525-07:00template//bell.h<br />
#ifndef __BELL__<br />#define __BELL__<br />#include "iBell.h"<br />#include "SoundMaker.h"<br />template<class T><br />class Bell : public SoundMaker<T>, public iBell<br /> {<br /> private:<br /> protected:<br /> public:<br /> Bell() : SoundMaker() {sound = "Ding"}<br /> void switchHammer() <br /> {<br /> if(sound == "Ding")<br /> sound = "Dong";<br /> else<br /> sound = "Ding";<br /> }<br /> };<br /><br />// base.h<br />
#ifndef __BASE__<br />#define __BASE__<br />#include "iBase.h"<br />template<class T><br />class Base : public iBase<br /> {<br /> private:<br /> static T count;<br /><br /> T id;<br /> protected:<br /> public:<br /> Base() : id(count++) {}<br /> T getID() {return id;}<br /> };<br />#endif<br />
<br />
<br />
// soundmaker.h<br />
#include "Base.h"<br />#include "iSoundMaker.h"<br />template<class T><br />class SoundMaker : public Base<T>, public iSoundMaker<br /> {<br /> private:<br /> protected:<br /> std::string sound;<br /> public:<br /><br /> Soundmaker() : Base(), sound("Bang") {}<br /> void playSound() {std::cout << sound << "\n";}<br /> };<br />#endif<br />
<br />
//speaker.h<br />
#include "iSpeaker.h"<br />#include "SoundMaker.h"<br />template<class T><br />class Speaker : public SoundMaker<T>, public iSpeaker<br /> {<br /> private:<br /> protected:<br /> public:<br /> Speaker() : SoundMaker() {}<br /> void increaseVolume()<br /> {<br /> sound += "!";<br /> }<br /> };<br />#endifUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-6944011056233728888.post-77827886644835465782013-07-16T13:15:00.004-07:002013-07-16T13:15:47.093-07:00bell#ifndef __BELL__<br />#define __BELL__<br /><br />#include "iBell.h"<br />#include "SoundMaker.h"<br />template<class T><br />class Bell : public SoundMaker<T>, public iBell<br /> {<br /> private:<br /> protected:<br /> public:<br /> Bell() : SoundMaker() {sound = "Ding"}<br /> void switchHammer() <br /> {<br /> if(sound == "Ding")<br /> sound = "Dong";<br /> else<br /> sound = "Ding";<br /> }<br /> };<br /><br /><br />#endifUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-6944011056233728888.post-8296484715426093932013-05-31T19:27:00.000-07:002013-05-31T19:27:12.189-07:00Concatenate n Chars// using library <cstrarg><br />
<br />
char* nstrcat(char* name, ...)<br />{<br /> int count =0, result_c =0;<br /> char* result_n = name ;<br /> char* i;<br /> while(*result_n)<br /> ++result_c;<br /><br /> va_list ap; <br /> va_start(ap, name);<br /><br /><br /><br /> for( i = name; i != '\0'; i = va_arg(ap, char*)){<br /> for( count = 0; i[count] != '\0'; i++){<br /> result_n[result_c + count] = i[count]; <br /> } <br /> result_c += count; <br /> }<br /> va_end(ap);<br />}<br />
<br />Reference:<br />
http://stackoverflow.com/questions/14023024/strcat-for-formatted-strings <br />
Unknownnoreply@blogger.com0