0% found this document useful (0 votes)
15 views7 pages

EC-237 Computer Systems & Programming Lab Report - 02: Fatima Hasnain ME-46-A

The document is a lab report for a Computer Systems & Programming course, detailing various tasks involving C++ programming. It includes code examples for arithmetic operations, modulus calculations, equality checks, comparisons, and a simple calculator program. Each task emphasizes the importance of comments for code clarity and user input handling.

Uploaded by

fatimahasnain410
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)
15 views7 pages

EC-237 Computer Systems & Programming Lab Report - 02: Fatima Hasnain ME-46-A

The document is a lab report for a Computer Systems & Programming course, detailing various tasks involving C++ programming. It includes code examples for arithmetic operations, modulus calculations, equality checks, comparisons, and a simple calculator program. Each task emphasizes the importance of comments for code clarity and user input handling.

Uploaded by

fatimahasnain410
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/ 7

DEPARTMENT OF COMPUTER & SOFTWARE ENGINEERING

COLLEGE OF E&ME, NUST, RAWALPINDI

EC-237 Computer Systems & Programming

LAB REPORT – 02

Course Instructor: Dr. Sagheer Khan

Lab Instructor: Engr. Eman Fatima

FATIMA HASNAIN
ME-46-A
Lab Tasks
TASK 1:

Write a C++ program that should take two integer inputs (already initialized) and use the
arithmetic operators to compute and display the sum, difference, product, and division of
the two numbers. Make sure to display the results of all the operations one by one. Make
sure to include comments for each line of the code to explain what it does.

CODE:

#include <iostream> // importing libraries


using namespace std;
int main()
{
int x = 5;
int y = 32;

int sum = x + y; // taking sum of x & y


int diff = x - y; // taking difference of x & y
int product = x * y; // taking product of x & y
int div = x / y; // dividing x by y

cout << "Sum: " << sum << endl; //displaying output
cout << "Difference: " << diff << endl;
cout << "Product: " << product << endl;
cout << "Division: " << div << endl;

system(“pause”); // to pause program to keep window open


return 0; // to indicate successful execution
}

OUTPUT:
TASK 2:

Write a C++ program that should take two integer inputs from the user. Using the modulus
operator, compute the remainder of the division of the first number by the second and
display the result. Make sure to include comments for each line of the code to explain what
it does.

CODE:

#include <iostream> //importing libraries


using namespace std;
int main()
{
int i1, i2, modulus; //declaring variables

cout << "Enter The First Integer ";

cin >> i1; //taking first integer as input from user

cout << "Enter The Second Integer ";

cin >> i2; //taking second integer as input from user

modulus = i1 % i2; //performing modulus operation

cout << "The Remainder Is: " << modulus << endl; //displaying output

system(“pause”); // to pause program to keep window open


return 0; // to indicate successful execution

OUTPUT:
TASK 3:

Write a C++ program that should take two integer inputs (already initialized) and check if
the numbers are equal or not using the equal to (==) and not equal to (!=) operators. For
both comparisons, display the result directly, with 1 representing true and 0 representing
false. Make sure to include comments for each line of the code to explain what it does.

CODE:

#include <iostream> // importing libraries


using namespace std;
int main()
{
int a = 5; // declaring & initializing variables
int b = 65;

if (a == b) { //using if else (conditional) statement


cout << "1" << endl;
}
if (a != b) {
cout << "0" << endl;
}
system(“pause”); // to pause program to keep window open
return 0; // to indicate successful execution

OUTPUT:
TASK 4:

Write a C++ program that should take two integer inputs from the user and use the greater
than (>), less than (<), and equal to (==) operators to compare the two numbers. For each
comparison, print the boolean result directly, with 1 representing true and 0 representing
false. Make sure to include comments for each line of the code to explain what it does.

CODE:

#include <iostream> // importing libraries

using namespace std;

int main()

int a, b; //declaring variables

cout << "Enter The First Integer(a): ";

cin >> a; //taking first integer as input from user

cout << "Enter The Second Integer(b): ";

cin >> b; //taking second integer as input from user

cout << "Is a Greater Than b: " << (a > b) << endl; //using boolean operators

cout << "Is a Less Than b: " << (a < b) << endl;

cout << "Is a Equal To b: " << (a == b) << endl;

system(“pause”); // to pause program to keep window open


return 0; // to indicate successful execution

OUTPUT:
HOME TASK

TASK 5:

Write a C++ program to create a simple calculator that performs basic arithmetic operations
(addition, subtraction, multiplication, division, and modulus) on two numbers provided by the
user. The program should perform all the operations. Use boolean operators to check if the
first number is greater than, less than, or equal to the second number, and display the
comparison result. Simply calculate and display the results of all the operations for the given
input numbers.

CODE:

#include <iostream>
using namespace std;
int main()
{
int x, y;
cout << "Enter The First Integer ";
cin >> x; //taking first integer as input from user
cout << "Enter The Second Integer ";
cin >> y; //taking second integer as input from user

int sum = x + y; // taking sum of x & y


int diff = x - y; // taking difference of x & y
int product = x * y; // taking product of x & y
int div = x / y; // dividing x by y

cout << "Sum: " << sum << endl;


cout << "Difference: " << diff << endl;
cout << "Product: " << product << endl;
cout << "Division: " << div << endl;

cout << "Is x Greater Than y: " << (x > y) << endl; // using boolean operators
cout << "Is x Less Than y: " << (x < y) << endl;
cout << "Is x Equal To y: " << (x == y) << endl;

system(“pause”); // to pause program to keep window open


return 0; // to indicate successful execution

}
OUTPUT:

You might also like