Lecture 2 : Writing Statements
Write Statements
What is Computer Variable
1. A symbol or name that stands for a value.
2. For example, in the expression x+y.
3. x and y are variables.
Running Program for the first time
1st. you need a compiler
#gallery-934-1 { margin: auto; } #gallery-934-1 .gallery-item { float: left; margin-top: 10px; text-align: center; width: 33%; } #gallery-934-1 img { border: 2px solid #cfcfcf; } #gallery-934-1 .gallery-caption { margin-left: 0; } /* see gallery_shortcode() in wp-includes/media.php */- image00210
- image0036
Running the compiler first time
`
Predefined Lines /Structure
| Command | Meaning |
| #include <iostream> | · It is a header file.
· Defined many pre built function like out put and input |
| Using name space std | · ‘namespace std’ is a ‘standard namespace’.
· cout, cin and a lot of other things are defined in it. (This means that one way to call them is by using std::cout and std::cin.) · The keyword using technically means, use this whenever you can. · This refers, in this case, to the std namespace. So whenever the computer comes across cout, cin, endl or anything of that matter, it will read it as std::cout, std::cin or std::endl. |
| Main() | · Start of a body |
| system(“pause”); | · Puase the screen , so you may screen the Screen . All compiler do not need it. |
Some important Terms




| #include <iostream> // Include the iostream library
using namespace std; // Use the standard namespace main ( ) { cout << “Hello world!”; // Print text to the screen system(“pause”); // Pause Screen } |
Press Compile


Click on Execute
Write 5 sentences on” My self”
| #include <iostream> // Include the iostream library
using namespace std; // Use the standard namespace main ( ) { cout << “My name is Ahmad Bilal ” ; // Print text to the screen cout << “I work at university of lahore ” ; // Print text to the screen cout << “I teach ITC ” ; // Print text to the screen cout << “I live in lahore ” ; // Print text to the screen cout << “I am Pakistani” ; // Print text to the screen system(“pause”); // Pause Screen } |
Running and Executing program
Problem 101
To set cursor on a new line type <<endl; after every sentence
New Code
| #include <iostream> // Include the iostream library
using namespace std; // Use the standard namespace main ( ) { cout << “My name is Ahmad Bilal “<<endl; // Print text to the screen cout << “I work at university of lahore”<<endl ; // Print text to the screen cout << “I teach ITC “<<endl ; // Print text to the screen cout << “I live in lahore “<<endl ; // Print text to the screen cout << “I am Pakistani”<<endl ; // Print text to the screen system(“pause”); // Pause Screen } |
First published on fatsup.wordpress.com ↗







