Jump to content

C++ class


someboddy

Recommended Posts

The first thing you need to know is how to use flowing diagrams. flowing diagrams are sample ways to show the program's guideline. flowing diagrams are written in normal language. for example, lets say we want towrite a program that get's a number, and multipile it by 2. so the flowing diagram goes like this.

 

 

Start

|

read number to A

|

put A*2 in A

|

write A

|

End

 

 

first, the program start's.

than, the program take a number from the user, and put it on the variable A.

than, the program change A to A*2/

than, the program write A on the screen.

than, the program end's.[/b]

Link to comment
Share on other sites

This flowing diagram can't actuly multipile's a number, but it can help us to create a program that can.

Type this program to the C++ compiler:

 

#include <iostream>

using namespace std;

 

void main(){

int A;

cin >>A;

A=A*2;

cout <<A;

}

 

now run it (press Ctrl+F9), enter a number, and press Enter. you will return to the editor. In order to see the program results, run the program again. (if you have visual C++, press F5 to run the program)

 

now I will explain the program:

 

#include <iostream>

using namespace std;

this part tells the program to use the file "iostream". this file contain's the basic commands you will need. every command in C++(and many another programming languages) must end with ";", so don't forget to put it.

 

void main(){

this command start's the program's boddy. after the program finish's the "include" part, it goes to the "main" part, and does the command's there. this line doesn't end with ";", becouse it's a function (I will explain about function's in more advance lesson's), and it will only end when it will reach to "}".

 

int A;

this command creates a new variable from the type integer, and give it the name "A". when we will want to use that variable, we use the name A. integer's are complete numbers, so you can't put fraction's in it.

 

cin >>A;

the "cin" command take's informatio from the users, and put it in variables. before every variable you want to put data in, you type ">>".

 

A=A*2;

this command put's the data in the right side ("A*2" in this case), to the variable in the left side ("A").

 

cout <<A;

the "cout" command print's data on the screen. the data can be variable, phrase, a number or text. before every data you want to print on the screen, you type "<<".

 

}

in order to end the "main" part (or any another block), you need "}". after the "}", you don't put ";".

Link to comment
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
×
×
  • Create New...