C++ gurus and learners, we program ourselves :P all work is CC licensed

Sunday, December 14

The course has been completed but i was unable to make regular blog posts

23:21 By


Tuesday, October 28

Merge Sort MultiThreading in C#; multithreaded

13:03 By


        int[] MergeSort(int[] input, int start, int end)
        {
            if (end - start < 2)
            {
                int[] result = new int[1];
                result[0] = input[start];
                return (result);
            }

            Task<int[]> Tleft = Task<int[]>.Factory.StartNew(() => { return MergeSort(input, start, (start + end) / 2); });

            Task<int[]> Tright = Task<int[]>.Factory.StartNew(() => { return MergeSort(input, (start + end) / 2, end); });

            //Task<int[]>.WaitAll(new Task<int[]>[]{Tleft,Tright});

            int[] left = Tleft.Result;

            int[] right = Tright.Result;
            int[] Result = Task<int[]>.Factory.StartNew(() => { return Merge(left, right); }).Result;

            Console.WriteLine(getText(Result));

            return Result;
        }

        int[] Merge(int[] left, int[] right)
        {
            int leftSize = left.Length, rightSize = right.Length;
            int[] result = new int[leftSize + rightSize];
            int leftIndex = 0, rightIndex = 0, resultIndex = 0;

            while (rightIndex < rightSize && leftIndex < leftSize)
            {
                result[resultIndex++] = left[leftIndex] < right[rightIndex] ? left[leftIndex++] : right[rightIndex++];
            }
            while (rightIndex < rightSize)
                result[resultIndex++] = right[rightIndex++];
            while (leftIndex < leftSize)
                result[resultIndex++] = left[leftIndex++];
            return result;
        }

Monday, October 27

Merge Sort

13:11 By

Please find the source code for merge sort algorithm. I have made this implementation on my own after taking this class https://class.coursera.org/algo-006/lecture/2

I will appreciate any comment that you have.


#include <iostream>
using namespace std;

int* Merge(int*, int*, const int, const int);

int* MergeSort(int* input, int start, int end, int& resultSize)
{
 if (end - start < 2)
 {
  int * result = new int[1];
  result[0] = input[start];
  resultSize = 1;
  return (result);
 }

 int leftSize = 0, rightSize = 0;

 int *left = MergeSort(input, start, (start + end) / 2, leftSize);
 int *right = MergeSort(input, (start + end) / 2, end, rightSize);

 int* result = Merge(left, right, leftSize, rightSize);
 resultSize = leftSize + rightSize;
 delete[] left;
 delete[] right;
 left = right = NULL; //to avoid dangling pointer
 return result;
}

int* Merge(int* left, int* right, const int leftSize, const int rightSize)
{
 int resultSize = leftSize + rightSize;
 int * result = new int[resultSize];
 int leftIndex = 0, rightIndex = 0, resultIndex = 0;

 while (rightIndex<rightSize && leftIndex<leftSize)
 {
  result[resultIndex++] = left[leftIndex] < right[rightIndex] ? left[leftIndex++] : right[rightIndex++];
 }
 while (rightIndex < rightSize)
  result[resultIndex++] = right[rightIndex++];
 while (leftIndex < leftSize)
  result[resultIndex++] = left[leftIndex++];
 return result;
}


void main()
{
 int* input = new int[20]{5, 34, 5, 6, 4, 56, 4, 3, 3, 5, 6, 4, 3, 5, 6, 87, 54, 3, 5, 76};

 int resultSize = 0;

 int* result = MergeSort(input, 0, 20, resultSize);
 for (size_t i = 0; i < resultSize; i++)
 {
  cout << endl << result[i];
 }
 delete[] input;

 delete[] result;

}

Sunday, October 26

Relaunching with a course on Design and Analysis of Algorithms from Stanford via Coursera

21:22 By

I will be relaunching this blog in sync with my quarter goal. I am working as an Assoc Software Engineer with Bentley Systems, which is a leading company in AEC infrastructure support. I love being there with all the people. As a part of my career growth i have participated in a MOOC course on Algorithms from Stanford via coursera. I plan to share two posts per week on what i have learned from that course.

Have a great weekend and keep following ;)

PS. Please find the link to this course --> https://www.coursera.org/course/algo 

Regards


Sunday, July 13

New domain name

18:55 By

I have acquired a new domain name. Www.umarqureshi.me

Saturday, February 1

Windows Store App Created

01:17 By

Update: Bug Fixes have been made. The open sample file is not working as expected, a review on windows store :)
I have created a windows store app but very small bug has been left out. It saves files with extension .docx but those files need to be opened with .rtf format. will fix this ASAP in next release :)

Thursday, January 30

Andrew Solomon @ TED

12:46 By

"I felt a funeral in my brain, and mourners to and fro kept treading, treading till I felt that sense was breaking through. And when they all were seated, a service, like a drum, kept beating, beating, till I felt my mind was going numb. And then I heard them lift a box and creak across my soul with those same boots of lead again, then space began to toll, as if the heavens were a bell and being were an ear, and I, and silence, some strange race wrecked, solitary, here. Just then, a plank in reason broke, and I fell down and down and hit a world at every plunge, and finished knowing then."

We know depression through metaphors. Emily Dickinson was able to convey it in language, Goya in an image. Half the purpose of art is to describe such iconic states.

As for me, I had always thought myself tough, one of the people who could survive if I'd been sent to a concentration camp.

In 1991, I had a series of losses. My mother died, a relationship I'd been in ended, I moved back to the United States from some years abroad, and I got through all of those experiences intact.

But in 1994, three years later, I found myself losing interest in almost everything. I didn't want to do any of the things I had previously wanted to do, and I didn't know why. The opposite of depression is not happiness, but vitality, and it was vitality that seemed to seep away from me in that moment. Everything there was to do seemed like too much work. I would come home and I would see the red light flashing on my answering machine, and instead of being thrilled to hear from my friends, I would think, "What a lot of people that is to have to call back." Or I would decide I should have lunch, and then I would think, but I'd have to get the food out and put it on a plate and cut it up and chew it and swallow it, and it felt to me like the Stations of the Cross.

And one of the things that often gets lost in discussions of depression is that you know it's ridiculous. You know it's ridiculous while you're experiencing it. You know that most people manage to listen to their messages and eat lunch and organize themselves to take a shower and go out the front door and that it's not a big deal, and yet you are nonetheless in its grip and you are unable to figure out any way around it. And so I began to feel myself doing less and thinking less and feeling less. It was a kind of nullity.

