Showing posts with label to. Show all posts
Showing posts with label to. Show all posts

Sunday, April 13, 2014

Using a Stack to Reverse Numbers

Yeah, I heard many of you saying this and I know it’s no big deal to
reverse a number and neither is it using stack to do so. I am writing this just
to give you an example of how certain things in a program can be done using
stacks. So, let’s move on…


As many of you already know, a stack is a Data Structure in which data can
be added and retrieved both from only one end (same end). Data is stored linearly
and the last data added is the first one to be retrieved, due to this fact it
is also known as Last-In-First-Out data structure. For more info please read
Data
Structures: Introduction to Stacks
.


Now, let’s talk about reversing a number, well reversing means to rearrange
a number in the opposite order from one end to the other.


Suppose we have a number


12345


then its reverse will be


54321


Ok, now let’s have a look at the example program which does this:



// Program in C++ to reverse
// a number using a Stack

// PUSH -> Adding data to the sat ck
// POP -> Retrieving data from the stack

#include<iostream.h>

// stack class
class stack
{
int arr[100];
// top will hold the
// index number in the
// array from which all
// the pushing and popping
// will be done
int top;
public:
stack();
void push(int);
int pop();
};


// member functions
// of the stack class
stack::stack()
{
// initialize the top
// position
top=-1;
}

void stack::push(int num)
{
if(top==100)
{
cout<<"
Stack Full!
"
;
return;
}

top++;
arr[top]=num;
}

int stack::pop()
{
if(top==-1)
{
return NULL;
}

return arr[top--];
}
// member function definition ends

void main()
{
stack st;
int num, rev_num=0;
int i=1, tmp;

cout<<"Enter Number: ";
cin>>num;

// this code will store
// the individual digits
// of the number in the
// Stack
while(num>0)
{
st.push(num%10);
num/=10;
}

// code below will retrieve
// digits from the stack
// to create the reversed
// number
tmp=st.pop();
while(tmp!=NULL)
{
rev_num+=(tmp*i);
tmp=st.pop();
i*=10;
}

cout<<"Reverse: "<<rev_num<<endl;
}



The above code is pretty much straightforward and I leave it up to you to understand
it!


P.S. If you experience any problems understanding it please first read the
article Data
Structures: Introduction to Stacks


Related Articles:


Read More..

Thursday, April 10, 2014

Ways 3 D Printing Machines Are Going To Transform Our World

By Eric Slagle


If you think back over the past few years you will probably not find anything that has created such a buzz like 3D printers. These devices are like something out of a science fiction movie. They are able to take raw materials and literally print out three-dimensional objects. They have the potential to greatly change everyday living.

Medical advances have been made using these machines. Human body parts can now be fabricated from metal, plastic or actual tissues. This can have a great impact on health care and help a lot of individuals. Not only are bones and cartilage being created with these machines, it is also possible to print organs.

This technology is also very exciting for those in the exploration of space. It means that with the right materials astronauts will be able to create tools and replacement parts on demand. If something breaks down it would be a lot quicker and safer to print the replacement piece so the repair can be made that it would be to wait for help to arrive. This technology could also use robots to create a ready to use habitat for humans on other planets.

The printer uses a computer-aided design as a pattern and outputs the raw material as indicated. It may take thousands and thousands of lines depending upon the size of the object being created. Units intended for home use are not very big and are approximately the size of an inkjet printer. At $1200-$1500 these units are a bit pricier than your average inkjet.

This is an evolving technology that will definitely impact society in a huge way. The fields of medicine and science will try and push the boundaries of what can be accomplished and we will all reap the benefits. Homeowners will not be left out as they too will look for new ways to use their home printers. They can be both practical and four hobbyists as well.

This type of printing is certainly in its infancy. Right now the things we do seem crude when weighed against the potential advancements it can bring. Imagine being able to purchase and get a pattern for things like games, jewelry and other items.

One of the most exciting things about 3D printers is that they will be creating new markets and jobs. There will be new opportunities for education and training to keep up with the evolution of the technology. It may soon be commonplace in medicine, science, schools and in our homes.




