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

Arithmetic, Relational, Inc/dec Operators: Lab Example 1

The document provides examples and tasks to teach students about arithmetic operators in C++. It includes examples of pre-increment, post-increment, pre-decrement, and post-decrement operators. The tasks instruct students to write programs that: 1) perform basic arithmetic operations on user-input integers, 2) separate digits of a four digit number, 3) evaluate an expression using integer variables, and 4) swap the values of two variables without a third variable. The examples demonstrate calculating the area of a circle using user-input radius and constants.

Uploaded by

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

Arithmetic, Relational, Inc/dec Operators: Lab Example 1

The document provides examples and tasks to teach students about arithmetic operators in C++. It includes examples of pre-increment, post-increment, pre-decrement, and post-decrement operators. The tasks instruct students to write programs that: 1) perform basic arithmetic operations on user-input integers, 2) separate digits of a four digit number, 3) evaluate an expression using integer variables, and 4) swap the values of two variables without a third variable. The examples demonstrate calculating the area of a circle using user-input radius and constants.

Uploaded by

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

Lab Manual c++

Arithmetic, relational, inc/dec operators


Lab Objectives:

Teach the students how to use the arithmetic operations in mathematical expressions, and use

it to write and execute a simple program.


Teach the students the arithmetic operation precedence.

Lab Example 1
o Make a program which will read an integer variable count from user and then
write each of the following statements in cout and note the output.
1. ++count,
2. -- count,
3. count ++,
4. count - -;

Source Code:
#include <iostream>
using namespace std;
int main()
{
int count ;
cout<<Enter the variable<<endl;
cin>>count;
cout<< count= << count <<endl;
cout<< count= << ++count <<endl;
cout<< count= << count <<endl;
cout<< count= << count++ <<endl;
cout<< count= << count <<endl;
return 0;
}

Lab Manual c++

Lab Task 1
o Write a program that reads two integers and output the result of following
operation:
a.
b.
c.
d.
e.

Addition
Subtraction
Division
Multiplication
Square

Lab Example 2
o Write a program that input radius of circle from the user and find out area of
circle.
Source Code:
int main()
{
float rad;
//variable of type float
const float PI = 3.14159F;
//type const float
cout<< Enter radius of circle: ; //prompt
cin>> rad;
//get radius
float area = PI * rad * rad;
//find area
cout<< Area is << area <<endl; //display answer
return 0;
}

Lab Task 2
o Write a program that reads a four digit number from user, then the program separates digits of
the number e.g 4567 to be displayed as:
4
5
6
7
2

Lab Manual c++

Lab Task 3
o Write a program that defines variables m, n, p, and amount, as integer Solve the following
expression on notebook by supposing some values of each variable, then execute your
program for the same values and see the difference if any.

(m + n) / (p + amount)

Lab Task 4
o

Write a program in C++ which would swap the values of two variables without using the third variable.

You might also like