Well yesterday was pretty tiring and nothing much happened!!!
I realised one thing though:
There are two mindsets to adopt while programming:
1. Make the implementation of the solution so simple such that there are obviously no flaws
2. Make the implementation of the solution so complicated that the flaws are not obvious.
Some people are adopting the second mindset!!! How Sad ...... for me.....!!!
I cracked up when one of my students told me that she has been working so much on a labsheet that she has even dreamed of programming.... I dnt know how to interpret that. Well since she did not say that 'Programming gave her a nightmare..' I'll assume that you only dream about pleasant things. So I prefer to assume that she is enjoying programming!!!
Had only one lecture and that was tiring enough!!! And on top of that, met Tigrooooo!!! Hoo Hoo Hoo, who was in a bad shapes and it worries me coz the state she was in is really bad. I sincerely hope she get well soon and starts bouncing around.....
Please get better n come back, i have no one else to tease!!!:'-)
Take care of yourself Tigrooo! HOo HOo HOo!!!
Got home at about half past six and hey... I had my microwaved Nachos with Peri-Peri and Mozarella..... it did not taste as good without Jalepenos... But anyways!!! Was still better that nothing.
Then went for the usual MSN/Facebook Session....... nothing much apart from that!!!
I did try the returning array/strings thing and i came up with the following code and it worked fine on Visual C++
#include<iostream.h>
#include<string.h>
class tnt{
private:
int* a;
char Name[10];
public:
tnt();
int* getA();
void get_ary_A(int b[]);
void getName(char chr [10]);
char* getptrName();
};
tnt::tnt()
{
a=new int[5];
a[0]=56;
a[1]=2;
a[2]=8;
a[3]=9;
a[4]=14;
strcpy(Name,"Gavin");
}
int* tnt::getA()
{
return a;
}
void tnt::getName(char chr[])
{
strcpy(chr,Name);
}
char* tnt::getptrName()
{
return Name;/*return the string (pointer to char)*/
}
void tnt::get_ary_A(int b[])
{
for(int g=0;g<5;g++)
{
b[g] = a[g];
}
}
void main()
{
tnt channel;
int* A;
int B[5];
char gname[10], gname2[10];
channel.get_ary_A(B);
A=channel.getA();
channel.getName(gname);/*pass string to fn and it behaves as if its passed by ref*/
cout<<endl;
cout<<gname;
cout<<endl;
strcpy(gname2,channel.getptrName());/*returning the pointer to the array and copying result in a string*/
cout<<gname2;
cout<<endl;
cout<<"Using the pointer\n";
for(int i=0;i<5;i++)
{
cout<<A[i];
cout<<endl;
}
cout<<"Using an array passed by ref\n";
for(int j=0;j<5;j++)
{
cout<<B[j];
cout<<endl;
}
}//main
Have Fun!!
G@V!N
Showing posts with label returning arrays and strings from instances of classes. Show all posts
Showing posts with label returning arrays and strings from instances of classes. Show all posts
Thursday, February 14, 2008
Subscribe to:
Posts (Atom)