About the Author:



Read More..

Wednesday, April 9, 2014

Adding Flexibility to Operators while Overloading them

  class_name class_name::operator+(int x)
{
class_name temp;

temp.a = a + x;
temp.b = b + x;

return temp;
}


With reference to the above operator
function
and supposing that ‘ob’ is an object of the class
to which this function belongs; Is the statement below legal:


ob2 = ob1 + 100;


Yes, but what about the following statement:


ob2 = 100 + ob1;


Surely this won’t work!


100 is an integer constant and has no ‘+’ operator that could add
it with user-defined types (object ‘ob’).


This certainly is a shortcoming, since often we don’t really care which
operand is where (as in addition and multiplication) and we order the operands
as necessary (as in subtraction and division).


To overcome this we can overload two-two versions of these operators
as friend
, one for ‘integer + object’ type and the other
for ‘object + integer’ type.


So, for example for addition we have to overload the ‘+’ operator
twice as below:


  friend class_name operator+(class_name,int);
friend class_name operator+(int,class_name);

Similarly we have to overload other operators.


The program below illustrates this concept:



// Program to illustrate
// the overloading of
// flexible addition
// and subtraction
// operators
#include <iostream.h>

class myclass
{
int a;
int b;

public:
myclass(){}
myclass(int x,int y){a=x;b=y;}
void show()
{
cout<<a<<endl<<b<<endl;
}

// object + int form
friend myclass operator+(myclass,int);
friend myclass operator-(myclass,int);

// int + object form
friend myclass operator+(int,myclass);
friend myclass operator-(int,myclass);
};

myclass operator+(myclass ob,int x)
{
myclass temp;

temp.a = ob.a + x;
temp.b = ob.b + x;

return temp;
}

myclass operator-(myclass ob, int x)
{
myclass temp;

temp.a = ob.a - x;
temp.b = ob.b - x;

return temp;
}

myclass operator+(int x, myclass ob)
{
// does the same thing
// because in addition
// it doesnt matters
// which operand is where
myclass temp;

temp.a = x + ob.a;
temp.b = x + ob.b;

return temp;
}

myclass operator-(int x, myclass ob)
{
myclass temp;

temp.a = x - ob.a;
temp.b = x - ob.b;

return temp;
}

void main()
{
myclass a(10,20);
myclass b(100,200);

a=a + 10;
a.show();

b=100 + b;
b.show();
}


Related Articles:


Read More..

Tuesday, April 8, 2014

Taking User Inputs to Create Personalized Pages

You might probably have seen this type of URLs:


http://somepage.com/index.php?name=noname&age=18


It of course is a dynamic web page. As a matter of fact the string after the
‘?’, the data, is what makes it dynamic. The page is dynamic because
most pages which take data this way, create the page according to the data passed.
In this post we’re going to see how pages take data, we’ll also
create a simple dynamic page which can be personalized to display user’s
name.


First, let’s understand what is in the URL


http://somepage.com/index.php?name=noname&age=18



index.php is a PHP page and everything after the ‘?’ is the data
being passed, which is


name=noname&age=18


here name and age are the two variables having the values noname and 18 respectively
which are being passed. Each variable is separated by a ‘&’
sign.


That’s it; now let’s see how we can catch these variables from
a PHP script.


This method of sending data is known as GET method. PHP has a $_GET[] array
which holds all the variables passed via this GET method.


So, if we invoke index.php as below:


http://somepage.com/index.php?name=noname&age=18


index.php will have access to the variables passed in the $_GET[] arrays as:


$var1=$_GET[‘name’];

$var2=$_GET[‘age’];


$var1 and $var2 will contain ‘noname’ and ‘18’ respectively.


Yeah, it’s that simple.


Now let’s create a simple dynamic page which can be personalized to show
the visitors name.



<?php
// have the data being passed
$name=$_GET[name];

// dot operator combines two strings
// output of PHP statements can be HTML tags
echo "<h1>Welcome ".$name."</h1>";
?>


I don’t think there is much to explain.


