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

Intensive Programming Lab 3

The document outlines the objectives of a programming lab focused on familiarizing students with data types, identifiers, operators, expressions, and basic input/output in C++. It includes examples of C++ programs for summing two numbers, performing arithmetic operations, and calculating the area and perimeter of geometric shapes. Additionally, it tasks students with writing programs for user input and temperature conversion.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Intensive Programming Lab 3

The document outlines the objectives of a programming lab focused on familiarizing students with data types, identifiers, operators, expressions, and basic input/output in C++. It includes examples of C++ programs for summing two numbers, performing arithmetic operations, and calculating the area and perimeter of geometric shapes. Additionally, it tasks students with writing programs for user input and temperature conversion.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Intensive Programming Lab

Lab 3: The Programming Environment

Learning Objectives:

The objectives of this first experiment are to make you familiar with data types, identifiers, basic
operators, expressions and basic input/output.

Example 1:

Write a C++ program that finds the sum of two numbers.

Code:
#include<iostream>
using namespace std;
/* function main begins program execution */
int main()
{
int num1=5; /* initializing an integer variable num1 to 5 */
int num2=9; /* initializing a variable num2 of integer data type */
int sum=0; /* variable sum in which sum will be stored */
sum= num1 + num2; /* Adding both number */
cout<<"The sum is: "<<sum;

return 0; /* indicate that program ended successfully */

} /* end function main */

Task 1: Write a C++ program to perform the basic arithmetic operations (addition, subtraction,
multiplication, division, remainder).

Example 2:

Write a C++ program that input two numbers from user and calculate their sum .

Code:
#include<iostream>
using namespace std;
/* function main begins program execution */
int main()
{
int num1, num2, sum; /* declairing variables */
cout<<"Enter two numbers";
cin>>num1>>num2; /*Reading two numbers from user */
sum= num1 + num2; /* Adding both number */
cout<<"The sum is: "<<sum; /* Display the result of addition */

return 0; /* indicate that program ended successfully */

} /* end function main */


Task 2: Write a C++ program that input two numbers from user and calculate basic arithmetic
operations (addition, subtraction, multiplication, division, remainder).

Task 3: Write a C-Program to calculate area and Perimeter of the triangle and rectangle.
[Area of triangle= ½ x base x vertical height , Perimeter of triangle = a + b + c]
[Area of rectangle= width x height , Perimeter of rectangle = 2( a + b)]

Task 4: Write a C++ program to enter temperature in Fahrenheit and convert to Celsius.

You might also like