Skip to main content

DSL A1

Hello Friends lets See the first practical of Data Structure Laboratory(DSL) of SPPU Second Year. Some of the students are afraid of coding as it is new to all of us. So we are here to conquer your fear. You will find it easy as it explained by students only.
So lets Get into it
The first practical of part A is :

In second year computer engineering class, group A student’s play cricket, group B students play badminton and group C students play football. Write a Python program using functions to compute following: - 
a) List of students who play both cricket and badminton 
b) List of students who play either cricket or badminton but not both 
c) Number of students who play neither cricket nor badminton 
d) Number of students who play cricket and football but not badminton. 
(Note- While realizing the group, duplicate entries should be avoided, Do not use SET built-in functions) 


So most of us know the SET theory in mathematics. The above problem is very easy if you have knowledge about set theory.
Lets Understand Above problem through Venn Diagram. We will assume three sets for Cricket, Badminton and Football as A, B and C respectively.As students can play multiple games all three sets are intersecting. It can be shown as  following :




where,
A=Set of Students Playing Cricket.
B=Set of Students Playing Badminton.
C=Set of Students Playing Football.
U=Set of Total No. of Students in Class.

So for every program we should first start with Input part. So get into input part we have to take Roll no. of total students  present in class and store it in Set U. Then we have to take Roll no. of students playing Cricket, Badminton and football in Set A, Set B, Set C respectively. Note though we are calling set to store elements we are using List Data Structure of python for storing Roll no. of students. 
So for Set U we will only take total no. students and then append Elements using for loop by incremental method.
For Set A we will first ask user to enter total no. of students playing cricket and that much times we will ask user to enter Roll no. of students using for loop.
Inside for loop using input() function we will take input and then append it to our List (set) A. Similarly we will perform for Badminton and Football.
Code for input is as follows:


Now Lets come to processing part. So lets start with First problem of our program we have to calculate students who play both cricket and badminton. In mathematical term it nothing but A∩B. So we have to find nothing but comman elements in A and B. Those elements which are present in both Set A and Set B.
In Venn Diagram it can be represented as follows :


To find comman elements we will use two for loops one for accessing the elements of  set A and Set B. Using for loop we can get  position of index in sets that we can use to access elements. Then we will compare the both elements from set a and set B and check whether they are equal or not  using if loop if they are equal then we will append it into the new list
The Program is as follows:


In second problem we have to create list of students who play either cricket or badminton but not both. So Students Who play cricket ,badminton and we have to remove elements comman to both which is nothing but set AB which we have calculated in a) problem.
In Venn Diagram it can be represented as follows :


The mathematical statement can be written as (A-AB)+(B-AB) .
First to calculate (A-AB) we will use two for loop for accessing elements and one if loop to check conditions.We will use flag variable to check whether the element is unique or not. flag is initialise as 0 to assume that element is unique Using if loop if we found that elements are equal than than we change flag to 1.
than after comparing one element of A with every element of AB(i.e After end of second for loop).We check if flag is 0 or not(UNIQUE or not) if it is 0 than we append to new list AOB.
Similarly we find (B-AB) and append elements to same list AOB
The Program is as follows:


In third problem we have to calculate number of students who play neither cricket nor badminton. It is nothing but from total no. of students(Universal Set) we have to remove students playing cricket and badminton. In mathematical statement it is ~(A⋃B) or (U-A-B)
The Venn Diagram can be represented as follows :


For this first we will remove elements of set A from set U.We will temporary store it in new list .than from new list we will remove elements of set B and store it in another list.So we need to initialise two new list.We will remove elements by same method as we used above (i.e using flag) 
The program for this is as follows:



In our last that is d) part we have to find number of students who play cricket and football but not badminton. Note here in question it is given cricket and football. So it is (A∩C) not (A⋃C). So from the set of students who play both cricket and football we have to remove students how play badminton.In mathematical statement it is nothing but (A∩C)-B.
The Venn Diagram it can be represented as follows :



For performing this task first we will find elements comman in both set A and set C using two for loop and one if loop. If we found the match we will we compare same element and check whether it is present in set B.If is not present in set B than we will append it to new list that is our required ans list.If the element is present than we can remove using flag method.  
The program for this is as follows:



You can Download Complete Code from Here 
DSL_A1 👈

Note that above problems can have multiple solution this can be one of them. If you find it useful please share with your friends . We are also from Second Year Computer Engineering so if there is any problem with code, if there are any suggestions or if you have any different code for this please share with us so that we and others who are visiting can also get new solutions by commenting below or sent to our mail.And do subscribe our blog if you want notifications as we are going to add all practicals and other information related to computer engineering
Thank You 🙏
 

Comments

Post a Comment

Popular posts from this blog

Bouncing Ball

Group B   Practical 4 a   Problem Statement :   Write a C++ program to implement bouncing ball using sine wave form. Apply the concept of polymorphism. Check Out Code Here  👇 Outputs :  Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊

OOP 6

   Object Oriented Programming Group B - Practical : 6 Problem Statement :  Write C++ program using STL for sorting and searching user defined records such as personal records (Name, DOB, Telephone number etc) using vector container. Check Out Code Here  👇 Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