Now if you save the file as index.php request the above page like


index.php?name=Richard


You’d see a welcome message with the name Richard.


This method of customizing pages/site to specific users is very common and
useful. Forums, email service, social networking sites and many other types
of sites employ this method to give personalization and registered-user specific
features.


For now, we only need to give personalization to visitors and not registered
user-specific features, so let’s expand the script a bit like this



<html>
<head>
<title>Personalized Page Example</title>
<body>

<?php
// have the data being passed
$name=$_GET[name];

if ($name=="") echo "<h1>Welcome Guest</h1>";
else echo "<h1>Welcome ".$name."</h1>";
?>

<p>Wow, this is an example of personalized page.
You can see that no matter who request this page
THESE TEXT appear to everyone but logged in users
are shown more personalized page.</p>
</body>
</html>


Now, if you request the page without any data, it’d show “Welcome
Guest” and when you request it with your name it shows “Welcome
Richard” or whatever you provided as your name.


Example of creating personalized pages and sites in PHP


Great isn’t it! But wait, isn’t it cumbersome to write URLs that
way to request pages. Yeah because that’s not the way, it was just to
explain the working. As a matter of fact we’ve got the form (HTML) which
would do all the data sending stuff for us and that is the topic of our next
post.


[Update: Read the next part of this post Taking
User Inputs to Create Personalized Pages II
]


Related Articles:


Read More..

Tuesday, March 25, 2014

How to Hide Your Post Date Time and or Author

There are some reason for bloger to hide Post date, time and author. May be they want to see their blog looks clear or everything. Now I will show you the trick to "hide your post date, time and or author". the mothods is very simple, just find the code that I pointed to you and delete it. You can chose which part want to delete, date only, time only, author only or it all. Ok, if you decided to do it lets begin the hack.

1. Login to blogger the go to "Layout --> Edit HTML"
2. Click on the "Download Full Template" to back up your template first.
3. Check on the "Expand Widget Templates" check box.

Hide Post Date
find this code and delete it.
<data:post.dateHeader/>.

Hide Post Time
find this code and delete it.
 <span class=post-timestamp>
<b:if cond=data:top.showTimestamp>
<data:top.timestampLabel/>
<b:if cond=data:post.url>
<a class=timestamp-link expr:href=data:post.url rel=bookmark
title=permanent link><abbr class=published
expr:title=data:post.timestampISO8601><data:post.timestamp/></abbr></a>
</b:if>
</b:if>
</span>
.

Hide Post Author
find this code and delete it.
 <span class=post-author vcard>
<b:if cond=data:top.showAuthor>
<data:top.authorLabel/>
<span class=fn><data:post.author/></span>
</b:if>
</span>
.

5. Save your editting

Good Luck ............

Related Post :
Change Post Date Become Calender Icon


Read More..

Thursday, March 20, 2014

Our Plane and Boat Ride experience to Boracay during Monsoon Season

Our Boracay trip has been booked last year when Cebu Pacific offered their piso-fare deal. We werent very much aware of what our schedule will be but since the total amount that we paid for was only around Php 600 including also the surcharges, we decided to push through anyway. 

It was Sunday when Maring came and left by Tuesday but monsoon rains were still pouring come Thursday morning. Upon arriving at Terminal 3, the usual empty areas were packed with people. Some sleeping, some waiting for flights and a lot of people have been stranded the day before.

Since we had companions who had earlier flights that have been moved, we were aware that our 1205 flight to Caticlan might be moved to a later time. Because of this, we went to Mrs Fields and had a relaxing meal while we wait for further announcement on our flights status. The boarding areas were actually packed with people who should have left earlier. 

We were surprised to hear that our flight was prompt. We actually caught up with our companions who were supposed to leave 45 minutes earlier than us. We were happy though that there wouldnt be anymore waiting time when we reach Caticlan.

