class Name
{
private:
char* ch;
int size;
public:
// construct, destruct, copy construct etc
Name capitalize()const;
};
// this is where I am stuck and confused.
// I need to return an object of Name to upper case
Name Name:: capitalize()const
{
Name temp;
// not sure what to do here
return temp;
}
It's pretty straightforward. 'temp' should be a copy of the current object ('this'), then you just go through temp's string and convert all its characters to uppercase.
You never initialize temp. That means it's default initialized, so since you don't specify any constructor a constructor by the compiler will be provided that initialize each data member to it's default value. Depending on your compiler this would be:
1 2
ch = 0;
size = 0;
or junk (arbitrary data). This is not what you want.
Also what is bufferSize; You never declare it. That goes for buffer also.
1)Define a constructor and use this to initialize temp.
2)Then use a loop like above but using your actual data members (ch and size) not other ones like buffer etc and capitalize every character you find.
3)Then return this temp object