Looking to learn Visual Basic Express??

I’m wondering how many people had problems with following the basics of programming when I was explaining C++? Well I figure its probably easier to get the concepts if I teach Visual Basic and you all get to learn how to program under windoze. Anyway leave a comment anyone who wants to learn visual basic I’ll check back soon and see where everyone is on this but I’ll probably end up just teaching it a little more than i did the C++ anyway.

CipherSpace!

It has come to my attention that people of power are looking to control and implement laws in cyberspace. The “net” is originally suppose to be free for the exchange of ideas. Who has the right to set laws in a place that is publicly used by every and anyone. I want to encourage a “subnet” so to speak where everyone will participate in the use of and creation the the chiperspace. http://en.wikipedia.org/wiki/Cipherspace will give a basic explanation of what this is. Use of Tor proxies and other proxies, VPNs, SSH, etc. to keep all activities anonymous and help to create anonymous websites. I also think we need a special “.cyp” extension for cipherspace websites.

I hope anyone who reads this will join this attempt to get people interested in this and that the creation of a cipherspace will come into a reality. We should be able to exchange anything online. Things like ideas, videos, movies, music, ebooks, games, programs, and anything else you can find. Anything placed withing the cipherspace should always be free for any kind of use. Anyone interested please leave a comment to this post and leave your ideas and what you think.

Published in: on April 5, 2010 at 12:41 am  Comments (2)  

C++…Control Structures (Loops)

Lets get into loops today. What a loop does is run the same set of code until the condition is false or meets a condition you choose. So first is the while loop its format is while (expression) statement. Here’s an example:

#include<iostream>
using namespace std;

int main()
{

int x;

cout<<"Enter a number: ";

cin>>x;

while(x>0)
{
cout<<x;
--x;
}
return 0;
}

So when you were to run this program and enter the number 10 it would print out:
10
9
8
7
6
5
4
3
2
1

and stop because x is greater than 0 so it wont print 0 or any negative numbers. As you should know the — means subtract 1 from x and if you were to put ++ that would be to add one. This should be pretty simple to understand.

Now we move into the do-while loop. The format for this one is do statement while (condition). This is simple to grasp if you understood the while loop. Do while is used when you need to determine the end of a loop from within the loop itself. For example lets say your working on a program that makes a database of employees in your company. You want to enter they’re name, age, and weekly pay. You would have your program ask these three questions for each employee once your done you can have your program end when you type something like done in the name section. Here’s a do-while loop example program:

#include
using namespace std;

int main()
{

string name;
do {
cout << "Name: ";
cin >> name;
}
while (name != done);
return0;
}

This was a simple example of a do-while loop. When we get into outputting to files we’ll come back to this example. But for now you can see how you can use a do-while loop. This example asks for a name and will keep asking until you enter “done”.

The last loop we’ll go over today is the for loop. for (initialization; condition; increase) statement; . Lets get right into an example, it should explain itself.

#include
using namespace std;

int main()
{
for (x=100; x != 0; x--){
cout<< x <<endl;
}
cout<<"Done!";
system("pause");
return0;
}

The out put would be:

100
99
98
97
96
95
94...

It will continue to 1 and wont print 0 but once it gets to 0 instead it will print Done!. So as you can see a for loop starting from the initialization will continue to do what your increase(or decrease) until the condition is met. So these are three of the Control Structures you need to know. In future examples we’ll begin to use them more.

C++….Constants

This week I’m going to show you how to do constants. This is a very simple subject to learn and its basically the same as variables but as the name suggests they stay constant. The difference from a variable is that constants save on memory usage where as variables can use up a lot. So lets jump right into things. You all should know if you’ve been keeping up with my lessons how to declare a variable. But what happens when you use something a lot more often and you want to use it in different functions and such. By the way the next lesson is on functions you don’t need to know it right now. So to declare a constant its as simple as this : #define thisnum 1337

That seems simple right? This type of constant is a define constant. It is written with the # symbol because it is read by the preprocessor just like the #include code. Lets use this in a simple program:

#include<iostream>
using namespace std;


#define acid "This is a string from my define constant!"

int main{
cout << acid;
system(pause);
return 0;
}

In this example the word acid is declared in define as “This is a string from my define constant!”. So no matter where you use it in the program acid will always print the string and you won’t have to declare it in different sections. Remember that #define is not a variable but a preprocessor directive. And since it is constant it cannot be changed like a variable. Now with that in mind you can declare constants like variables with declared constants. To use a declared constant you use it in the same way as you would a variable. const int math = 4+4; so lets do an example program:


#include<iostream>
using namespace std;

int main{
const int a = 5;
const int b = 6;
int c;

c = a + b;
cout << a;
cout << b;
cout<<

system(pause);
return 0;
}

So there you go it shouldn’t be too hard to follow now you can use define and declared constants in your programs. Next lesson will be using some loops. As usual any comments or anything can be left in the comments section for this post.

C++ switches….

Alright today I’ll be explaining switches in C++. But first let me tell you what a switch is. Basically what it does is makes making decisions easier than using if statements. You can even use it to make menus. So here’s an example of a switch statement… ex:

switch(x)
{
case 1:
//code here
break;

case 2:
// some other code here
break;

case 3:
//even more code
break;

default:
//code here

}

This is a simple switch statement. You start with declaring switch and in the ( ) is the variable you want to test. The variable goes from the switch statement and checks it in the case statements to see if there’s a match. So if X is 1 then it runs the code that’s in that section. “break” tells the computer to leave switch and continue running the rest of the program. Without it then it will start to run whats in case 2. It will do this until it either reaches the end or finds a break statement. Now lets put this into practice with an example…..


