Programming Fundamental Lab Manual 2
Programming Fundamental Lab Manual 2
Programming Fundamental Lab Manual 2
What is programming?
Programming is the process of creating sets of instructions that tell a computer what to
do.
It involves writing code in a programming language to solve problems or automate tasks .
Programming Languages
Definition: Programming languages are formal languages designed to communicate
instructions to a computer.
Examples: Python, Java, C++, Kotlin
Compilers and interpreters are program that help convert the high level language
into machine code.
Compiler Vs Interpreter
• Compiler convert the whole high level language program to machine language
at a time while
C++ Compiler:
• GCC stands for GNU Compilers Collections is used to compile mainly C and
C++ language.
Installation Steps
What is C++?
Write the following C++ code and save the file as myfirstprogram.cpp (File > Save File as):
myfirstprogram.cpp
1. #include <iostream>
2. using namespace std;
3. int main() {
4. cout << "Hello World!";
5. return 0;
6. }
Don't worry if you don't understand the code above - we will discuss it in detail in later chapters.
For now, focus on how to run the code. In Codeblocks, it should look like this:
Then, go to Build > Build and Run to run (execute) the program.
#include <iostream> is a header file library that lets us work with input and output
objects, such as cout. Header files add functionality to C++ programs.
using namespace std means that we can use names for objects and variables from
the standard library.
Another thing that always appear in a C++ program, is int main(). This is called
a function. Any code inside its curly brackets {} will be executed.
The cout object, together with the insertion operator (<<), is used to output
values/print text.
New Lines
#include <iostream>
using namespace std;
int main() {
cout << "Hello World! \n";
cout << "I am learning C++";
return 0;
}
Or
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
cout << "I am learning C++";
return 0;
}
C++ Comments
Comments can be used to explain C++ code, and to make it more readable. It can also
be used to prevent execution when testing alternative code. Comments can be singled-
lined or multi-lined.
Single-line Comments
Any text between // and the end of the line is ignored by the compiler (will not be
executed).
This example uses a single-line comment before a line of code:
Example
// This is a comment
cout << "Hello World!";
Example