And then the anxiety set in. If you told me that I'd have to be depressed for the next month, I would say, "As long I know it'll be over in November, I can do it." But if you said to me, "You have to have acute anxiety for the next month," I would rather slit my wrist than go through it. It was the feeling all the time like that feeling you have if you're walking and you slip or trip and the ground is rushing up at you, but instead of lasting half a second, the way that does, it lasted for six months. It's a sensation of being afraid all the time but not even knowing what it is that you're afraid of. And it was at that point that I began to think that it was just too painful to be alive, and that the only reason not to kill oneself was so as not to hurt other people.

And finally one day, I woke up and I thought perhaps I'd had a stroke, because I lay in bed completely frozen, looking at the telephone, thinking, "Something is wrong and I should call for help," and I couldn't reach out my arm and pick up the phone and dial. And finally, after four full hours of my lying and staring at it, the phone rang, and somehow I managed to pick it up, and it was my father, and I said, "I'm in serious trouble. We need to do something."

The next day I started with the medications and the therapy. And I also started reckoning with this terrible question: If I'm not the tough person who could have made it through a concentration camp, then who am I? And if I have to take medication, is that medication making me more fully myself, or is it making me someone else? And how do I feel about it if it's making me someone else?

I had two advantages as I went in to the fight. The first is that I knew that, objectively speaking, I had a nice life, and that if I could only get well, there was something at the other end that was worth living for. And the other was that I had access to good treatment.

But I nonetheless emerged and relapsed, and emerged and relapsed, and emerged and relapsed, and finally understood I would have to be on medication and in therapy forever. And I thought, "But is it a chemical problem or a psychological problem? And does it need a chemical cure or a philosophical cure?" And I couldn't figure out which it was. And then I understood that actually, we aren't advanced enough in either area for it to explain things fully. The chemical cure and the psychological cure both have a role to play, and I also figured out that depression was something that was braided so deep into us that there was no separating it from our character and personality.

I want to say that the treatments we have for depression are appalling. They're not very effective. They're extremely costly. They come with innumerable side effects. They're a disaster. But I am so grateful that I live now and not 50 years ago, when there would have been almost nothing to be done. I hope that 50 years hence, people will hear about my treatments and be appalled that anyone endured such primitive science.

Depression is the flaw in love. If you were married to someone and thought, "Well, if my wife dies, I'll find another one," it wouldn't be love as we know it. There's no such thing as love without the anticipation of loss, and that specter of despair can be the engine of intimacy.

There are three things people tend to confuse: depression, grief and sadness. Grief is explicitly reactive. If you have a loss and you feel incredibly unhappy, and then, six months later, you are still deeply sad, but you're functioning a little better, it's probably grief, and it will probably ultimately resolve itself in some measure. If you experience a catastrophic loss, and you feel terrible, and six months later you can barely function at all, then it's probably a depression that was triggered by the catastrophic circumstances. The trajectory tells us a great deal. People think of depression as being just sadness. It's much, much too much sadness, much too much grief at far too slight a cause.

As I set out to understand depression, and to interview people who had experienced it, I found that there were people who seemed on the surface to have what sounded like relatively mild depression who were nonetheless utterly disabled by it. And there were other people who had what sounded as they described it like terribly severe depression who nonetheless had good lives in the interstices between their depressive episodes. And I set out to find out what it is that causes some people to be more resilient than other people. What are the mechanisms that allow people to survive? And I went out and I interviewed person after person who was suffering with depression.

One of the first people I interviewed described depression as a slower way of being dead, and that was a good thing for me to hear early on because it reminded me that that slow way of being dead can lead to actual deadness, that this is a serious business. It's the leading disability worldwide, and people die of it every day.

One of the people I talked to when I was trying to understand this was a beloved friend who I had known for many years, and who had had a psychotic episode in her freshman year of college, and then plummeted into a horrific depression. She had bipolar illness, or manic depression, as it was then known. And then she did very well for many years on lithium, and then eventually, she was taken off her lithium to see how she would do without it, and she had another psychosis, and then plunged into the worst depression that I had ever seen in which she sat in her parents' apartment, more or less catatonic, essentially without moving, day after day after day. And when I interviewed her about that experience some years later -- she's a poet and psychotherapist named Maggie Robbins — when I interviewed her, she said, "I was singing 'Where Have All The Flowers Gone' over and over to occupy my mind. I was singing to blot out the things my mind was saying, which were, 'You are nothing. You are nobody. You don't even deserve to live.' And that was when I really started thinking about killing myself."

You don't think in depression that you've put on a gray veil and are seeing the world through the haze of a bad mood. You think that the veil has been taken away, the veil of happiness, and that now you're seeing truly. It's easier to help schizophrenics who perceive that there's something foreign inside of them that needs to be exorcised, but it's difficult with depressives, because we believe we are seeing the truth.

But the truth lies. I became obsessed with that sentence: "But the truth lies." And I discovered, as I talked to depressive people, that they have many delusional perceptions. People will say, "No one loves me." And you say, "I love you, your wife loves you, your mother loves you." You can answer that one pretty readily, at least for most people. But people who are depressed will also say, "No matter what we do, we're all just going to die in the end." Or they'll say, "There can be no true communion between two human beings. Each of us is trapped in his own body." To which you have to say, "That's true, but I think we should focus right now on what to have for breakfast." (Laughter) A lot of the time, what they are expressing is not illness, but insight, and one comes to think what's really extraordinary is that most of us know about those existential questions and they don't distract us very much. There was a study I particularly liked in which a group of depressed and a group of non-depressed people were asked to play a video game for an hour, and at the end of the hour, they were asked how many little monsters they thought they had killed. The depressive group was usually accurate to within about 10 percent, and the non-depressed people guessed between 15 and 20 times as many little monsters — (Laughter) — as they had actually killed.

A lot of people said, when I chose to write about my depression, that it must be very difficult to be out of that closet, to have people know. They said, "Do people talk to you differently?" And I said, "Yes, people talk to me differently. They talk to me differently insofar as they start telling me about their experience, or their sister's experience, or their friend's experience. Things are different because now I know that depression is the family secret that everyone has.

I went a few years ago to a conference, and on Friday of the three-day conference, one of the participants took me aside, and she said, "I suffer from depression and I'm a little embarrassed about it, but I've been taking this medication, and I just wanted to ask you what you think?" And so I did my best to give her such advice as I could. And then she said, "You know, my husband would never understand this. He's really the kind of guy to whom this wouldn't make any sense, so I just, you know, it's just between us." And I said, "Yes, that's fine." On Sunday of the same conference, her husband took me aside, and he said, "My wife wouldn't think that I was really much of a guy if she knew this, but I've been dealing with this depression and I'm taking some medication, and I wondered what you think?" They were hiding the same medication in two different places in the same bedroom. And I said that I thought communication within the marriage might be triggering some of their problems. (Laughter) But I was also struck by the burdensome nature of such mutual secrecy. Depression is so exhausting. It takes up so much of your time and energy, and silence about it, it really does make the depression worse.

