LAB 03 Programing
LAB 03
Lab-4
Introduction to Programming
OBJECTIVE:
To understand basics of programming in C++ .
EQUIPMENT REQUIRED:
• Laptop
• Computer
TOOLS REQUIRED:
• DEV - C++
Theory & Procedure:
• Language Processors o Compiler—translates C++ source code to machine code. o Linker—
combines the compiler-generated machine code with precompiled library code or compiled code
from other sources to make a complete executable program. o Preprocessor—adds to or modifies
the contents of the source file before the compiler begins processing the code.
• Programming Techniques o Structure Programming o Sequential Structure o Conditional
Structure o Iterative Structure o Function Call
• Main Function o #include <iostream>
This line is a preprocessing directive. All preprocessing directives within C++ source
code begin with a # symbol. This one directs the preprocessor to add some predefined
source code to our existing source code before the compiler begins to process it.
o int main()
This specifies the real beginning of our program. Here we are declaring a function named
main. All C++ programs must contain this function to be executable.
• C++ Statements
The statements of the program are written in curly braces. The curly brace {is called opening brace and}
is called closing brace. The braces are known as delimiters. These statements are collectively known as
body of a program.
#include <iostream>
Computer System and Programing Page 1
LAB 03 Programing
using namespace std;
int main() {
cout << "This is a simple C++ program!" <<
endl;
}
Following are the building blocks that are used to build a C++ Program:
• numeric values
• variables
• declarations
• assignment
• identifiers
• reserved words
Data Types:
int: this key word is used to store integer values. It takes 2 to 4 bytes in memory float:
it is used to store real values. It takes 4 bytes in memory. char: it is used to store
character value. It takes 1 byte in memory.
Syntax:
int varname; int: C++
Keyword varname: Variable
identifier
; : Statement terminator
Variable declaration: the process of specifying variable name and its data type is called variable
declaration
Example of variable
declaration:
#include <iostream>
using namespace std;
int main() {
int x;
Variable Initialization: the process of assigning a value to a variable at the time of declaration is known as
variable initialization
Example of variable initialization:
#include <iostream>
using namespace std;
Computer System and Programing Page 2
LAB 03 Programing
int main() {
int x=10;
cout << x << endl;
}
Exercises:
1. Write a program that performs all mathematical operations on two variables.
2. Write a program that inputs name, age and address from the user and then displays these values
on screen.
Computer System and Programing Page 3
LAB 03 Programing
Computer System and Programing Page 4
LAB 03 Programing
3. Write a program that solves the following expression a * b/ (-c * 31 % 13) *d
4. Write a program that inputs the and applied arithmetic operation .
Rubric 1
Marks CLO1 – Level C2 mapped to PLO1 (Knowledge)
Computer System and Programing Page 5
LAB 03 Programing
02 Is not able to write the code in C++ and interpret it. Major help is required in
writing the program.
06 Can write and interpret C++ codes with minor error help.
10 Can write and interpret C++ codes effectively and confidently.
Computer System and Programing Page 6