Jump to content

Introduction to C++ "Hallow World"


cis_academy

Recommended Posts

First C++ program:

 

//include this file for basic input output

#include // or // .h means header file

 

int main()

{

 

//display output string, "Hello, World!"

cout << "Hello, World!" ;

cout << endl;

 

// return 0 to operating system

return 0;

 

}

 

The purpose of this topic is to give a good understanding of the programming language

C++ to any individual that needs it.

 

C++? Why are so many programs written in C++?

C++ is a third generation programming language. When computers were first invented, they were programmed with very simple, low-level commands. A programmer would design a program, then translate the program into a specific set of codes, known as machine language. These codes would be fed into a computer with switches, punch-cards, or primitive keypads. These programs were cumbersome to write, and very hard to debug. (Debugging is the act of removing mistakes in a program.) Machine code is considered the first generation of programming languages.

Assembly languages are considered the second generation of programming languages. Assembly languages allow a programmer to design a program and translate it into machine language using a piece of software called an assembler. Most assembly languages are still very cumbersome to work with. However, the biggest disadvantage of assembly languages is that they are processor-specific. This means that programs written in assembly language will only work on processors similar to the one of the machine that they were written on.

Third generation languages are compiled languages. These languages are not processor-specific. In theory, a program written in a third generation language will be able to run on any other machine. This is not always the case, due to a number of factors. Third generation languages are much more abstract than assembly languages. Third generation languages are translated into assembly language by a complicated piece of software called a compiler A compiler can be thought of a language translator.

 

Third generation language – compiler - assembly code – assembler - machine code

 

C++ is a very constructive language, because it gives the programmer a lot of control, it is also is abstract enough so development can be done quite quickly. C++ is a very portable language as well, because it is a third-generation language, and because it has a well defined set of standards written for.

C++ is widely used for program development under a variety of operating systems.

 

Welcome post your Questions on this topic:

 

Next Topic: Compiling and Running.

Link to comment
Share on other sites

Harut jan,

Can you take the program that Karapetyan listed above and print out "Azat is the man" 10 times?

 

 

Oh by the way harut, for our third example we are going to improve the Windows XP kernal. Hope you do a good job on this one and learn from it.

 

[ February 22, 2002: Message edited by: Azat ]

Link to comment
Share on other sites

Welcome to the board Karapetyan! Nice thread you started

 

quote:
Originally posted by Azat:

Oh by the way harut, for our third example we are going to improve the Windows XP kernal. Hope you do a good job on this one and learn from it.


Does anyone have any idea how many lines of code the XP kernel has? Last I read was about NT 4.0 which had about 40 millions lines of code (everything combined) but I haven't seen any data about the kernel. They are also saying that the code base doubles every year so now they should be past the 100 million lines of code mark

Link to comment
Share on other sites

  • 3 weeks later...

quote:
Originally posted by Azat:

Harut jan,

Can you take the program that Karapetyan listed above and print out "Azat is the man" 10 times?

 

Oh by the way harut, for our third example we are going to improve the Windows XP kernal. Hope you do a good job on this one and learn from it. smilies/smile.gif


How come I can't post? kepeeps saying, sorry, we do not permit this html tag.
Link to comment
Share on other sites

quote:
Originally posted by Azat:

Harut jan,

Can you take the program that Karapetyan listed above and print out "Azat is the man" 10 times?

 

Oh by the way harut, for our third example we are going to improve the Windows XP kernal. Hope you do a good job on this one and learn from it. smilies/smile.gif


The code:

 

#include

 

//NOTE: In brackets, the library. It is essential for the program to work or the computer will not know where to exectute the commands from.

 

int main()

 

//NOTE: Remember: no semi colon after brackets. Int main is the only exeption to the semi-colon rule. It is very essential for each program to have int main on the front other wise it won't work.

 

{

cout<<"Azat is the man"<

cout<<"Azat is the man"<

cout<<"Azat is the man"<

cout<<"Azat is the man"<

cout<<"Azat is the man"<

cout<<"Azat is the man"<

cout<<"Azat is the man"<

cout<<"Azat is the man"<

cout<<"Azat is the man"<

cout<<"Azat is the man"<

 

return 0;

 

}

 

//NOTE: there MUST ALWAYS be brackets at the beginning and end of each program, to mark the beginning and end.

 

To Harut and Azat, I know this way does work, but it's still not right because a loop should be used to output "Azat is the man" 10 times. The endl on the end is right but it is just another way of ending the line. It is just very basic coding. I will dig out my C++ notes from last year and find the method of the loop! I need them anyway, so it's a good thing the post reminded me.

 

[ March 12, 2002, 07:05 AM: Message edited by: Kazza ]

Link to comment
Share on other sites

quote:
Originally posted by Sip:

Does anyone have any idea how many lines of code the XP kernel has? Last I read was about NT 4.0 which had about 40 millions lines of code (everything combined) but I haven't seen any data about the kernel. They are also saying that the code base doubles every year so now they should be past the 100 million lines of code mark smilies/eek.gif smilies/eek.gif smilies/eek.gif


Last I heard it is less than 50 millions line of code of which over 30 are error handling code.
Link to comment
Share on other sites