And then I began thinking about all the ways people make themselves better. I'd started off as a medical conservative. I thought there were a few kinds of therapy that worked, it was clear what they were -- there was medication, there were certain psychotherapies, there was possibly electroconvulsive treatment, and that everything else was nonsense. But then I discovered something. If you have brain cancer, and you say that standing on your head for 20 minutes every morning makes you feel better, it may make you feel better, but you still have brain cancer, and you'll still probably die from it. But if you say that you have depression, and standing on your head for 20 minutes every day makes you feel better, then it's worked, because depression is an illness of how you feel, and if you feel better, then you are effectively not depressed anymore. So I became much more tolerant of the vast world of alternative treatments.

And I get letters, I get hundreds of letters from people writing to tell me about what's worked for them. Someone was asking me backstage today about meditation. My favorite of the letters that I got was the one that came from a woman who wrote and said that she had tried therapy, she had tried medication, she had tried pretty much everything, and she had found a solution and hoped I would tell the world, and that was making little things from yarn. (Laughter) She sent me some of them. (Laughter) And I'm not wearing them right now. I suggested to her that she also should look up obsessive compulsive disorder in the DSM.

And yet, when I went to look at alternative treatments, I also gained perspective on other treatments. I went through a tribal exorcism in Senegal that involved a great deal of ram's blood and that I'm not going to detail right now, but a few years afterwards I was in Rwanda working on a different project, and I happened to describe my experience to someone, and he said, "Well, you know, that's West Africa, and we're in East Africa, and our rituals are in some ways very different, but we do have some rituals that have something in common with what you're describing." And I said, "Oh." And he said, "Yes," he said, "but we've had a lot of trouble with Western mental health workers, especially the ones who came right after the genocide." And I said, "What kind of trouble did you have?" And he said, "Well, they would do this bizarre thing. They didn't take people out in the sunshine where you begin to feel better. They didn't include drumming or music to get people's blood going. They didn't involve the whole community. They didn't externalize the depression as an invasive spirit. Instead what they did was they took people one at a time into dingy little rooms and had them talk for an hour about bad things that had happened to them." (Laughter) (Applause) He said, "We had to ask them to leave the country." (Laughter)

Now at the other end of alternative treatments, let me tell you about Frank Russakoff. Frank Russakoff had the worst depression perhaps that I've ever seen in a man. He was constantly depressed. He was, when I met him, at a point at which every month he would have electroshock treatment. Then he would feel sort of disoriented for a week. Then he would feel okay for a week. Then he would have a week of going downhill. And then he would have another electroshock treatment. And he said to me when I met him, "It's unbearable to go through my weeks this way. I can't go on this way, and I've figured out how I'm going to end it if I don't get better. But," he said to me, "I heard about a protocol at Mass General for a procedure called a cingulotomy, which is a brain surgery, and I think I'm going to give that a try." And I remember being amazed at that point to think that someone who clearly had so many bad experiences with so many different treatments still had buried in him somewhere enough optimism to reach out for one more. And he had the cingulotomy, and it was incredibly successful. He's now a friend of mine. He has a lovely wife and two beautiful children. He wrote me a letter the Christmas after the surgery, and he said, "My father sent me two presents this year, First, a motorized C.D. rack from The Sharper Image that I didn't really need, but I knew he was giving it to me to celebrate the fact that I'm living on my own and have a job I seem to love. And the other present was a photo of my grandmother, who committed suicide. As I unwrapped it, I began to cry, and my mother came over and said, 'Are you crying because of the relatives you never knew?' And I said, 'She had the same disease I have.' I'm crying now as I write to you. It's not that I'm so sad, but I get overwhelmed, I think, because I could have killed myself, but my parents kept me going, and so did the doctors, and I had the surgery. I'm alive and grateful. We live in the right time, even if it doesn't always feel like it."

I was struck by the fact that depression is broadly perceived to be a modern, Western, middle-class thing, and I went to look at how it operated in a variety of other contexts, and one of the things I was most interested in was depression among the indigent. And so I went out to try to look at what was being done for poor people with depression. And what I discovered is that poor people are mostly not being treated for depression. Depression is the result of a genetic vulnerability, which is presumably evenly distributed in the population, and triggering circumstances, which are likely to be more severe for people who are impoverished. And yet it turns out that if you have a really lovely life but feel miserable all the time, you think, "Why do I feel like this? I must have depression." And you set out to find treatment for it. But if you have a perfectly awful life, and you feel miserable all the time, the way you feel is commensurate with your life, and it doesn't occur to you to think, "Maybe this is treatable." And so we have an epidemic in this country of depression among impoverished people that's not being picked up and that's not being treated and that's not being addressed, and it's a tragedy of a grand order. And so I found an academic who was doing a research project in slums outside of D.C., where she picked up women who had come in for other health problems and diagnosed them with depression, and then provided six months of the experimental protocol. One of them, Lolly, came in, and this is what she said the day she came in. She said, and she was a woman, by the way, who had seven children. She said, "I used to have a job but I had to give it up because I couldn't go out of the house. I have nothing to say to my children. In the morning, I can't wait for them to leave, and then I climb in bed and pull the covers over my head, and three o'clock when they come home, it just comes so fast." She said, "I've been taking a lot of Tylenol, anything I can take so that I can sleep more. My husband has been telling me I'm stupid, I'm ugly. I wish I could stop the pain."

Well, she was brought into this experimental protocol, and when I interviewed her six months later, she had taken a job working in childcare for the U.S. Navy, she had left the abusive husband, and she said to me, "My kids are so much happier now." She said, "There's one room in my new place for the boys and one room for the girls, but at night, they're just all up on my bed, and we're doing homework all together and everything. One of them wants to be a preacher, one of them wants to be a firefighter, and one of the girls says she's going to be a lawyer. They don't cry like they used to, and they don't fight like they did. That's all I need now is my kids. Things keep on changing, the way I dress, the way I feel, the way I act. I can go outside not being afraid anymore, and I don't think those bad feelings are coming back, and if it weren't for Dr. Miranda and that, I would still be at home with the covers pulled over my head, if I were still alive at all. I asked the Lord to send me an angel, and he heard my prayers."