Because the plane was small (propeller type), we were aware that it may be a little bumpy. Our take-off was good but when we were going through the clouds, the turbulence was much worse than expected. It was a good thing that this was a short flight and there were no meals, otherwise, Im pretty sure that a lot of drinks would have been spilled because of the really turbulent ride. We thought that after that one set of turbulence, everything will be okay. But during landing, we didnt expect it to be just as bad! As much as I want to be as calm as I can, I could help but pray for our safe landing because for a moment, I thought we were about to crash. I couldnt define how awful it could be but my husband who was seated 2 rows behind me shared that Japanese people who were sitting next to him was showing each other their wet and sweaty hands because of the tension. After we landed, everyone just cheered and I thank God we were able to arrive safely to our destination. You might say that its a little discriminating because the weather that day was really bad but, our companions who landed about 5-10 minutes earlier (same airline company as us) didnt experience the rough turbulent ride that we did. Maybe because their pilot was more experienced than our pilot? Not too sure as well but it would really be better if they let more experienced people handle smaller planes so that people wont be scared to death on their plane ride.

and so, I searched for scary landings on Youtube...

Ours was not as scary but I got interested and watched several more "crosswind" landing videos -- http://www.youtube.com/watch?v=mMvLuUJFHYk
Going back, our package included transfers. We easily made our way to the ferry port via a private van from the airport. After reaching the port, we waited for 15 minutes until we were requested to board the vessel that will bring us to the island. After the tough plane ride that we had, we didnt realize that being at sea will be more challenging. Other than the boat not being as clean and tidy, the waves were stronger than usual. Good thing that it didnt take more than 15 minutes for us to reach the island because we didnt have sea-sickness medicines with us!

Seeing the island though, it was very much worth all the hassle that we had to go through. It was a one-of-a-kind experience that we will never forget! We were all very happy though that we were riding PAL on our way back to Manila - their pilots are really better!

LaNnA
PS. Liked the post? Subscribe to my blog by typing in your email below. Youll get my posts in your inbox via email.
Enter your email address:


Delivered by FeedBurner



-->
Read More..

Tuesday, March 18, 2014

Who Asked You to End Homelessness

So many people want to end homelessness. Here is just a short list of people and agencies desperately trying to put an end to homelessness in our towns and cities.



The Alliance to End Homelessness (Ottawa, Canada)

Arizona Coalition to End Homelessness

CT Coalition to End Homelessness

Denver Commission to End Homelessness

End Homelessness Now

Los Angeles Coalition to End Hunger & Homelessness

New Hampshire Coalition to End Homelessness

The National Alliance to End Homelessness

New Mexico Coalition to End Homelessness

People To End Homelessness

The Philadelphia Committee to End Homelessness



The National Coalition for the Homeless says "Our mission is to end homelessness."



The Urban Institute asks "What will it take to end homelessness?"



In June of 2004 the mayor of Washington, DC, announced a plan to end homelessness in the city within ten years.



Philip Magano, White House homelessness czar, says, "We can no longer tolerate the homelessness of so many of our neighbors. Our commitment is to fulfill the promise of a home for every American... That effort will begin with an initiative directed to remedy homelessness for those who are disabled living on the streets and in encampments across our country. We cannot acknowledge their plight, and then do nothing to remedy their situation."



Who do these people think they are? How arrogant is it to look at someone, judge his life against your own, and find his deficient? I never met a homeless person who said, I want you to end my homelessness. I met homeless people who asked for spare change, for food, for employment, for drug treatment, for medical help, for shelter for a night, for a ride to the next town, and for someone to talk to. All that yes, and I have always asked for respect and dignity. No one wants to give up the right to direct his own life.



Why do people think they know best how others should live, without ever asking those they say they want to help? It is because when people talk about a homelessness problem, they are talking about the problem that the rich have passing the poor every day. When Paul Magano says we cant tolerate homelessness, he means he cant tolerate the homeless.



Be certain when you offer to help, that you are offering to help someone other than yourself. To do that, the first thing you need to do is listen.



People will tell you if they want help, and what help they want. Dont impose your life on others. Youll only harm them. When people say they are going to end homelessness, I receive that as a threat.



