Search Tools Links Login

LAST CHANCE: Move toward a higher language with C++. Great tutorial on:Outoput in C++,variable,etc


Visual Basic 6, or VB Classic

I have updated the last submission on C++. I hope that this will encourage VB programmers to speread there knowledge, and learn new languages, as well as keep there current ones. This is the last time i will post a C++ tutorial on VB world, so if you think my tutorial helps either tell me in the feedback, or IM me through aim(BlazinIndustryz2) or MSNIM(habitat1422@hotmail.com). If i get good feedback i will try to help out more, so look for my next submissions in C/C++ world. Thank you.

Original Author: Kurt Serge

Code

//I hope you all get something out of this, and if you do, email me so i know
//how im doing. Or you can use my aim(BlazinIndustryz2)or msnIM(habitat1422@hotmail.com)
//if you have questions just ask me :-)
//first of all, you need a compiler(you can learn C++ without a compiler,
//but it might be easier with it)
//http://www.bloodshed.net/dev/devcpp.html
//I would prefer DevC++ version 4, but its clearly up to you.
//WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!: C++ IS CASE SENSATIVE, ALL CODE IS
//USUALLY LOWER_CASE
//Heres the code, i will explain everyline, at every symbol.

//first of all the "//" is one way to comment in C++, unlike vb's '
//You can also use another comment when you want to comment out large
//groups of commenting, without drawing the slashes on every line. Look:
/*
The top one signals the commenting to start, and when you reach the last
one the commenting is over.
you can
add more lines
and wont have to make the "//" on every line
*/


#include
//ok , in C++ you have to tell the compiler what you need to put in your
//program the "#" says that your going to do something in the preprocessor
//(#include is part of the "preprocessor"). Now include means your
//going to use iostream.h(pronounced  i - o - stream - dot - h) in your program.
//keep reading and you will understand it more a little later.

//int main()
//int is an integer. Simple enough. main is your program, and the () are there
//because main is a function, and all functions have a () for parimeters. main has NO
//parimeters right now. if you dont understand that, than just forget about it for now,
//it will come with practice.

//{
//}
//These are typed at the beginning of the code, and at the end. It helps to sort of quarantine
//code inside the brackets, and is a seperator.
/*
example:
in VB you would have this
Private Sub Command1_Click()
code in here
End Sub
You can compare the "{}" in C++ to this VB code. Private Sub Command1_Click() will begin the
code, but when the End Sub is reached, the compiler knows that the code for the command1_click()
is over. You should try to understand this before getting into more complicated things, because
you need the "{}" alot in more complex programs.
*/

//now your code will look like this
// #include
//
// int main()
// {
//
// }

//Now in between the 2 "{}" you will need a body of code. This is where comes in.
//By writing , you have stated that your project will contain code from
//This is one new coding word you can use after putting in iostream.h
//cout(not pronounced "cowt", pronounced see-out")
//you would code cout like this:
//cout << "THIS IS HOW YOU USE COUT";
//The "<<" is the INSERTION OPERATOR. it is used to show that cout has been used, and the next
//line of code will have what you want cout to do.
//HERES WHAT COUT DOES
//cout will display on screen "THIS IS HOW YOU USE COUT". It will display what you type(in quotes)
//after the "<<". This is used as an OUTPUT STREAM, but dont worry about what OUTPUT STREAM means
//right now, just make sure you know what cout is used for.
//ok now the code looks like this:
#include
int main()
{
cout << "THIS IS HOW YOU USE COUT";
return 0; //Return 0; ends your program, 0 is False, so it returns false, therefore ending the program.
}
//******************************************************************
//STOP:ONE PROBLEM
//Did you notice that your app will open, print the statement, then close right after? Read
//Section 2(Learn C++ Variables, and a new function) to learn how to easily fix the problem.
//*****************************************************************
//some things you may notice are:
//you can place whitespaces(spaces and enters)between your code, and c++ will still compile it
//you could write cout like this
//cout
//<< "THIS IS HOW YOU USE COUT"
//;
//Although this is possible, it is not recomended.
//You also may notice the semicolon";" that comes after the code. Almost all the code that
//is inside the body"{}" will have a semicolon after it. There are exceptions, but youll get used
//to them over time. But thats now to worry right now, the goal was to learn C++, and if you read
//down to here, then youve wrote your first program! You can test it on your compiler. If you
//don't have one, you should get one from the site at the top of the screen. I have left a .cpp
SECTION 1:STARTING OFF
//file in the folder. A .cpp is the extension for a C++ file, just like this file is a .txt.
//open the .cpp with your compiler to see if it works, and if it dosn't something is wrong with
//your compiler.

