Professional Documents
Culture Documents
Chapter 2,3
Introduction to C++
Lecture Outline:
• Sample programs
Programming Examples
EXAMPLE 1:
4
Programming Examples
EXAMPLE 1:
#include <iostream>
Write a program to ask using namespace std;
int main()
the user for the width {
const int one_tree_space 4;
and length of a piece of int length, width, area, no_of_trees;
cout<<“Enter the length of the land \n”;
land and then tell him cin>>length;
cout<<“Enter the width of the land \n”;
how many orange trees cin>>width;
area = Length*width;
he can grow on it. no_of_trees=area/one_tree_space;
cout<<“The available number of trees = “<<no_of_trees;
Given that each orange return(0);
}
tree requires 4 m2.
5
Programming Examples
EXAMPLE 2:
6
Programming Examples
7
Thank You