The more we can kill this year, the less will have to be killed the next war, for the more I see of these Indians the more convinced I am that they all have to be killed or be maintained as a species of paupers. Their attempts at civilization are simply ridiculous.

General Sherman, 1868



Why not annihilation? Their glory has fled, their spirit broken, their manhood effaced; better that they die than live the miserable wretches that they are. History would forget these latter despicable beings, and speak, in later ages of the glory of these grand Kings of forest and plain…

L. Frank Baum, author of The Wizard of Oz, advocating genocide, 1890
Read More..

Sunday, March 16, 2014

How to Make Soft Tacos Easy Frugal Recipe

Tacos have changed considerably since I first wrote about them. Between home-made salsa, taco seasoning, and homegrown lettuce, I think the only thing that has stayed the same is beef and tortillas. First, make tortillas, mixing:

2 cups whole white wheat flour ($0.32)
3/4 teaspoons salt ($0.03, if that)
1/4 cup shortening ($0.25, softened butter, but you can use whatever)
1/2 cups water ($0)

For a soaked grain tortilla, add 1 tablespoons of whey, yogurt or cider vinegar, mix dough the day before and leave at room temperature until you are ready to cook it.

I divide it by ten, as that is just right for my family, with enough for leftovers for my husband. My kids have disassembled tacos. They like the tortillas with the salsa on them, but everything else they eat separately. So, each ball of dough I roll out flat. The aim is a circle, but it doesnt have to be perfect.


Fry in a dry pan for roughly thirty seconds on each side.


Brown one pound of ground beef ($1.30) with

1 large chopped onion - $0.15
1/2 jalapeno, finely chopped - $0.06
1 teaspoon of garlic -$0.04
1/2 teaspoon cayenne pepper or hot paprika -$0.03

Divide the seasoned beef (or chicken or shredded pork or turkey) onto each tortilla. Sprinkle with 2/3 of an ounce of cheese on each ($0.79), then lettuce, preferably from a window garden ($0.08).

Lacto-fermenting a condiment like salsa is a means of preserving it as well as turning the food into a probiotic. I lacto-ferment my salsa, but if youre not interested in lacto-fermenting, the same recipe can be used to make regular salsa. Just immediately refrigerate instead of letting it ferment on the counter. I put one heaping tablespoon of salsa onto each taco ($0.30), then fold it over.


I didnt know until I finished this post that this recipe is the exact same price as my old taco recipe, but I like these better. They are more from scratch, homegrown, with no mystery ingredients, and they taste amazing.

Read More..

Tuesday, March 4, 2014

Letter to Cool Publisher

To: [Cool Book Publishing Firm]



Dear [Cool Book Editor],



I am in the midst of writing a book which teaches how to live well while homeless. A review of your online catalogue reveals several similar books, including [Nuther Homelessness Book], which gives information on being homeless in a traditional way, the life, to use a crude term, of a bum. My book will offer readers an alternative to this stereotypical lifestyle, and will make a nice companion to that work in the catalogue or on the shelf. I propose a lifestyle which has all the advantages and freedoms that attend a rent free life, without the social stigma. My guide will teach methods of being homeless undetectably, invisibly. A person living as I recommend will be welcome in restaurants, malls, schools and at social events. When he walks onto a car dealership, a salesman will try to sell him a car. He will be employable. He will have options to change or maintain his lifestyle.



I spent nearly five years, from mid-1996 to the beginning of 2001, homeless, or as I liked to call it with a distributed household. I had storage, shelter, mailbox, telephone, shower, bathroom facilities, cooking equipment, and transportation, even access to television, radio, computer equipment, and ac power. I had the essence of a home. It was simply more geographically scattered than is traditional in our culture. My techniques could be adapted to anyones tastes and talents, and to the resources available anywhere.



I have enclosed a topic outline of the proposed book, several sample sections, and a self addressed stamped envelope for your convenience. There is no need to return any of the submitted materials. Thank you for considering my Survival Guide to Homelessness.



Sincerely,



Mobile Homemaker



Sent: 5 November 2004

Names omitted to protect the guilty.



Read More..