Kazza jan, even it is very simple (what you've posted) i don't understand a bit of it.

 

i just started studying C++

 

in fact, today is my first day of college after a break. in about 20 mins i will attand my first C++ class for the first time.

 

wish me a luck.

Link to comment
Share on other sites

quote:
Originally posted by Harut:

Kazza jan, even it is very simple (what you've posted) i don't understand a bit of it.

 

i just started studying C++

 

in fact, today is my first day of college after a break. in about 20 mins i will attand my first C++ class for the first time.

 

wish me a luck.


You have probably had it by now, but a balated good luck, lol! I'll help teach you later if you want and explain it more..
Link to comment
Share on other sites

  • 10 months later...

quote:
Originally posted by Sip:

Sorry, I'm a bit drunk right now, but I see a syntax error with a { symbol. It may very well turn out that I'm not seeing straight right now but just in case


OH MY GOD. What is this Sip "I'm a bit drunk right now"? You started to drink?
Link to comment
Share on other sites

Oh yah, Hyestyle, WELCOME ABOARD! Sorry I forgot my manners

 

quote:
Originally posted by Azat:

quote:
Originally posted by Sip:

Sorry, I'm a bit drunk right now, but I see a syntax error with a { symbol. It may very well turn out that I'm not seeing straight right now but just in case


OH MY GOD. What is this Sip "I'm a bit drunk right now"? You started to drink?
Azat jan, after a NICE (productive ) few hours at the craps table, it was time to live it up a little. Man I love craps. If you play conservatively and know when to quit, you can often recover the cost of your trip just from that!!! Mathematically, it makes absolutely no sense, but it's been happening to me the last few times I've been to Vegas and I hope it continues for a long time to come. I don't go to win big ... just enough to cover costs of going there.

 

I was also VERY disappointed on the Eagles. Man, only if the Eagles had beaten the Tampa Bay Buc's, I would have made a KILLING on my bets. But worst of all was that the stupid guy put the wrong bet for my buddy... and he didn't realize it until it was too late (forgot to check the actual ticket when he made the bet). So all the time he ended up having to cheer for the Titans, even though both of us knew very well Raiders were easily going to cover the spread and the totals But that's ok ... I don't like sports betting too much anyway! Craps is my game now

Link to comment
Share on other sites

Originally posted by Hyestyle:

Thanks Seaphan.  De mi erku ban xosatsek tanem inch gitenk computerits lol  

erku ban? erku ban? Ok, esa:

 

1) 0

2) 1

 

:)

 

Hyestyle, here's a cool puzzle for you, now that you like C so much. I posted this before. This, and the solution to it, and some other puzzles can be found in THIS THREAD. But try to figure it out on your own first before going to that thread. I really think this is a great problem!

 

--------

 

C/C++ Programming Problem

Please find three ways to change one character in the following code so that the resulting code will print 20 times - (minus sign). Remember : for each solution you can only change one character, and there are three different solutions (yes, space is one character too).

 

int i, n=20;
for(i = 0; i < n; i --)
  printf("-");

Basically it says you can't add or delete anything. Just "change" one character (including blanks). The output should be "--------------------" (20 minus signs). It took me a while to figure it out so it is definitely not a trick question or a joke. It makes you "think" when you see that only changing one character can have such dramatic effects :eek: ! Now go and try to debug 1 million lines of code in a real program :rolleyes: !!!

Link to comment
Share on other sites

Aright Seaphan. Actually, I don't know much about C or C++ even though I like it

Do you know Qbasic? Quick Basic? if so lets talk about it too. Talk about everything you know.

 

I've done your puzzle and yes it did take me a while do figure it out ut not that hard. Here it is:

 

code:
 

#include

 

int main()

 

{

int i, n=20;

for(i = 0; i < n; i++)

printf("-");

 

}


Link to comment
Share on other sites

LOL Man I really enjoyed reading all of your messages and I loughed at it. Damn! I guess this is getting more interesting then i thought it would. But anyway, I'm glad Seaphan that you know lot of programming languages. I haven't heard of Spagatti coding. But I know Seaphan you'll help me with my programs when i take them at school, but you will aslo help me learn this stuff quickly. LOL Anyway vontsor yuxem varum arten shat xosatsi.

 

OK now I'm trying to solve this puzzle you've given me. I change 2 instead of 1 asumes? ok ape hesa.....I'll post it later late me just see what i got.

Link to comment
Share on other sites

Hehehe ... don't worry about "ugh varel" is the computer section. There is enough of that in other sections and not enough here. We need balance in life

 

About spaghetti coding, it refers to how comlicated and confusing a program becomes prior to the new modularized and object oriented programming languages. Before, a program was just a list of stuff, usually with line numbers. If you wanted to do different things, you had to jump (goto) from line to line. If you tried to follow a program, you would often end up going through lines and lines, jumping back and forth, like what "spaghetti" looks like in a bowl

 

But basically with QBasic (and Pascal), a lot of that changed in mainstream "beginner" programming. So people who were just starting to program, started with functions and subroutines and started thinking more in terms of modules and objects as opposed to lines and instructions.

 

I think it was a huge step (even though C and maybe FORTRAN had already been doing it for a some time). Once Microsoft started distributing qbasic with DOS, ALL the little kids (including me) started learning programming the right way from the beginning.

Link to comment
Share on other sites

Seaphab this puzzle is a waiste of time i think i can't think of a way of doing without chaning 2 characters. I have to change 2 instead of 1. Since you said there are 3 ways of doing it, give me one way so that might be easier for me as an example.

 

How old are you Seaphan? Let's talk about Qbasic after finishing this puzzle.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...