#include<iostream>
using namespace std;

int main()

{

int pets;

cout<<"how many pets do you have?"<<endl;
cin>>pets;

switch (pets)
{
case 1: cout>>"take care of it?">>endl;
break;

case 2:
cout>>"wow if they're small ok but if you have two big dogs WOW!">>endl;

break;

case 3:
cout>>"ok that's pushing it a little.">>endl;
break;


defaut:

cout>>”any pets at all????”<<endl;

}
system(pause);

return 0;

}

By now you should be able to tell that if the user types they have 1 pet it will run case 1 and so on. This make choices more organized and understandable than using if statements. Also saves a lot of typing. So practice that maybe take one of the “break” statements out to see what happens and come back soon for the next lesson. ;-)

if/else if/else….

So this post I’m going to teach you about if, else if and else control structures. What the if statements do is give the person or yourself using the program some kind of choice. So lets say you ask a question if the person answers yes or no they will get a response that goes with their answer.

ex:

#include
using namespace std;
int main{


string gender;
cout<<"Are you a boy or a girl? "<>gender;

if (gender == boy){
cout<<"I heard you ate worms in school!";
}
else if (gender == girl){
cout<<"your learning to program??? that's so cool!";
}
else {
cout<<"Whats wrong don't know your gender?";
}
system(pause);
return0;
}

So you can see that when the person say’s they are a boy it goes to the if statement and runs the code there. If they say they are a girl it goes to the else if statement and runs that code but if they put anything else as an answer like “onion” it will run the else statement. Else is basically the part of your code that runs when no other answer was given. So that’s the basics of if control structures. Need any help just leave a comment.

C++ Variables 2……

Sorry this post has taken so long I have been swamped with so many things for the past month. Anyway this is the C++ tutorial on using variables part 2. Its probably taken me forever to get out and by now u have all my other posts memorize. I explained variables in my last post about them being like containers of what you want. Now I’m going to show you how to use variables to hold strings. In case you don’t know a String is a bunch of letters or a sentence anything like this “Welcome to Warfusion’s page” everything in the quotations is considered a string. Here is an example:


#include
using namespace std;
int main()
{
var1="I am the best programmer ever!"


cout << var1;


return0;
}

Here in this example “var1″ contains the string “I am the best programmer ever!” When you cout to the screen the variable var1 it prints out what it contains which is the string. Practice this and I’ll get a post out soon. Hope this was short but sweet!

Published in: on November 17, 2009 at 11:09 pm  Leave a Comment  
Tags: , , , , , , , ,

Learn C++…”Variables”

So lets create a new.cpp file and call it var.cpp. Today’s lesson is about variables. A variable is simply a container that holds something like a number, string, etc. A variable can be called anything except asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, operator, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_cast, struct, switch, template, this, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while. So lets begin with a simple addition example:
#include <iostream>
using namespace std;


int main()
{
int a,b;
a=5
b=9
cout<< a+b;
system("pause");
return 0;
}

After you compile this code you should getthe number 14 in your command prompt. “a=5″ means a contains the number 5 so if you had typed cout<<a; it would print the number 5. The same is for b it contains the number 9. So when we put a + b it was the same as asking 5 + 9. Simple? Incase you dont understand think of a variable as a box which holds what you tell it. So we told a to hold 5. Now when we use the a box it contains 5. That should be pretty simple. Lets move on to showing how to use strings (lines of letters and words) with variables…

#include <iostream>
using namespace std;


int main()
{
string war;
int x;
war="I like to use variables!!!"
x=2009
cout<< war << "It all started in" <<
system("pause");
return 0;
}

In this example we use the word “war” as the variable with holds the string “I like to use variables!!!” an x hold the number 2009. So all you need to really know about variables is that they contain what you what. Next lesson will be a little more on variables and how to change them to a new value.

Learn C++…”Hello World”

This week will be the first post of my C++ tutorial. As with almost all programming languages we’ll start with the legendary “Hello World” program. But first your going to need a compiler. The best free one for C++ is Dev++ (bloodshed). Just do a google search for it and you should find it. If not leave a comment here and I’ll post a link for the portable one you can keep on a thumb drive. So lets begin. Here is the code for your first program….
#include <iostream>
using namespace std;

int main()
{
//our first program!
cout << "Hello World";
system("PAUSE");
return 0;
}

So lets go line by line now. The #include tells the preprocessor to include this file in out case <iostream> which is the input/output file that tells the computer to show what we want to the screen or to take some kind of input. Next is using namespace std;. This will be included in almost all your c++ programs. This tells the computer to use the namespace for “std”. Its easier than using std:: before amost all your lines. The following line int main();. Basically all programs must have a “main” function!

The { } is where you put your code for a function. Now cout << is the standard output we use it tells the computer to print this to the screen. When typing strings we put them in quotations. As you may have noticed all c++ lines of code ends with a semicolon “;”. I haven’t told you about the //our first program! this is a one line comment, all single line comments must start with “//”.

system("PAUSE") simply just pauses the end of your program…prints out (Press any key to close…) once you press a key it closes the window. return 0; tells the computer that if all goes well then close without any problems.

Those are the basic’s of your first C++ program. Next post we’ll go over variables, what they are, and how to use them. If you need anything clarified please feel free to leave a comment.

Next few weeks…..

Over the next few week’s I want to teach the basics of C++. If it goes well and people like what they see then I will go into the more advanced stuff. I personally love C++ and want to try and explain in an easy way the parts of it and to get you on your way learning OOP (Object Oriented programming). So look forward to for those posts.

Follow

Get every new post delivered to your Inbox.