I was really moved by these experiences, and I decided that I wanted to write about them not only in a book I was working on, but also in an article, and so I got a commission from The New York Times Magazine to write about depression among the indigent.

And I turned in my story, and my editor called me and said, "We really can't publish this."

And I said, "Why not?"

And she said, "It just is too far-fetched. These people who are sort of at the very bottom rung of society and then they get a few months of treatment and they're virtually ready to run Morgan Stanley? It's just too implausible." She said, I've never even heard of anything like it."

And I said, "The fact that you've never heard of it is an indication that it is news." (Laughter) (Applause) "And you are a news magazine."

So after a certain amount of negotiation, they agreed to it. But I think a lot of what they said was connected in some strange way to this distaste that people still have for the idea of treatment, the notion that somehow if we went out and treated a lot of people in indigent communities, that would be an exploitative thing to do, because we would be changing them. There is this false moral imperative that seems to be all around us that treatment of depression, the medications and so on, are an artifice, and that it's not natural. And I think that's very misguided. It would be natural for people's teeth to fall out, but there is nobody militating against toothpaste, at least not in my circles.

And people then say, "Well, but isn't depression part of what people are supposed to experience? Didn't we evolve to have depression? Isn't it part of your personality?" To which I would say, mood is adaptive. Being able to have sadness and fear and joy and pleasure and all of the other moods that we have, that's incredibly valuable. And major depression is something that happens when that system gets broken. It's maladaptive.

People will come to me and say, "I think, though, if I just stick it out for another year, I think I can just get through this."

And I always say to them, "You may get through it, but you'll never be 37 again. Life is short, and that's a whole year you're talking about giving up. Think it through."

It's a strange poverty of the English language, and indeed of many other languages, that we use this same word, depression, to describe how a kid feels when it rains on his birthday, and to describe how somebody feels the minute before they commit suicide.

People say to me, "Well, is it continuous with normal sadness?" And I say, in a way it's continuous with normal sadness. There is a certain amount of continuity, but it's the same way there's continuity between having an iron fence outside your house that gets a little rust spot that you have to sand off and do a little repainting, and what happens if you leave the house for 100 years and it rusts through until it's only a pile of orange dust. And it's that orange dust spot, that orange dust problem, that's the one we're setting out to address.

So now people say, "You take these happy pills, and do you feel happy?" And I don't. But I don't feel sad about having to eat lunch, and I don't feel sad about my answering machine, and I don't feel sad about taking a shower. I feel more, in fact, I think, because I can feel sadness without nullity. I feel sad about professional disappointments, about damaged relationships, about global warming. Those are the things that I feel sad about now. And I said to myself, well, what is the conclusion? How did those people who have better lives even with bigger depression manage to get through? What is the mechanism of resilience? And what I came up with over time was that the people who deny their experience, the ones who say, "I was depressed a long time ago and I never want to think about it again and I'm not going to look at it and I'm just going to get on with my life," ironically, those are the people who are most enslaved by what they have. Shutting out the depression strengthens it. While you hide from it, it grows. And the people who do better are the ones who are able to tolerate the fact that they have this condition. Those who can tolerate their depression are the ones who achieve resilience.

So Frank Russakoff said to me, "If I had it again to do over, I suppose I wouldn't do it this way, but in a strange way, I'm grateful for what I've experienced. I'm glad to have been in the hospital 40 times. It taught me so much about love, and my relationship with my parents and my doctors has been so precious to me, and will be always."

And Maggie Robbins said, "I used to volunteer in an AIDS clinic, and I would just talk and talk and talk, and the people I was dealing with weren't very responsive, and I thought, 'That's not very friendly or helpful of them.' And then I realized, I realized that they weren't going to do more than make those first few minutes of small talk. It was simply going to be an occasion where I didn't have AIDS and I wasn't dying, but could tolerate the fact that they did and they were. Our needs are our greatest assets. It turns out I've learned to give all the things I need."

Valuing one's depression does not prevent a relapse, but it may make the prospect of relapse and even relapse itself easier to tolerate. The question is not so much of finding great meaning and deciding your depression has been very meaningful. It's of seeking that meaning and thinking, when it comes again, "This will be hellish, but I will learn something from it." I have learned in my own depression how big an emotion can be, how it can be more real than facts, and I have found that that experience has allowed me to experience positive emotion in a more intense and more focused way. The opposite of depression is not happiness, but vitality, and these days, my life is vital, even on the days when I'm sad. I felt that funeral in my brain, and I sat next to the colossus at the edge of the world, and I have discovered something inside of myself that I would have to call a soul that I had never formulated until that day 20 years ago when hell came to pay me a surprise visit. I think that while I hated being depressed and would hate to be depressed again, I've found a way to love my depression. I love it because it has forced me to find and cling to joy. I love it because each day I decide, sometimes gamely, and sometimes against the moment's reason, to cleave to the reasons for living. And that, I think, is a highly privileged rapture.

Thank you. 

Setting the Tone New Beginnings

12:12 By

From: Ian Lawton
Spiritual teacherof inner wisdom,
divine love, deeper consciousness,
oneness, peace, and abundance.

Contact Ian: ian@soulseeds.com

