Jump to content
Birdhouse919

Guide on C++ (Borland)

Recommended Posts

Hello Everyone,

This will be an on-going tutorial on Borland C++ and I plan to answer all questions you may have regarding the subject.

The following will provide you with basic knowledge of the c++ language and will hopefully guide you to further your knowledge in the future.


[B][CENTER]Starting Components/Vocabulary:[/CENTER][/B]

[CODE]
\n = <paragraph> ( Next Line for output)

clrscr(); = Clears the screen of all previous data shown.

getch(); = pauses programs to allow for users to see the given prompt.

cout = Sends a message to the console.

main() = Marker of the "Main" program. - no task to complete.

Braces * {} * - Starting and ending of code projects.

#include = Import methods

iosteam.h = Prototype Example

// = Comment Lines

/* */ = Comment Lines
[/CODE]

[B]The main() is the literately the main component of the program (Similar to Server.Java or Client.java in RSPS terms).[/B]

[CODE]main()
{
Executable Code;
return 0;
}[/CODE]

The int value that main returns is usually the value that will be passed back to the operating system. 0 traditionally indicates that the program was successful.


[CENTER][B]Identifiers and outputs[/B][/CENTER]

[B]Identifiers & variables hold values in the computer's RAM while the program is still running.[/B]

[CODE]char - Characters

int- integers from -32,768 - 32,767

float- Decimals -3.4x10^-38 - 3.4x10^38[/CODE]

[CENTER][B]Expansions:[/B][/CENTER]

[CODE]long-integers from -2,147,438,648 - 2,147,438,647

Double- Decimal -1.7x10^308 - 1.7x10^308

long double- -3.4x10^4932 - 3.4x10^4932[/CODE]



[CENTER][B]Declaring Variables:[/B][/CENTER]

[LIST=1]
[*]Any variable used has to start with a letter or underscore.
[*]After the first character, you can use any key on Keyboard, besides the Dash key.
[*]Use a name that describes the use of variables (IMPORTANT).
[*]No Spaces (Separate two words using an underscore).
[*]Use no C++ reserved words as variable names. (Way around this is Capitalize the variables first letter)
[/LIST]


[B][CENTER]Legal Variables:[/CENTER][/B]

Example:

[CODE]int Average;
float Mess;[/CODE]

[B][CENTER]Illegal Variables:[/CENTER][/B]

Example:

[CODE]char Last Name; (Has a space)
int int; (Uses a C++ Reserved word)[/CODE]



[CENTER][B]Proper Code Format:[/B][/CENTER]

[CODE]#include <anyprototype.h>

main()
{

variable declarations;

code(Will use declared variables in);

return 0;
}[/CODE]

[B][CENTER]Command code:[/CENTER][/B]

[CODE]cin is an input command (cin retrieves data entries typed by the user).
cin>>Num1;[/CODE]


[B]Sample Code:[/B]
(Code for getting the user to input 2 num then find the average).

[CODE]#include<anyprototype.h>

main()
{

float Num1, Num2, Avg;

cout<<"Please enter first number";
cin>>Num1;

cout<<"Please enter the second number";
cin>>Num2;

Avg=(Num1+Num2)/2.; //(Make sure the decimal is there!!)

cout<<"The average of"<<Num1<<" and "<<Num2;
cout<<" is "<<Avg;

getch();
return 0;
}[/CODE] Edited by Birdhouse919

Share this post


Link to post
Share on other sites
You're leaving out important information. For example, if you tell people that 'cout' is sending a message to the console, they don't know actually how to use it.

For example, they wouldn't know how to do this because you've only supplied them with the keyword.
[code]
cout << "Hello World" << endl;
[/code]

Additionally, the main() method has a return type of int.

getch() shouldn't be used if you're working with multiple people or distributing your work. It's non-standard C, so some compilers don't have it.

Edit: I see you added some stuff. You should really finish the thread before posting it. Edited by Hope

Share this post


Link to post
Share on other sites
[quote name='Hope']Edit: I see you added some stuff. You should really finish the thread before posting it.[/QUOTE]

I keep getting a weird error message when trying to preview my post that completely messes up the screen.
I will write out the rest in a WORD file and then just input all the data at one time. :p

This is a tutorial for Borland, which is different from standard C. Edited by Birdhouse919

Share this post


Link to post
Share on other sites
[quote name='Birdhouse919']I keep getting a weird error message when trying to preview my post that completely messes up the screen.
I will write out the rest in a WORD file and then just input all the data at one time. :p

This is a tutorial for Borland, which is different from standard C.[/QUOTE]

Please ignore the error message, i have already reported it a few days ago. Its due to the new forums code. It still works fine.

Share this post


Link to post
Share on other sites
[quote name='kibitz']Please ignore the error message, i have already reported it a few days ago. Its due to the new forums code. It still works fine.[/QUOTE]

I know what it's from, but on my computer, it messes up the entire screen and I can't read anything on the web-page when it happens.
Works on my tablet, but not on my desktop.

Share this post


Link to post
Share on other sites
[quote name='Birdhouse919']I keep getting a weird error message when trying to preview my post that completely messes up the screen.
I will write out the rest in a WORD file and then just input all the data at one time. :p

This is a tutorial for Borland, which is different from standard C.[/QUOTE]

C != C++. In fact C isn't event a subset of C++ (you can't throw C code at a c++ compiler necessarily; there are language differences)

Also, pl ease don't spread false knowledge. You're better off not spreading any at that point. A number of the things you've stated are either clear misunderstandings or falsities. I can understand "dumbing down" a bit to appeal to an audience lacking enough background, but ensure that you aren't being incorrect while doing so. You could also precurse with "Can be thought of as ..." or "used here to ..." versus just stating that something is something that it isn't.

For example, what you are calling a prototype is just a header file. A [B]function prototype[/B] is when you [B]declare [/B]a function before you [B]define[/B] its body. A prototype can be used to specify the number of and types of arguments for a function so that the compiler can throw errors when it sees the function being called otherwise. They can also be useful in a header file in order to kind of declare functions for use where the header is included regardless of how those functions are actually implemented.

Also, in C/C++ only alphanumeric characters and the underscore are valid for use in an identifier, where a number can't begin it.

It's probably worth mentioning the preprocessor, and how #include is a preprocessor command that literally copies the contents of the included file wherever the include statement is (which is header files should really only contain declarations for things: structs, prototpyes, typedefs etc.). This is also why it's important to include a newline at the end of the header, or the pasting of the included files contents could cause a syntax error if not ending in a newline.

Another thing worth mentioning is that you don't have to (and really shouldn't) throw all of your variables at the beginning of a function. You should declare them in the lowest scope they can possibly exist in, as this allows for better optimization when the compiler knows that a variable is used only in a specific scope versus being needed for the entire function. You probably should declare variables at the beginning of their block, as this is required by < C99, but this doesn't mean the beginning of the function. You can even use braces to force scope, like in C89 where you had to declare your looping variable outside of the loop construct itself:

[code]
int i = 0;
for(i = 0; i < someshit; i++)
;

//more code
[/code]

You can force the scope of i to be with the loop by throwing extra braces around it giving it it's own block. with the loop:

[code]
{
int i = 0;
for(i = 0; i < someshit; i++)
;
}
//more code
[/code]

That's about as much as I feel like typing.

Anyway, I hope you continue to play with C++ and continue to research and learn, but I hope even more that you realize how turd-like c++ is and instead choose to write more code in c. Good luck to you sir! Edited by Trey

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×