0% found this document useful (0 votes)
5 views

Lab 01

Uploaded by

degag64086
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab 01

Uploaded by

degag64086
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction to Computer Programming (EE)

Lab 01: Introduction


Objectives:
To acquaint students with basics of C++ Programming

Basic Program Structure

#include<iostream>
Using namespace std;
Int main()
{
Cout<< “Hello World!”;
Return 0;
}

Preprocessor Directive - #include<iostream>

The main function -int main (), int > return type integer, main > name of the
function, ( ) > argument list or list of parameters

Cout << -Command for display of output

Return 0 -Returning value of 0

Variable
A variable is used to hold a value, it is a place in the computer memory which needs to be
declared inside the body of program. Variable has 4 basic parameters:

1. Name
2. Data type
3. Value
4. Address

Muhammad Hammad Page 1


Introduction to Computer Programming (EE)

The value of variable can be changed after its declaration. On the other hand, constants have a
fixed value once they are declared. Every variable has some data type e.g., int, float, char, long,
double etc. Datatypes will be discussed in detail in lab 2. When a variable is declared, it takes
some memory and possesses some address.

int a=10; int b=20; int sum;

in the above example, variable a and b are declared as well as instantiated while variable sum is
just declared.

Try Example

#include<iostream>
using namespace std;
int main()
{
int a=10;int b=20;int sum;
cout<<"The value of a is "<<a<<endl;
cout<<"This value of b is "<<b<<endl;
sum=a+b;
cout<<"The sum is "<<sum;
return 0;
}

Cin>> - Command for taking input data.

cout<<" Enter value of variable a ";


cin>>a;

Muhammad Hammad Page 2


Introduction to Computer Programming (EE)

Lab Tasks
1. Write a C++ program that takes two inputs from the user and calculates their
sum. Display the result.
2. Write a C++ program that takes three integer inputs, calculates their average,
and displays output.
3. Write a C++ program which calculated area of circle by taking radius from
user.
4. Append the above program and calculate the volume of a sphere.
5. Write a C++ program to calculate (𝑎 + 𝑏)2 .

Muhammad Hammad Page 3

You might also like