I like to get up early in the morning; the stillness is contagious and fills me with optimism. Everything feels so possible. The first thing I do before anyone else gets up, before eating breakfast, before opening email accounts or checking social media, is write a short stream of consciousness, the first thing that comes to mind and an affirmation to go with it. It sets an intention for my day. Then I post the same thought to Facebook and theSoulseeds website and get on with the next thing. It’s my early morning ritual. On the rare occasion that I sleep late, it feels like the day never begins properly, I never catch up and feel out of sorts.
One of the most exciting features of new beginnings is that you have the opportunity to set the tone for all that follows. Your first thoughts set the tone for your intentions. The first words spoken set the tone for a whole conversation. Your first actions set the tone for the rest of your day. All these firsts and more are like the candles and soft music that set the tone for romance, or the incense and soft lighting that sets the tone for relaxation. Mood, intention and tone.
Sue Monk Kidd sets the tone for her book The Secret Life of Bees with these opening words,
And when you get down to it, Lily, that is the only purpose grand enough for a human life. Not just to love but to persist in love.
Imagine if we all set the intention to love, not just when it suits us, not just when it feels good, but to persist in love throughout the days and years of our lives. Imagine the tone we would set for the world. There would be a love revolution. Imagine what we would achieve. I read an interview with Steve Wozniak, cofounder of Apple. He was asked what he liked best about working at Apple in the early days. He said,
Back then it was so exciting. Everything we did we were setting the tone for the world. We were thecomputer to have in your home. Any project you worked on had value. Today, if you work on 10 different things, one of them might have value.
We can safely say that Apple started out putting their best foot forward and the rest is history. That’s another expression we use for setting the tone of a beginning- starting out on the right foot or putting your best foot forward. That phrase always brings to my mind the orders of my high school football coaches. Always line up with your outside foot set resolutely forward, ready to move straight ahead. It was partly a body language issue. You faced back towards the action, setting a tone and sending a message. As Shakespeare said in King John, “Make haste; the better foot before.”
New beginnings are a privilege, and not to be taken for granted. The opportunity to start over, start new, rewrite the script, build something from the ground up, set the tone for an intention, are all part of the forgiving nature of the universe. Second, third and seven hundredth chances are built into the nature of life. When you truly believe that, you can set about living on purpose and without regrets. You are not alive at this time in history with your unique blend of experience and skill by accident. You are not reading this article at this time in your life by accident. There are things that you still need to express and manifest in the world, and your next thoughts, words and actions will set the tone for the rest of your life and help to create the future for all. Your kindred spirits are others who believe in second chances and fresh starts, and live their lives putting their best foot forward. Imagine the love revolution if more of us lived this way.
Just because you set out with awesome intention, and putting your best foot forward, doesn’t mean you get it right every time. That’s fine. The certainty of imperfection won’t prevent you from moving forward with intention. You will start over as many times as you need to.
New beginnings are an awesome opportunity for renewed authenticity. Even the nervous energy is a gift to channel your best and most urgent efforts. The ground floor is where it all begins, and where you intend to jump in and set the tone for all that follows. Set your best foot forward, and the other is sure to follow.
I will end this series on new beginnings with an inspiration from the film The Curious Case of Benjamin Button. Benjamin grows up backwards; beginning his life as an old man and ending up as a baby. He grows younger with each passing moment. There is a joke that if it had won best picture at the Academy Awards, the Oscar would have been given out at the beginning of the night instead of the end when they normally hand out best picture. My favorite scene in the movie is when his daughter reads a letter Benjamin wrote to her, having never met her father.

For what it’s worth: it’s never too late or, in my case, too early to be whoever you want to be. There’s no time limit, stop whenever you want. You can change or stay the same; there are no rules to this thing. We can make the best or the worst of it. I hope you make the best of it. And I hope you see things that startle you. I hope you feel things you never felt before. I hope you meet people with a different point of view. I hope you live a life you’re proud of. If you find that you’re not, I hope you have the strength to start all over again.

Career Choices

11:58 By

I am often asked for help about career choices from aspiring entrepreneurs, professionals or students. I try my best to share my insights on career choices but the following advice that I received from Mr. Richard Branson, sums it all up for everyone who is either at career cross roads or wants to make a shift in his/her career:

"While you are facing choices about your path to a career, and in all the choices that follow, focus on your own goals and try not to be distracted by those of others. Consider the needs of your community and how you might best contribute. What is your vision for change? Start working towards that. In business, as in life, what matters is that you do something POSITIVE."

Tuesday, January 7

ARROW KEYS IN C++

00:09 By

WANT TO INCLUDE ARROW KEYS IN YOUR C++ PROGRAM !!! JUST copy this code in your compiler, execute and press arrow keys. .. this code is only for hint on how to use arrow keys oin your c++ program..... REMEMBER ASCII codes of arrow keys 1. Up key = 72 2. Down key = 80 3. Left key = 75 4. Right key = 77
//arrow keys in c++
#include
#include 
using namespace std;
 
void main()
{
 char a;
  
 while(a<100)//infinite loop
 
 {
 
 a = getch();
 if (a == 80) 
  cout<<"DOWN\n";
 
 else
  if (a == 72) 
   cout<<"UP\n";
 
 else
  if (a == 77) 
   cout<<"RIGHT\n";
 
 else
  if (a == 75) 
  cout<<"LEFT\n";
 }
}
 

 

Sunday, December 22

C++ geometry [for game projects and similar]

15:17 By

Hi.
 Let's just call it a graphics function blog thoe i just know 2 or 3 of them but they'll be enough for simple drawing.

 This will require gotoxy function which is mentioned in a blog from Umair Sajid. The recap is as follow:
________________________________________________________________
#include <iostream>
#include <windows.h>

void gotoxy ( int , int );       //prototype
{main function and stuff}
void gotoxy(int x,int y)       //header. with x and y as coordinates to where cursor goes
{
     HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
                                         //output handle to be defined for function
     COORD coordinates;
                                         //COORD is a data type of windows.h header to store 2D graphic position's                                                  coordinates.
     coordinates.X = x;
                                         //save x coordinate value into the COORD structure's data type
     coordinates.Y = y;
                                         //similarly for y axis coordinate
     SetConsoleCursorPosition( hOut , coordinates );
                                         //finaly the function which set's the position of the cursor that you
                                           gave
}
define it and then you are good to go for the graphics functions
=======================================================================
  1. Simple lines:
     To understand this, just look up to coordinates of a simple line:
They change in a simple manner:
x,y
x+1,y
x+2,y
x+3,y
x+4,y
x+5,y
Here is a more understandable form:
x,y
++x,y
++x,y
++x,y
++x,y
++x,y
so here is the functions:
________________________________________________________________________
1. Horizontal line:
void horizontal_line(int , int , int);
void horizontal_line(int x, int y, int size)
{
      for(int i=0;i<size;i++)
      {
            gotoxy(x,y);
            cout<<char(219);
            x++;
      }
}
2. Vertical line:
void vertical_line(int , int , int);
void vertical_line(int x, int y, int size)
{
      for(int i=0;i<size;i++)
      {
            gotoxy(x,y);
            cout<<char(219);

            y++;
      }
}
=======================================================================
 2. Simple squares:
void square(int , int , int , int);
void square( int x, int y, int width, int length )
{
       int t_x;
       for(int i=0;i<length;i++)
       {
              t_x=x;
              for(int j=0;j<width;j++)
             {
                     gotoxy(t_x,y);
                     cout<<char(219);
                     t_x++;
             }
              y++;
        }
}
=======================================================================
You can also use colours for making it better.
Errors in code are possible as i did'nt made it on compiler so don't think that it won't work. In case of any problem you can email me.
That's all. I hope this'll help ya with simple interfaces. I'll give other methods for circle, hollow square ( completely hollow ) when obviously i need to make them and use them :)
Asslam-o-Alalikum.

Saturday, December 14

Use of ascii characters to print table in console


A post on using ascii chart for printing a table in console
#include <iostream>
using namespace std;

