0% found this document useful (0 votes)
2 views4 pages

Programming Fundaments Week 1 Lab

The document outlines a lab for revising ITC concepts in C++, covering special symbols, data types, conditional statements, loops, and arrays. It details basic set operations such as union, intersection, difference, and complement using arrays, along with a searching problem involving student marks. The lab tasks include comparing search methods with and without sorting to determine efficiency.

Uploaded by

iamsaadshafiq
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)
2 views4 pages

Programming Fundaments Week 1 Lab

The document outlines a lab for revising ITC concepts in C++, covering special symbols, data types, conditional statements, loops, and arrays. It details basic set operations such as union, intersection, difference, and complement using arrays, along with a searching problem involving student marks. The lab tasks include comparing search methods with and without sorting to determine efficiency.

Uploaded by

iamsaadshafiq
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

Programming Fundaments

Week 1 Lab
Section B18

Lab Description:

This lab is basically design for the revision of ITC concepts.

How C++ program works

Special symbols:

Special symbols are the operator which are used to perform different operations like:

1. Arithmetic operators (+, -, *, /, %)


2. Logical operators (&&, ||, !)
3. Relational operators (>, <, >=, <=, ==, !=)
Data Type:

Data type is a set of values together with a set of allowed operations. Integral, which is a data type that
deals with integers, or numbers without a decimal part. Floating point, which is a data type that deals
with decimal numbers. Some of the data types which are commonly used are: integer(int), floating
point(float), character(char), Boolean(bool).

Conditional Statements

Loops
Array:

An array is a collection of a fixed number of components (also called elements) all of the same data type
and in contiguous (that is, adjacent) memory space.

Lab Tasks

Basic Set Operations:

Now that we know the concept of an arrays, we already know about sets which we learn in
mathematics. Let us discuss each set operation one by one in detail and see how we can perform basic
set operations using arrays.

Union of Sets:

For two given sets A and B, A ∪ B (read as A union B) is the set of distinct elements that belong to set A

A = {1, 2, 3, 4} and B = {4, 5, 6, 7}, then the union of A and B is given by A ∪ B = {1, 2, 3, 4, 5, 6, 7}. Now
and B or both. To understand this set operation of the union of sets better, let us consider an example: If

let’s consider set A and B as integer arrays and try to apply union operation on both arrays.

Intersection of Sets:

For two given sets A and B, A ∩ B (read as A intersection B) is the set of common elements that belong
to set A and B. To understand this set operation of the intersection of sets better, let us consider an
example: If A = {1, 2, 3, 4} and B = {3, 4, 5, 7}, then the intersection of A and B is given by A ∩ B = {3, 4}.
Now let’s consider set A and B as integer arrays and try to apply intersection operation on both arrays.

Set Difference:

The set operation difference between sets implies subtracting the elements from a set which is similar
to the concept of the difference between numbers. The difference between sets A and B denoted as A −
B lists all the elements that are in set A but not in set B. To understand this set operation of set
difference better, let us consider an example: If A = {1, 2, 3, 4} and B = {3, 4, 5, 7}, then the difference
between sets A and B is given by A - B = {1, 2}. Now let’s consider set A and B as integer arrays and try to
apply difference operation on both arrays.

Complement of Sets:

The complement of a set A denoted as A ′ or A c (read as A complement) is defined as the set of all the
elements in the given universal set(U) that are not present in set A. To understand this set operation of
complement of sets better, let us consider an example: If U = {1, 2, 3, 4, 5, 6, 7, 8, 9} and A = {1, 2, 3, 4},
then the complement of set A is given by A' = {5, 6, 7, 8, 9}. Now let’s consider set A and B as integer
arrays and try to apply complement operation on both arrays.

Searching Problem:
Identify the position holder:

We have multiple students in each class. We need to figure out the first three positions of our class. We
can store the marks of class into an array and roll numbers into another array. But select the data type
of arrays wisely.

Search without sorting:

Try to solve the above problem without sorting the data.

Search with sorting:

Try to solve the above problem with sorting the data.

Compare the working:

Now compare the working of both methods and identify which methods works smartly and efficiently.

You might also like