//This is the largest beginners C++ tutorial ive seen, please show me some feedback. I want to
//know if ive taught a few people C++

SECTION 2:VARIABLES, AND MORE
/*If you havn't read section 1, DO NOT PERSIST. Go back and read section 1. If you
dont understand section 1, then also go back, and look it over. YOU NEED TO KNOW WHAT
IS REVEIWED IN SECTION 1!!!

Ok, now you learn variables. Variables are words that can stand for something else. If
you have done algebra, you know what variables are. Same concept applys here.
example: x + 5    the variable is x. It can be changed to produce different values
if x is equal to 10, then x + 5 = 15. But remember not all variables are numbers, but for now
we will use ONLY numbers.
Now i will list the variables you will learn. Look them over carefully.


VARIABLE DEFINITION
int           int stands for integer. An integer is a whole number.
example: 1 is an integer, 245 is an integer, 2.3 is NOT an integer
float A float is another name for a DECIMAL. 2.3 is a FLOAT, 45.43 is a FLOAT.
long Long is another type of int. Its larger than an integer, therefore
if you worked with big numbers you would us a long.
double Larger than an int, or a long.
signed signed means that the number can be negative(-)
it would code like this: signed int;
unsigned The opposite of signed. It is a positive number.
char A tricky little variable, that stands for character. Its kind of
complicated to learn about it right now. Just understand that it holds
letters.

Ok you got that? Good, now that you know what each one means your going to need to put it in
the code. Heres how you would declare an integer(int), with the name integerone.
int integerone;
the integerone is your variable. Its type is int(integer). So how do you know what integerone
is equal to? Right now its not equal to much, but we can change that. When you declare it,
you can make it equal to an integer. Pick any number. We'll use 5.
int integerone = 5;
Now integerone is equal to 5. Remember cout? well were going to use it to show our integer.
*/

#include //include the iostream to use cout.
int main()
{
int integerone = 7; //your integerone variable is 7
cout << integerone;
return 0;
}
//Ok, normally you put quotes around what you want to display. Not here. If you put quotes on it
//it displays the text:  integerone on your screen. If its not in quotes, cout puts the variable
//on the screen. If you run this, it will say this on the screen: 7


/*Get it? I hope you do. Now youll notice once again, that you wont even see the input, the
screen flashes and you can't see what cout put on the screen. Your going to need some way
to keep the window open....hmmm... I KNOW!
GETCH();
The getch function will keep the information on the screen, untill you press a key. But, just
like cout, it needs an include.
#include

you would write it just before return 0; , so that it would wait until you pressed a key, then
carry out the rest of the code, which is return 0;. The program ends.
EXAMPLE OF GETCH();
#include
#include
int main()
{
cout << "THIS IS TEXT. " << "MORE TEXT.";
getch();
  
return 0;
}
This program contains TWO important, and new things.
1:getch() is used, after the output goes onto the screen, getch() makes it display onscreen,
untill you press a key.
2:I used the "<<" operator twice. You can use them one after another.

Heres another thing:
cout << "TEXT" << endl;
cout << "MORE TEXT;
Youll notice the endl. You've never seen it, and what it does is simpley add a line(endl = "end line)"
the output would be...
TEXT
MORE TEXT
with out endl it would be

TEXTMORE TEXT
see the difference?
Back to variables:
you want to add 2 variables, and then get an answer. heres how:

#include
#include
int main()
{
int varone = 5;
int vartwo = 15;
int varthree; //nothing in the variable, no value yet
varthree = varone + vartwo //add the two variables, and assign the answer to varthree
             //now varthree = 20
cout << varthree;
getch();
return 0;
}
Your output is: 20 because varthree is equal to 20 after you add them
together.
THats it for section 2, ill show more in the next section
NOTE: only one of these programs will compile, because the rest are commented
out. You need to uncomment them to work.
*/

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 92 times

Categories

Visual Basic 6

Attachments

LAST_CHANC872015262002.zip
Posted: 9/3/2020 3:45:00 PM
Size: 10,622 bytes


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.