int main() {
 char topLeftCorner = (char)201, bottomLeft = (char)200, topRight= (char)187;
 char bottomRight = (char)188, horizontal = (char)205, vertical = (char)186;

 cout<<topLeftCorner;

 for(int i=0; i<10;i++)
  cout<<horizontal;

 cout<<topRight<<endl;

 cout<<vertical;

 for(int i=0;i<10;i++)cout<<' ';

 cout<<vertical;
 cout<<endl<<bottomLeft;

 for(int i=0; i<10;i++)
  cout<<horizontal;

 cout<<bottomRight;

 //or you can use ascii character 219 for all of the purposes, it is very easy to use
 return 0;
}

Wednesday, December 11

sorting of character arrays based on first character only

18:50 By

A code for Sir Saeed

/**
 * code by http://CppQA.blogspot.com
 * sorting of character arrays based on first character only
 * C++
*/
#include <iostream>
#include <string.h>
using namespace std;

int main() {
 char countries[5][15] = {"Pakistan","India","Afghanistan","Iran","China"};
 for(int i=0;i<5;i++)
 {
  for(int j=0;j<5-1;j++)
  {
   if(countries[i][0] < countries[j][0])
   {//swaping
    char temp[15];
    strcpy(temp,countries[i]);
    strcpy(countries[i],countries[j]);
    strcpy(countries[j],temp);
   }
  }
 }
 
 //print
 for(int i=0;i<5;i++)cout<<countries[i]<<endl;
 return 0;
}

Sunday, December 8

Filing in C++

13:37 By

Its very irritating to input again and again and best way to avoid it is FILING and it is pretty simple :)

Code:

 #include<iostream.h>
 #include<conio.h>
 #include<fstream.h>
 void main(){

   char name[15];

//---------------- READING FROM  FILE ---------------

ifstream insertion("contries.txt");

cout<<"\t\tReading data from file contries.txt\n\n"<<endl;

   while(insertion>>name)
   {
    cout<<name<<endl;
   }

insertion.close();

//--------------- WRITING IN FILE ------------------

//to clear the data of "data.txt" so that new content overwrites the file

// if u want to append new data to previous file skip the following two lines

ofstream empty("data.txt");

empty.close();

 //writing new data in "data.txt"

cout<<"\t\tWriting following data in file data.txt\n\n"<<endl;

int copyng[]={1995,1996,1997,1998,1999,2000,0,8,7,6};
ofstream burr("data.txt",ios::app);

int n=sizeof(copyng)/sizeof(copyng[0]);     //to find out the size of array in terms of # of elements

   for(int i=0;i<n;i++)
   {
   cout<<copyng[i]<<endl;
   burr<<" "<<copyng[i]; }
   burr.close();
   cout<<"\n\t\tPress any key to exit"<<endl;
   getche();
   }





Note:
 Your .txt file should be in the same location as that of your .cpp file.

For More Info:

For more details and possible values of parameters visit the link below
http://www.cplusplus.com/doc/tutorial/files/
Include filing in your programs and ENJOY


Regards





Sunday, November 24

Moving Text - SCreen Saver in C++

Moving Text - SCreen Saver in C++

Although it is exam time but i just can't help myself from compiler;; below is just code, nothing much to explain; just copy past and run it is compatible with visual studio as no graphic thing is used; enjoy

  1. #include<iostream>
  2. #include<windows.h>
  3. HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
  4. void clr(int y){SetConsoleTextAttribute(out,y);}
  5. void go(int a,int b){COORD cord; cord.X = a; cord.Y = b; SetConsoleCursorPosition(out,cord);}
  6. using namespace std;
  7. void G(int x,int y)
  8. {go(x,y);cout<<char(220)<<char(220)<<char(220)<<char(220)<<char(220)<<endl; y++;
  9. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(219)<<endl; y++;
  10. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(32)<<endl; y++;
  11. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(223)<<char(219)<<endl; y++;
  12. go(x,y);cout<<char(223)<<char(223)<<char(223)<<char(223)<<char(223)<<endl;}
  13. void A(int x,int y)
  14. {go(x,y);cout<<char(220)<<char(220)<<char(220)<<char(220)<<endl; y++;
  15. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(219)<<endl; y++;
  16. go(x,y);cout<<char(219)<<char(220)<<char(220)<<char(219)<<endl; y++;
  17. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(219)<<endl; y++;
  18. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(219)<<endl;}
  19. void M(int x,int y)
  20. {go(x,y);cout<<char(219)<<char(220)<<char(32)<<char(220)<<char(219)<<endl; y++;
  21. go(x,y);cout<<char(219)<<char(32)<<char(287)<<char(32)<<char(219)<<endl; y++;
  22. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(219)<<endl; y++;
  23. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(219)<<endl; y++;
  24. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(219)<<endl;}
  25. void E(int x,int y)
  26. {go(x,y);cout<<char(220)<<char(220)<<char(220)<<char(220)<<char(220)<<endl; y++;
  27. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(32)<<endl; y++;
  28. go(x,y);cout<<char(219)<<char(205)<<char(205)<<char(32)<<char(32)<<endl; y++;
  29. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(32)<<endl; y++;
  30. go(x,y);cout<<char(223)<<char(223)<<char(223)<<char(223)<<char(223)<<endl;}
  31. void R(int x,int y)
  32. {go(x,y);cout<<char(220)<<char(220)<<char(220)<<char(220)<<char(220)<<endl; y++;
  33. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(32)<<char(219)<<endl; y++;
  34. go(x,y);cout<<char(219)<<char(220)<<char(220)<<char(220)<<char(219)<<endl; y++;
  35. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(219)<<char(32)<<endl; y++;
  36. go(x,y);cout<<char(219)<<char(32)<<char(32)<<char(219)<<char(220)<<endl;}
  37. int main()
  38. {
  39. int X=0,x1,x2,x3,x4,x5,x6,y=5; x1=0; x2=6; x3=12; x4=18; x5=24; x6=30;
  40. for (int i=0;i<1;)
  41. {clr(9);go(x1,y);G(x1,y);if(x1>72){x1=1;}x1++;clr(12);go(x2,y);A(x2,y);if(x2>72){x2=1;}x2++;
  42. clr(6);go(x3,y);M(x3,y);if(x3>72){x3=1;}x3++;clr(9);go(x4,y);M(x4,y);if(x4>72){x4=1;}x4++;
  43. clr(10);go(x5,y);E(x5,y);if(x5>72){x5=1;}x5++;clr(12);go(x6,y);R(x6,y);if(x6>72){x6=1;}x6++;
  44. if(x1==2){y+=3;} if(y>50){y=3;}system("cls");}
  45. return 0;
  46. }
for feedback:



    
    

    Saturday, November 23

    Hollow Square & Hollow diamond & Hollow Triangle

    Hollow Square & Hollow diamond & Hollow Triangle

    It's basically a request from a student as we go further in loops and functions we need to know more tricks and practise more for these things which eventually leads to good programming;
    Basic concept to understand;
    1. Notice if any line of the shape is going to match original filled shape; i.e. in square the first line and last line are filled!
    2. Make sure you know the ration of spaces for hollow part to the number of characters in the corresponding filled space i.e. if your square is of the size of 5x5 so it is going to be 5 characters in a single line; but in hollow shape you are going to print only 2 characters ; the first one and last one no matter how much long line is this; but here in 5 character line the total spaces would be countable as spaces=one side length - 2;
    Prepare for the basic shapes looping that will be joined together to make final shape i.e. to make diamond you place 4 triangles together if you ever made it:

    Hence by mixing these points you can make logic of this king of shapes.

    Basic Hollow looping;
    In this kind of looping you have to make sure that ration of lines is safely described to make appropriate loop
    Square concept:
    1. int main()
    2. {
    3.         int size;            //suppose it is 5
    4.         cin>>size;
    5.         for (int i = 0 ; i < size ; i++ ) //runs 5 times
    6.          {
    7.                  cout  <<  "*" ;          //first char
    8.                  for (int j=2;j<size;j++) //runs 5-2 times
    9.                  {
    10.                      cout<<" ";
    11.                  }
    12.                  cout  <<  "*" ;          //last char
    13.           }
    14.    return 0;
    15. }
    Now here in line 8 you can see that formula which subtracts number of characters from hollow line to make it even to the rest of shape, it could be 5 - 3  or maybe  5-4  required for the program hence the distribution of spaces and loops as well; depending on the shape.
    And for first and last line here is simple method:
    1.  if ( line 1 || last line ) //mean i==1 or i==size-1 according to loop iteration
    2.  {
    3.          for ( int a=0;a<size;a++ )
    4.          {
    5.              cout<< "*" ;
    6.          }
    7.       cout << endl ; continue ;
    8.  }
    Put it in main loop Before the space loop so that if first line is being print it would print it and skip the space printing for first and last line.
    i guess it is enough for the basic concept and you will be able to make assignment ;; I'll give complete codes after exams;; thanks for reading and for feedback or any questions:
    Join the group  on facebook for constant news about new posts..
    
    

    Friday, November 22

    gotoxy() function in c++ by Umair Sajid

    21:49 By

    gotoxy() function :

    The gotoxy function is used to to move the cursor to a specified location on the screen. Its Just Something Other then just Sequential Execution .It moves the cursor with respect to x axis and y axis. It is very useful when the output is to be displayed at a specified location on the screen.

    Working: 

    The Variable x indicates x-axis. Its Value can be from 0 to 79. The Variable y indicates the y-axis. Its Value can be from 0 to 24.

    Program:

    #include               // Header Files 
    #include               // for getch() function 
    #include               
    #include             // Necessary when treating consoles  
    using namespace std;
    void gotoxy (int x, int y)
        {
             COORD coordinates;     // coordinates is declared as COORD
             coordinates.X = x;     // defining x-axis
             coordinates.Y = y;     //defining  y-axis
            SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coordinates);       
        }
    int main()              
    {
        int x;
        int y; 
     
        cout<<"Enter x: ";
        cin>>x;
        cout<<"Enter y: ";
        cin>>y;
            
        gotoxy(x,y);     // function call 
        cout<<"C++ Clan Umair Sajid"<<endl;
        getch();
        return EXIT_SUCCESS;
    }
    

    Tuesday, November 19

    Easy Colouring

    As promissed here is bit easy technique for those colour commands;
    Hope you guys understand it :
    Theme here is to use funcitons to determin command stuff i.e. how much easy would it be if you only have to type 

    color(r); //red colour

    here is the function that will help you to use colours easily
    ______________________________________________________________________

    1. HANDLE Output=GetStdHandle(STD_OUTPUT_HANDLE);
    2. void colour(int x)
    3. {SetTextAttribute(Output,x);}
    ______________________________________________________________________
    here if you remember colour codes integers just use them as follows:

    colour(10);      //green


    and if you want to make it runing upon character values you can place switch in it

    1. HANDLE Output=GetStdHandle(STD_OUTPUT_HANDLE);
    2. void colour(char ch)
    3. {
    4. int x;
    5. switch (ch)
    6. {
    7. case 'r':  x=12; break;                       //red
    8. case 'b': x=9;   break;                        //blue
    9. case 'g': x=10; break;                        //green
    10. case 'a': x=11; break;                        //aqua
    11. case 'v': x=13; break;                         //voilet
    12. case 'y': x=14; break;                         //yellow
    13. case 'w: x=15; break;                         //white
    14. }
    15.  SetTextAttribute(Output,x);
    16. }

    now you can call it as this;
    colour('r');                    //red colour
    end of post;



    
    

    Monday, November 18

    Play Sound in Your CPP Program

    Till now, all of us have coded C++ programs on the black & white console, some know how to color the text on string.
    Lets go a step ahead and introduce sound being played as your program runs.

    Interesting, Right?
             Yes, you'll have a new effect to add in your code :-)

    How to Do?
             The amazing sound feature consists of just two lines,
    1. The PlaySound function call.
    2. The header file that contains this function.

    Code:
               
     #include<iostream.h>
     #include<conio.h>
     #include <string.h>
     #include <windows.h>
     using namespace std;
            
     int main()
     {
                     PlaySound("file_name.wav",NULL,SND_FILENAME|SND_LOOP);
     // PlaySound method is defined in windows.h
     // file_name is the name of your sound file in .wav format
     getche();
     return 0;
     }

    Note:
     Your .wav file should be in the same location as that of ur .cpp file.

    More:


    For details and possible values of parameters in PlaySound function visit the link below
    http://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx
    Include sound in your programs and have FUN
    Stay Blessed :-)


    Regards

    
    

    Bit Level Manipulation and Programming in C++

    C++ is a classical language and it allows us to manipulate bits in much better ways. for starter we will learn 2 kind of bit operators namely bit shift operators

    Left shift operator: <<
    Right shift operator: >>

    The left shift operator shifts all bits to left and left most bit(MSB) is dropped/deleted
    similarly the right shift operator shifts all bits to right and LSB(right most bit) is dropped

    e.g. binary of 2 will be 00000010 which is when shifted to left becomes 00000100 which in decimal is 4
    so it also means that shifting to left multiplies by 2 and shifting to right divides by 2.

    void main()
    {
    int castles = 2;
    castles = castles<<1; //this will set castles = 4 i.e. 2x2
    castles <<=2; //this will left shift by 2 bits and hence castles is now multiplied by 2 two times so it now becomes 16
    //you can experiment for your self with these tricks
    //PS these are heavily used for masking purposes and files compression as well
    

    Reverse any Integer without strings

    It seems now are a stronger community to write generalized programs for FAST NU as well :)
    I am posting a program below which reverses any number with just 1 while loop.
    See if it works :P
    PS please if you copy this or get inspired from this post for your blog then mention us in the post that will be a great gesture than just being douche 3:)
    //Code by Umar Farooq
    /**
     * follow us at http://CppQA.blogspot.com
     * 
    **/
    #include <iostream>
    using namespace std;
    
    int main() {
     int number = 12345678;
     cout<<"Reverse of number "<<number<<" is ";
     while(number)
     {
      cout<<number%10;
      number/=10;
     }
     
     return 0;
    }
    

    Sunday, November 17

    Loading bar in C++

    Since we are high on special effects these days, so below is the code to make a loading bar in C++.

    #include iostream.h
    #include conio.h
    #include windows.h
    #include dos.h
    
    void main()
    {
     system("color 0a");
     cout<<"\n\n\n\t\t\t\tPlease wait while loading\n\n";
     char a=177, b=219;
     cout<<"\t\t\t\t";
     for (int i=0;i<=15;i++)
     cout<<a;
     cout<<"\r";
     cout<<"\t\t\t\t";
     for (int i=0;i<=15;i++)
     {
      cout<<b;
      for (int j=0;j<=1e8;j++); //You can also use sleep function instead of for loop
     }
    
     clrscr();
     cout<<"\n\n\n\t\t\tHELLO WORLD\n\n\t\t\tShashka made by Ivan :P";
    
     getch();
    }

    Output is :

    Addition of two 2-Dimensional Arrays

    Below is the code that I made to add the elements of a 2-D array.
    The 2-dimensional arrays have been previously discussed, what they are and how to initialize them.
    http://cppqa.blogspot.com/2013/11/two-dimension-pointers-c.html

    For those (like me) who are still confused, think of it like this,
    An 1-dimensional array can hold element like this:
    [ 1 3 5 7 9]    => array1[5]

    Whereas a 2-D array will hold elements much like a matrix, like this:
    | 2  4 |
    | 6  8 |            => array2[2][2]
    So we get a matix of 2rows and 2 columns.

    Now that we have a basic concept of 2-D array, lets go a little further.
    The initialization is petty much same as that in the above link. We shall only do the addition of 2-D arrays.

    int main()
    {
    int x[2][2] , y[2][2] , z[2][2];
    //for simplicity 2,2 matrix is used, but you can also make a user specified
    
    int i , j , k;
    
    cout<<"enter number for 1st matrix"<<endl; //applying for loop to enter the data
    
    for( i = 0 ; i < 2 ; i++)
    for( j = 0 ; j < 2 ; j++)
    {
    cin>>x[i][j];
    }
     
    cout<<"enter numbers for 2nd matrix"<<endl;
    for( i = 0 ; i < 2 ; i++)
    for( j = 0 ; j < 2 ; j++)
    {
    cin>>y[i][j];
    }
    
    for( i = 0 ; i < 2 ; i++)
    for( j = 0 ; j < 2 ; j++)
    {
    z[i][j] = 0;
    for( k = 0 ;k < 2 ; k++)
    z[i][j]=x[i][j]+y[i][j]; // x + y stored in z
    }
    
    cout<<"additon of matrix is"<<endl;   // z is displayed
    for( i = 0 ; i < 2 ; i++)
    {
    for( j = 0 ; j < 2 ; j++)
    cout<<z[i][j]<<"\t";
    cout<<"\n";
    }
    getch();
    return 0;
    }
    
    
    So here it is a simple program to add two 2-D arrays

    Saturday, November 16

    Recursive functions

    19:30 By

    Recursive functions

    Recursive functions are way much difficult then simple functions
    1. in a function you place set of commands in a bracket and use it as many time as u want
    2. in recursive functions you make such a function which with the help of other functions and the repetition of it's own body gives you output ; complex but short code.
    As compared to recursive function simple function when called runs specific commands inside it's body (could be loop but still simple as for command) it's decision criteria is small or let's say limited.
    In recursive function you make some kind of super function which has wide choice of features including that it's body is small.
    Definition: When a function calls itself or other functions while execution it is said to be recursive function.
    Here is a simple example : 
    To print a countdown form a digit that user inputs up to '0'
    1. #include <iostream>
    2. using namespace std;
    3. void sample_recursive_function(int N)
    4. {
    5.            if (N==0) { cout<<"N"<<endl; }
    6.          else  { cout<<"N"<<endl; --N; sample_recursive_function(N);}
    7. }
    8. int main()
    9. {
    10.           int N;
    11.           cout<<"Enter the number: ";
    12.           cin>>N;
    13.           sample_recursive_function(N);
    14.           return 0;
    15. }
    Enter the number: 5                                                                                                                                                       
    5                                                                                                                                                                                              
    4                                                      -                                                                                                                                      
    3                                                                                                                                                                                              
    2                                                                                                                                                                                              
    1                                                                                                                                                ^   --                                     
    0                                                                                                                                                                       -                     
    Press any key to continue . . . .                                                                                                                                  

    In this function there is not much as coding or might say complex coding but it is a complex logic. This is what is difference between these functions.
    This function can also call other functions described in this program hence you can generate loop in which more then 1 functions will work with each other to generate desired output;

                 A -------------> B
                                          |
                  |                             |
                  |                             |
                  |                            V
                D <-------------  C
    In this diagram functions are related to each other because when you call one function in another function the control goes to this function and once this function is finished then it will allow for control to go back to main called function..
    Here is an example :
    1.              int sum(int a , int b )                                      //f1
    2.             {            
    3.                         int c=  a+b;
    4.                         if  ( check_type(c)  == 1 )
    5.                        { return c;
    6.                         else
    7.                                 c+=1;
    8.             }

    9.             int check_type(int x)                                   //f2
    10.             {
    11.                       int check=x; 
    12.                      if ( x%2==0 ) 
    13.                       { return 1;} 
    14.                      if ( c%2!=0 )
    15.                        { return 0; }
    16.             }
    Here f1 is calling f2 to change it's output. A simple recursive function.
    Hope you understood the concept of recursive functions; gud luck; Allah HAfiz