├── GroupA_Practical1(python).py ├── GroupA_Practical2(python).py ├── GroupA_Practical7(python).py ├── GroupA_Practical9(python).py ├── GroupB_Practical13(python).py ├── GroupB_Practical14(python).py ├── GroupB_Practical16(python).py ├── GroupC_Practical19(C++).cpp ├── GroupC_Practical20(C++).cpp ├── GroupD_Practical25(C++).cpp ├── GroupD_Practical26(C++).cpp ├── GroupE_Practical29(C++).cpp ├── GroupE_Practical31(C++).cpp ├── GroupE_Practical32(C++).cpp └── README.md /GroupA_Practical1(python).py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | 4 | Experiment No. 1 : In a second year computer engineering class, group A students play cricket, group B students play 5 | badminton and group C students play football. 6 | Write a python program using functions to compute following: 7 | a) List of students who play both cricket and badminton. 8 | b) List of students who play either cricket or badminton but not both. 9 | c) Number of students who play neither cricket nor badminton. 10 | d) Number of students who play cricket and football but not badminton. 11 | (NOTE : While realising the group, duplicate entries should be avoided. Do not use SET built-in functions) 12 | ''' 13 | 14 | 15 | # Function for removing duplicate entries from the group 16 | 17 | def removeDuplicate(d): 18 | lst=[] 19 | for i in d: 20 | if i not in lst: 21 | lst.append(i) 22 | return lst 23 | 24 | #<----------------------------------------------------------------------------------------> 25 | 26 | # Function for finding intersection between two sets (A&B) 27 | 28 | def intersection(lst1,lst2): 29 | lst3=[] 30 | for val in lst1: 31 | if val in lst2: 32 | lst3.append(val) 33 | return lst3 34 | 35 | #<------------------------------------------------------------------------------------------> 36 | 37 | # Function for finding union of two sets (A|B) 38 | 39 | def union(lst1,lst2): 40 | lst3=lst1.copy() 41 | for val in lst2: 42 | if val not in lst3: 43 | lst3.append(val) 44 | return lst3 45 | 46 | #<-------------------------------------------------------------------------------------------> 47 | 48 | # Function for finding difference between two sets (A-B) 49 | 50 | def diff(lst1,lst2): 51 | lst3=[] 52 | for val in lst1: 53 | if val not in lst2: 54 | lst3.append(val) 55 | return lst3 56 | 57 | #<----------------------------------------------------------------------------------------------> 58 | 59 | # Function for finding symmetric difference of two sets (A^B) 60 | 61 | def sym_diff(lst1,lst2): 62 | lst3=[] 63 | D1=diff(lst1,lst2) 64 | print("Difference between Cricket and Badminton (C-B) is : ", D1) 65 | D2=diff(lst2,lst1) 66 | print("Difference between Badminton and Cricket (B-C) is : ", D2) 67 | lst3=union(D1,D2) 68 | return lst3 69 | 70 | #<------------------------------------------------------------------------------------------------> 71 | 72 | # Functon for finding List of students who play both cricket and badminton 73 | 74 | def CB(lst1,lst2): 75 | lst3=intersection(lst1,lst2) 76 | print("\n\nList of students who play both cricket and badminton is : ", lst3) 77 | return len(lst3) 78 | 79 | #<------------------------------------------------------------------------------------------------> 80 | 81 | # Function for finding List of students who play either cricket or badminton but not both 82 | 83 | def eCeB(lst1,lst2): 84 | lst3=sym_diff(lst1,lst2) 85 | print("\nList of students who play either cricket or badminton but not both is : ",lst3) 86 | return len(lst3) 87 | 88 | #<--------------------------------------------------------------------------------------------------> 89 | 90 | # Function for finding Number of students who play neither cricket nor badminton 91 | 92 | def nCnB(lst1,lst2,lst3): 93 | lst4=diff(lst1,union(lst2,lst3)) 94 | print("\n\nList of students who play neither cricket nor badminton is : ",lst4) 95 | return len(lst4) 96 | 97 | #<---------------------------------------------------------------------------------------------------> 98 | 99 | # Function for finding Number of students who play cricket and football but not badminton 100 | 101 | def CBnF(lst1,lst2,lst3): 102 | lst4=diff(intersection(lst1,lst2),lst3) 103 | print("\n\nList of students who play cricket and football but not badminton is : ",lst4) 104 | return len(lst4) 105 | 106 | #<-----------------------------------------------------------------------------------------------------> 107 | 108 | # Main function 109 | 110 | # Creating an empty list for SE COMP 111 | SEComp = [] 112 | n = int(input("\nEnter number of students in SE COMP: ")) 113 | print("Enter the names of",n,"students (Please press ENTER after entering each students name) :") 114 | for i in range(0, n): 115 | ele = input() 116 | SEComp.append(ele) # adding the element 117 | print("Original list of students in SEComp : " + str(SEComp)) 118 | 119 | #<-------------------------------------------------------------------------------------------------------> 120 | 121 | 122 | # Creating an empty list for Cricket 123 | Cricket = [] 124 | n = int(input("\n\nEnter number of students who play cricket : ")) 125 | print("Enter the names of",n,"students who play cricket (Please press ENTER after entering each students name) :") 126 | for i in range(0, n): 127 | ele = input() 128 | Cricket.append(ele) # adding the element 129 | print("Original list of students playing cricket is :" +str(Cricket)) 130 | Cricket=removeDuplicate(Cricket) 131 | print("The list of students playing cricket after removing duplicates : " +str(Cricket)) 132 | 133 | #<-------------------------------------------------------------------------------------------------------> 134 | 135 | 136 | # Creating an empty list for Football 137 | Football = [] 138 | n = int(input("\n\nEnter number of students who play football : ")) 139 | print("Enter the name of",n,"students who play football (Please press ENTER after entering each students name) :") 140 | for i in range(0, n): 141 | ele = input() 142 | Football.append(ele) # adding the element 143 | print("Original list of students playing football :" +str(Football)) 144 | Football=removeDuplicate(Football) 145 | print("The list of students playing football after removing duplicates : " +str(Football)) 146 | 147 | #<--------------------------------------------------------------------------------------------------------> 148 | 149 | 150 | # Creating an empty list for Badminton 151 | Badminton = [] 152 | n = int(input("\n\nEnter number of students who play badminton : ")) 153 | print("Enter the name of",n,"students who play badminton (Please press ENTER after entering each students name) :") 154 | for i in range(0, n): 155 | ele = input() 156 | Badminton.append(ele) # adding the element 157 | print("Original list of students playing badminton :" +str(Badminton)) 158 | Badminton=removeDuplicate(Badminton) 159 | print("The list of students playing badminton after removing duplicates : " +str(Badminton)) 160 | 161 | #<----------------------------------------------------------------------------------------------------------> 162 | 163 | flag=1 164 | while flag==1: 165 | print("\n\n--------------------MENU--------------------\n") 166 | print("1. List of students who play both cricket and badminton") 167 | print("2. List of students who play either cricket or badminton but not both") 168 | print("3. List of students who play neither cricket nor badminton") 169 | print("4. Number of students who play cricket and football but not badminton") 170 | print("5. Exit\n") 171 | ch=int(input("Enter your Choice (from 1 to 5) :")) 172 | 173 | if ch==1: 174 | print("Number of students who play both cricket and badminton : ", CB(Cricket,Badminton)) 175 | a = input("\n\nDo you want to continue (yes/no) :") 176 | if a == "yes": 177 | flag = 1 178 | else: 179 | flag = 0 180 | print("Thanks for using this program!") 181 | 182 | elif ch==2: 183 | print("Number of students who play either cricket or badminton but not both : ", eCeB(Cricket, Badminton)) 184 | a = input("\n\nDo you want to continue (yes/no) :") 185 | if a == "yes": 186 | flag = 1 187 | else: 188 | flag = 0 189 | print("Thanks for using this program!") 190 | 191 | elif ch==3: 192 | print("Number of students who play neither cricket nor badminton : ", nCnB(SEComp,Cricket,Badminton)) 193 | a = input("\n\nDo you want to continue (yes/no) :") 194 | if a == "yes": 195 | flag = 1 196 | else: 197 | flag = 0 198 | print("Thanks for using this program!") 199 | 200 | elif ch==4: 201 | print("Number of students who play cricket and football but not badminton : ", CBnF(Cricket,Football,Badminton)) 202 | a = input("\n\nDo you want to continue (yes/no) :") 203 | if a == "yes": 204 | flag = 1 205 | else: 206 | flag = 0 207 | print("Thanks for using this program!") 208 | 209 | elif ch==5: 210 | flag=0 211 | print("Thanks for using this program!") 212 | 213 | else: 214 | print("!!Wrong Choice!! ") 215 | a=input("\n\nDo you want to continue (yes/no) :") 216 | if a=="yes": 217 | flag=1 218 | else: 219 | flag=0 220 | print("Thanks for using this program!") 221 | 222 | #<---------------------------------------------END OF PROGRAM---------------------------------------> 223 | 224 | 225 | 226 | 227 | 228 | 229 | -------------------------------------------------------------------------------- /GroupA_Practical2(python).py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | Experiment Number 2 : Write a python program to store marks stored in subject "Fundamentals of Data Structure" by 4 | N students in the class. Write functions to compute following: 5 | 1. The average score of the class. 6 | 2. Highest score and lowest score of the class. 7 | 3. Count of students who were absent for the test. 8 | 4. Display mark with highest frequency. 9 | ''' 10 | 11 | 12 | # Function for average score of the class 13 | 14 | def average(listofmarks): 15 | sum=0 16 | count=0 17 | for i in range(len(listofmarks)): 18 | if listofmarks[i]!=-999: 19 | sum+=listofmarks[i] 20 | count+=1 21 | avg=sum/count 22 | print("Total Marks : ", sum) 23 | print("Average Marks : {:.2f}".format(avg)) 24 | 25 | #<-----------------------------------------------------------------------------------------------------> 26 | 27 | # Function for Highest score in the test for the class 28 | 29 | def Maximum(listofmarks): 30 | for i in range(len(listofmarks)): 31 | if listofmarks[i]!=-999: 32 | Max=listofmarks[0] 33 | break 34 | for i in range(1,len(listofmarks)): 35 | if listofmarks[i]>Max: 36 | Max=listofmarks[i] 37 | return(Max) 38 | 39 | #<------------------------------------------------------------------------------------------------------> 40 | 41 | # Function for Lowest score in the test for the class 42 | 43 | def Minimum(listofmarks): 44 | for i in range(len(listofmarks)): 45 | if listofmarks[i]!=-999: 46 | Min=listofmarks[0] 47 | break 48 | for i in range(1,len(listofmarks)): 49 | if listofmarks[i] 54 | 55 | # Function for counting the number of students absent for the test 56 | 57 | def absentcount(listofmarks): 58 | count=0 59 | for i in range(len(listofmarks)): 60 | if listofmarks[i]==-999: 61 | count+=1 62 | return(count) 63 | 64 | #<-------------------------------------------------------------------------------------------------------> 65 | 66 | # Function for displaying marks with highest frequency 67 | def maxFrequency(listofmarks): 68 | i=0 69 | Max=0 70 | print("Marks | Frequency") 71 | for j in listofmarks: 72 | if (listofmarks.index(j)==i): 73 | print(j," | ",listofmarks.count(j)) 74 | if listofmarks.count(j)>Max: 75 | Max=listofmarks.count(j) 76 | mark=j 77 | i=i+1 78 | return(mark,Max) 79 | 80 | 81 | #<-------------------------------------------------------------------------------------------------------> 82 | 83 | # Main function 84 | 85 | marksinFDS=[] 86 | numberofstudents=int(input("Enter total number of students : ")) 87 | for i in range(numberofstudents): 88 | marks=int(input("Enter marks of student "+str(i+1)+" : ")) 89 | marksinFDS.append(marks) 90 | 91 | flag=1 92 | while flag==1: 93 | print("\n\n--------------------MENU--------------------\n") 94 | print("1. Total and Average Marks of the Class") 95 | print("2. Highest and Lowest Marks in the Class") 96 | print("3. Number of Students absent for the test") 97 | print("4. Marks with Highest Frequency") 98 | print("5. Exit\n") 99 | ch=int(input("Enter your Choice (from 1 to 5) :")) 100 | 101 | if ch==1: 102 | average(marksinFDS) 103 | a = input("Do you want to continue (yes/no) :") 104 | if a == "yes": 105 | flag = 1 106 | else: 107 | flag = 0 108 | print("Thanks for using this program!") 109 | 110 | elif ch==2: 111 | print("Highest Score in Class : ", Maximum(marksinFDS)) 112 | print("Lowest Score in Class : ", Minimum(marksinFDS)) 113 | a = input("Do you want to continue (yes/no) :") 114 | if a == "yes": 115 | flag = 1 116 | else: 117 | flag = 0 118 | print("Thanks for using this program!") 119 | 120 | elif ch==3: 121 | print("Number of Students absent in the test : ", absentcount(marksinFDS)) 122 | a = input("Do you want to continue (yes/no) :") 123 | if a == "yes": 124 | flag = 1 125 | else: 126 | flag = 0 127 | print("Thanks for using this program!") 128 | 129 | elif ch==4: 130 | mark,fr = maxFrequency(marksinFDS) 131 | print("Highest frequency is of marks {0} that is {1} ".format(mark,fr)) 132 | a = input("Do you want to continue (yes/no) :") 133 | if a == "yes": 134 | flag = 1 135 | else: 136 | flag = 0 137 | print("Thanks for using this program!") 138 | 139 | elif ch==5: 140 | flag=0 141 | print("Thanks for using this program!") 142 | 143 | else: 144 | print("!!Wrong Choice!! ") 145 | a=input("Do you want to continue (yes/no) :") 146 | if a=="yes": 147 | flag=1 148 | else: 149 | flag=0 150 | print("Thanks for using this program!") 151 | 152 | #<---------------------------------------------END OF PROGRAM---------------------------------------> 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /GroupA_Practical7(python).py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | Experiment No. 7 : Write a python program for MAGIC SQUARE. 4 | A magic square is an n*n matrix of the integers 1 to (n^2) such that the sum of each row, 5 | column and diagonalis the same. 6 | The figure given below is an example of the magic square for case n=5. In this example 7 | the common sum is 65. 8 | 9 | 9 | 3 | 22 | 16 | 15 | 10 | 2 | 21 | 20 | 14 | 8 | 11 | 25 | 19 | 13 | 7 | 1 | 12 | 18 | 12 | 6 | 5 | 24 | 13 | 11 | 10 | 4 | 23 | 17 | 14 | 15 | Conditions for placing the values in the matrix in appropriate manner (CIRCULAR ARRAY) : 16 | 17 | 1. The position of next number is calculated by decrementing row number of previous number by 1, and incrementing 18 | the column number of previous number by 1. At any time, if the calculated row position becomes -1, it will wrap 19 | around to n-1. Similarly, if the calculated column position becomes n, it will wrap around to 0. 20 | 21 | 2. If the magic square already contains a number at the calculated position, calculated column position will be 22 | decremented by 2, and calculated row position will be incremented by 1. 23 | 24 | 3. If the calculated row position is -1 & calculated column position is n, the new position would be: (0, n-2). 25 | ''' 26 | 27 | 28 | # A function to generate odd 29 | # sized magic squares 30 | 31 | def generate_Magic_Square(size): 32 | magicSquare=[[0 for x in range(size)] for y in range(size)] 33 | 34 | # Initializing first position of matrix 35 | i=size/2 36 | j=size-1 37 | 38 | # Fill the magic square by placing values at appropriate position 39 | num=1 40 | while num<=(size*size): 41 | if i==-1 and j==size: # 3rd Condition 42 | j=size-2 43 | i=0 44 | else: 45 | # next number goes out of right side of square 46 | if j==size: 47 | j=0 48 | 49 | # next number goes out of upper side 50 | if i<0: 51 | i=size-1 52 | 53 | if magicSquare[int(i)][int(j)]: # 2nd condition 54 | j=j-2 55 | i=i+1 56 | continue 57 | else: 58 | magicSquare[int(i)][int(j)]=num 59 | num=num+1 60 | 61 | j=j+1 62 | i=i-1 # 1st condition 63 | 64 | # Printing of magic square 65 | sum=size*(size*size+1)/2 66 | print("Sum of each row or column is : ",sum) 67 | print("Magic Square of size",size,"*",size,"is : \n") 68 | 69 | for i in range(0,size): 70 | for j in range(0,size): 71 | print(' %2d ' % (magicSquare[i][j]),end=' | ') 72 | 73 | # To display magic square in matrix form 74 | if j==size-1: 75 | print() 76 | 77 | #<-------------------------------------------------------------------------------------------------> 78 | 79 | #Main function 80 | 81 | flag=1 82 | while flag==1: 83 | n=int(input("\nEnter the size of the MAGIC SQUARE : ")) 84 | if n%2==0: 85 | s=int(input("Please enter an ODD Number (for example - 3,5,7,9,....) : ")) 86 | generate_Magic_Square(s) 87 | else: 88 | generate_Magic_Square(n) 89 | a=input("\nDo you want to print Magic Square of some other size (yes/no) : ") 90 | if a=='yes': 91 | flag=1 92 | else: 93 | flag=0 94 | print("\nThanks for using this program!") 95 | 96 | #<------------------------------------------ END OF PROGRAM -----------------------------------------> 97 | 98 | 99 | -------------------------------------------------------------------------------- /GroupA_Practical9(python).py: -------------------------------------------------------------------------------- 1 | ''' 2 | This program is created by ATHARVA PAWAR 3 | 4 | Experiment No. 9 : Write a Python Program to compute following computation on matrices : 5 | a)Addition of two matrices 6 | b)Subtraction of two matrices 7 | c)Multiplication of two matrices 8 | d)Transpose of a matix 9 | ''' 10 | 11 | import numpy 12 | 13 | # initializing matrices 14 | x = numpy.array([[1, 2], [4, 5]]) 15 | y = numpy.array([[7, 8], [9, 10]]) 16 | 17 | # using add() to add matrices 18 | print("The element wise addition of matrix is : ") 19 | print(numpy.add(x, y)) 20 | 21 | # using subtract() to subtract matrices 22 | print("The element wise subtraction of matrix is : ") 23 | print(numpy.subtract(x, y)) 24 | 25 | # using dot() to multiply matrices 26 | print ("The product of matrices is : ") 27 | print (numpy.dot(x,y)) 28 | 29 | 30 | # using "T" to transpose the matrix 31 | print("The transpose of given matrix is : ") 32 | print(x.T) 33 | 34 | 35 | # Created by ATHARVA PAWAR 36 | -------------------------------------------------------------------------------- /GroupB_Practical13(python).py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | 4 | Experiment No. 13 : Write a python program to maintain club members, sort on roll numbers in ascending order. 5 | Write function “Ternary_Search” to search whether particular student is member of club or not. 6 | Ternary search is modified binary search that divides array into 3 halves instead of two. 7 | ''' 8 | 9 | 10 | # Accepting Roll Numbers of the Students 11 | 12 | def accept_roll(): 13 | roll_no = [] 14 | no_of_students = int(input("Enter the number of students : ")) 15 | for i in range(no_of_students): 16 | roll_no.append(int(input("Enter Roll Number of Student {0} : ".format(i+1)))) 17 | return roll_no 18 | 19 | #<---------------------------------------------------------------------------------------------> 20 | 21 | # Printing the Roll Numbers of the Students 22 | 23 | def print_roll(roll_no): 24 | for i in range(len(roll_no)): 25 | print(roll_no[i],sep = "\n") 26 | 27 | #<---------------------------------------------------------------------------------------------> 28 | 29 | # Insertion Sort for Sorting the list of Roll Numbers 30 | 31 | def insertion_sort(roll_no): 32 | for i in range(1,len(roll_no)): 33 | key = roll_no[i] 34 | j = i-1; 35 | while j >= 0 and key < roll_no[j]: 36 | roll_no[j+1] = roll_no[j] 37 | j -= 1 38 | roll_no[j+1] = key 39 | return roll_no 40 | 41 | #<----------------------------------------------------------------------------------------------> 42 | 43 | # Function for performing Non-Recursive Ternary Search 44 | 45 | def NR_Ternary_Search(roll,roll_find): 46 | left = 0 47 | right = len(roll) - 1 48 | while left <= right: 49 | mid1 = left + (right - left) // 3 50 | mid2 = left + 2 * (right - left) // 3 51 | if roll_find == roll[left]: 52 | return left 53 | elif roll_find == roll[right]: 54 | return right 55 | elif roll_find < roll[left] or roll_find > roll[right]: 56 | return -1 57 | elif roll_find <= roll[mid1]: 58 | right = mid1 59 | elif roll_find > roll[mid1] and roll_find <= roll[mid2]: 60 | left = mid1 + 1 61 | right = mid2 62 | else: 63 | left = mid2 + 1 64 | return -1 65 | 66 | #<-------------------------------------------------------------------------------------------------> 67 | 68 | # Function for performing Recursive Ternary Search 69 | 70 | def R_Ternary_Search(roll, left, right, roll_find): 71 | if (right >= left): 72 | mid1 = left + (right - left) // 3 73 | mid2 = right - (right - left) // 3 74 | if (roll[mid1] == roll_find): 75 | return mid1 76 | if (roll[mid2] == roll_find): 77 | return mid2 78 | 79 | if (roll_find < roll[mid1]): 80 | return R_Ternary_Search(roll, left, mid1 - 1, roll_find) 81 | elif (roll_find > roll[mid2]): 82 | return R_Ternary_Search(roll, mid2 + 1, right, roll_find) 83 | else: 84 | return R_Ternary_Search(roll, mid1 + 1, mid2 - 1, roll_find) 85 | return -1 86 | 87 | #<----------------------------------------------------------------------------------------------------> 88 | 89 | # Main 90 | unsort_Roll = [] 91 | sort_Roll = [] 92 | flag = 1 93 | 94 | while flag == 1: 95 | print("\n---------------------MENU---------------------") 96 | print("1. Accept Student Roll Numbers") 97 | print("2. Display the Roll Numbers of Student") 98 | print("3. Sort Roll Numbers from the list") 99 | print("4. Perform Non-Recursive Ternary Search") 100 | print("5. Perform Recursive Ternary Search") 101 | print("6. Exit\n") 102 | 103 | ch = int(input("Enter your choice (from 1 to 6) : ")) 104 | 105 | if ch == 1: 106 | unsort_Roll = accept_roll() 107 | 108 | elif ch == 2: 109 | print_roll(unsort_Roll) 110 | 111 | elif ch == 3: 112 | print("Elements after performing Insertion Sort : \n") 113 | sort_Roll = insertion_sort(unsort_Roll) 114 | print_roll(sort_Roll) 115 | 116 | elif ch == 4: 117 | find_roll = int(input("Enter the Roll Number to be searched : ")) 118 | index = NR_Ternary_Search(sort_Roll,find_roll) 119 | if index != -1: 120 | print("The Roll Number",find_roll,"is found at position",index+1) 121 | else: 122 | print("Roll Number",find_roll,"nor found!!") 123 | 124 | elif ch == 5: 125 | find_roll = int(input("Enter the Roll Number to be searched : ")) 126 | left = 0 127 | right = len(sort_Roll) - 1 128 | index = R_Ternary_Search(sort_Roll,left,right,find_roll) 129 | if index != -1: 130 | print("The Roll Number",find_roll,"is found at position",index+1) 131 | else: 132 | print("Roll Number",find_roll,"nor found!!") 133 | 134 | elif ch == 6: 135 | print("Thanks for using this program!!") 136 | flag=0 137 | 138 | else: 139 | print("Wrong choice!!") 140 | flag = 0 141 | 142 | 143 | #<-------------------------------------END OF PROGRAM------------------------------------------> 144 | 145 | 146 | -------------------------------------------------------------------------------- /GroupB_Practical14(python).py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | 4 | Experiment Number 14: Write a python program to store first year percentage of students in an array. 5 | Write function for sorting array of floating point numbers in ascending order using: 6 | a) Selection Sort 7 | b) Bubble Sort and display top five scores 8 | ''' 9 | 10 | 11 | # Function for Selection Sort of elements 12 | 13 | def Selection_Sort(marks): 14 | for i in range(len(marks)): 15 | 16 | # Find the minimum element in remaining unsorted array 17 | min_idx = i 18 | for j in range(i + 1, len(marks)): 19 | if marks[min_idx] > marks[j]: 20 | min_idx = j 21 | 22 | # Swap the minimum element with the first element 23 | marks[i], marks[min_idx] = marks[min_idx], marks[i] 24 | 25 | print("Marks of students after performing Selection Sort on the list : ") 26 | for i in range(len(marks)): 27 | print(marks[i]) 28 | 29 | #<---------------------------------------------------------------------------------------> 30 | 31 | # Function for Bubble Sort of elements 32 | 33 | def Bubble_Sort(marks): 34 | n = len(marks) 35 | # Traverse through all array elements 36 | for i in range(n - 1): 37 | # Last i elements are already in place 38 | for j in range(0, n - i - 1): 39 | 40 | # Traverse the array from 0 to n-i-1 41 | # Swap if the element found is greater than the next element 42 | if marks[j] > marks[j + 1]: 43 | marks[j], marks[j + 1] = marks[j + 1], marks[j] 44 | 45 | print("Marks of students after performing Bubble Sort on the list :") 46 | for i in range(len(marks)): 47 | print(marks[i]) 48 | 49 | #<---------------------------------------------------------------------------------------> 50 | 51 | # Function for displaying top five marks 52 | 53 | def top_five_marks(marks): 54 | print("Top",len(marks),"Marks are : ") 55 | print(*marks[::-1], sep="\n") 56 | 57 | #<----------------------------------------------------------------------------------------> 58 | 59 | # Main 60 | 61 | marks=[] 62 | n = int(input("Enter number of students whose marks are to be displayed : ")) 63 | print("Enter marks for",n,"students (Press ENTER after every students marks): ") 64 | for i in range(0, n): 65 | ele = int(input()) 66 | marks.append(ele) # adding the element 67 | 68 | print("The marks of",n,"students are : ") 69 | print(marks) 70 | 71 | flag=1; 72 | while flag==1: 73 | print("\n---------------MENU---------------") 74 | print("1. Selection Sort of the marks") 75 | print("2. Bubble Sort of the marks") 76 | print("3. Exit") 77 | ch=int(input("\n\nEnter your choice (from 1 to 3) : ")) 78 | 79 | if ch==1: 80 | Selection_Sort(marks) 81 | a=input("\nDo you want to display top marks from the list (yes/no) : ") 82 | if a=='yes': 83 | top_five_marks(marks) 84 | else: 85 | print("\nThanks for using this program!") 86 | flag=0 87 | 88 | elif ch==2: 89 | Bubble_Sort(marks) 90 | a = input("\nDo you want to display top five marks from the list (yes/no) : ") 91 | if a == 'yes': 92 | top_five_marks(marks) 93 | else: 94 | print("\nThanks for using this program!") 95 | flag = 0 96 | 97 | elif ch==3: 98 | print("\nThanks for using this program!!") 99 | flag=0 100 | 101 | else: 102 | print("\nEnter a valid choice!!") 103 | print("\nThanks for using this program!!") 104 | flag=0 105 | 106 | 107 | #<----------------------------------------END OF PROGRAM-------------------------------------------------> 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /GroupB_Practical16(python).py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | Experiment No. 16 : Write a python program to store first year percentage of students in array. 4 | Write function for sorting array of floating point numbers in ascending order using 5 | quick sort and display top five scores. 6 | ''' 7 | 8 | 9 | # Function for accepting the percentage of the Students 10 | 11 | def input_percentage(): 12 | perc = [] 13 | number_of_students = int(input("Enter the number of Students : ")) 14 | for i in range(number_of_students): 15 | perc.append(float(input("Enter the percentage of Student {0} : ".format(i+1)))) 16 | return perc 17 | 18 | #<---------------------------------------------------------------------------------------------------------------------> 19 | 20 | # Function for printing the percentage of the Students 21 | 22 | def print_percentage(perc): 23 | for i in range(len(perc)): 24 | print(perc[i],sep = "\n") 25 | 26 | #<---------------------------------------------------------------------------------------------------------------------> 27 | 28 | # Function for performing partition of the Data 29 | 30 | def percentage_partition(perc,start,end): 31 | pivot = perc[start] 32 | lower_bound = start + 1 33 | upper_bound = end 34 | 35 | while True: 36 | while lower_bound <= upper_bound and perc[lower_bound] <= pivot: 37 | lower_bound += 1 38 | 39 | while lower_bound <= upper_bound and perc[upper_bound] >= pivot: 40 | upper_bound -= 1 41 | 42 | if lower_bound <= upper_bound: 43 | perc[lower_bound],perc[upper_bound] = perc[upper_bound],perc[lower_bound] 44 | 45 | else: 46 | break 47 | 48 | 49 | perc[start],perc[upper_bound] = perc[upper_bound],perc[start] 50 | 51 | return upper_bound 52 | 53 | #<---------------------------------------------------------------------------------------------------------------------> 54 | 55 | # Function for performing Quick Sort on the Data 56 | 57 | def Quick_Sort(perc,start,end): 58 | while start < end: 59 | partition = percentage_partition(perc,start,end) 60 | Quick_Sort(perc,start,partition-1) 61 | Quick_Sort(perc,partition+1,end) 62 | return perc 63 | 64 | #<---------------------------------------------------------------------------------------------------------------------> 65 | 66 | # Function for Displaying Top Five Percentages of Students 67 | 68 | def display_top_five(perc): 69 | print("Top Five Percentages are : ") 70 | if len(perc) < 5: 71 | start, stop = len(perc) - 1, -1 72 | else: 73 | start, stop = len(perc) - 1, len(perc) - 6 74 | 75 | for i in range(start, stop, -1): 76 | print(perc[i],sep = "\n") 77 | 78 | 79 | #<---------------------------------------------------------------------------------------------------------------------> 80 | 81 | # Main 82 | 83 | unsorted_percentage = [] 84 | sorted_percentage = [] 85 | flag = 1 86 | 87 | while flag == 1: 88 | print("\n--------------------MENU--------------------") 89 | print("1. Accept the Percentage of Students") 90 | print("2. Display the Percentages of Students") 91 | print("3. Perform Quick Sort on the Data") 92 | print("4. Exit") 93 | 94 | ch = int(input("Enter your choice (from 1 to 4) : ")) 95 | 96 | if ch == 1: 97 | unsorted_percentage = input_percentage() 98 | 99 | elif ch == 2: 100 | print_percentage(unsorted_percentage) 101 | 102 | elif ch == 3: 103 | print("Percentages of Students after performing Quick Sort : ") 104 | sorted_percentage = Quick_Sort(unsorted_percentage,0,len(unsorted_percentage)-1) 105 | print_percentage(sorted_percentage) 106 | a = input("Do you want to display the Top 5 Percentages of Students (yes/no) : ") 107 | if a == 'yes': 108 | display_top_five(sorted_percentage) 109 | 110 | elif ch == 4: 111 | print("Thanks for using this program!!") 112 | flag = 0 113 | 114 | else: 115 | print("Invalid Choice!!") 116 | 117 | 118 | #<-----------------------------------------------END OF PROGRAM--------------------------------------------------------> 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /GroupC_Practical19(C++).cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Department of Computer Engineering has student's club named 5 | 'Pinnacle Club'. Students of Second, third and final year of 6 | department can be granted membership on request. Similarly one 7 | may cancel the membership of club. First node is reserved for 8 | president of club and last node is reserved for secretary of 9 | club. Write C++ program to maintain club member‘s information 10 | using singly linked list. Store student PRN and Name. Write 11 | functions to 12 | a) Add and delete the members as well as president or even 13 | secretary. 14 | b) Compute total number of members of club 15 | c) Display members 16 | d) Display list in reverse order using recursion 17 | e) Two linked lists exists for two divisions. Concatenate two 18 | lists 19 | */ 20 | 21 | # include 22 | # include 23 | # include 24 | using namespace std; 25 | class list; 26 | class node 27 | { 28 | int prn; 29 | string name; 30 | node *next; 31 | public: 32 | node(int 33 | x, string 34 | nm) 35 | { 36 | prn = x; 37 | next = NULL; 38 | name = nm; 39 | } 40 | friend 41 | 42 | class list; 43 | }; 44 | class list 45 | { 46 | node * start; 47 | public: 48 | list() 49 | { 50 | start = NULL; 51 | } 52 | void 53 | create(); 54 | void 55 | display(); 56 | void 57 | insertAtBeginning(); 58 | void 59 | insertAtEnd(); 60 | void 61 | insertAfter(); 62 | void 63 | deleteAtFirst(); 64 | void 65 | deleteByValue(); 66 | void 67 | deleteAtEnd(); 68 | int 69 | computeTotal(); 70 | void 71 | sortList(); 72 | void 73 | concatList(list & q1); 74 | void 75 | displayRev(node * t); 76 | bool 77 | reverseDisplay() // function is only 78 | for passing start as argument to recursive function 79 | { 80 | if (start == NULL) 81 | return false; 82 | node * temp = start; 83 | displayRev(temp); 84 | // cout << "(President)"; 85 | return true; 86 | } 87 | }; 88 | void 89 | 90 | list::displayRev(node * t) 91 | { 92 | if (t == NULL) 93 | return; 94 | else 95 | { 96 | displayRev(t->next); 97 | cout << "\nPRN NO:" << t->prn << " Name: " << t->name; 98 | } 99 | } 100 | void 101 | list::create() 102 | { 103 | int 104 | no; 105 | string 106 | nam; 107 | if (start == NULL) 108 | { 109 | cout << "Enter PRN number: "; 110 | cin >> no; 111 | cout << "Enter name: "; 112 | cin >> nam; 113 | cout << nam; 114 | start = new 115 | node(no, nam); 116 | cout << "\n=============== List Created ==============="; 117 | } 118 | else 119 | { 120 | cout << "\nList is already created."; 121 | } 122 | } 123 | void 124 | list::display() 125 | { 126 | node * t; 127 | t = start; 128 | if (start == NULL) 129 | cout << "\nList is Empty"; 130 | else 131 | {cout << "\n=============== List: ===============\n"; 132 | while (t != NULL){ 133 | cout << t->prn << " " << t->name << " \n"; 134 | t=t->next; 135 | } 136 | // cout << t->prn << " " << t->name << " \n"; 137 | } 138 | } 139 | void 140 | 141 | list::insertAtBeginning() 142 | { 143 | int 144 | no; 145 | string 146 | nam; 147 | node * temp; 148 | if (start == NULL) 149 | { 150 | create(); 151 | } 152 | else 153 | { 154 | cout << "\nEnter PRN Number : "; 155 | cin >> no; 156 | cout << "Enter Name : "; 157 | cin >> nam; 158 | // cout << nam; 159 | temp = new 160 | node(no, nam); 161 | temp->next = start; 162 | start = temp;; 163 | cout << "Inserted " << temp->name << " at the 164 | beginning."; 165 | } 166 | } 167 | void 168 | list::insertAtEnd() 169 | { 170 | int 171 | no; 172 | string 173 | nam; 174 | node * t; 175 | if (start == NULL) 176 | create(); 177 | else 178 | { 179 | cout << "\nEnter PRN Number : "; 180 | cin >> no; 181 | cout << "Enter Name : "; 182 | cin >> nam; 183 | t = start; 184 | while (t->next != NULL) 185 | t = t->next; 186 | node * p = new 187 | node(no, nam); 188 | t->next = p; 189 | } 190 | } 191 | 192 | void 193 | list::insertAfter() 194 | { 195 | int 196 | prev_no; 197 | cout << "\nEnter PRN No. after do you want insert : "; 198 | cin >> prev_no; 199 | node * t; 200 | t = start; 201 | string 202 | nam; 203 | int 204 | flag = 0, no; 205 | while (t != NULL) 206 | { 207 | if (t->prn == prev_no) 208 | { 209 | flag = 1; 210 | break; 211 | } 212 | t = t->next; 213 | } 214 | if (flag == 1) 215 | { 216 | node * p; 217 | cout << "\nEnter PRN Number : "; 218 | cin >> no; 219 | cout << "Enter Name : "; 220 | cin >> nam; 221 | p=new node(no, nam); 222 | p->next=t->next; 223 | t->next=p; 224 | } 225 | else 226 | { 227 | cout << "\n" << prev_no << " is not in list."; 228 | } 229 | } 230 | void list:: 231 | deleteAtFirst() 232 | { 233 | node * t; 234 | if (start == NULL) 235 | cout << "\nClub is Empty.."; 236 | else 237 | { 238 | t=start; 239 | start=start->next; 240 | t->next=NULL; // Not necessary 241 | 242 | delete t; 243 | cout << "\nPresident deleted.."; 244 | } 245 | } 246 | void list:: 247 | deleteByValue() 248 | { 249 | int 250 | no, flag = 0; 251 | node * t, *prev; 252 | if (start == NULL) 253 | cout << "\nList/Club is empty"; 254 | else 255 | { 256 | cout << "\nEnter PRN No. of member to be deleted : "; 257 | cin >> no; 258 | t=start->next; // t=start if we have to delete president also..start->next is first member 259 | while (t->next != NULL) 260 | { 261 | if (t->prn == no) 262 | { 263 | flag = 1; 264 | break; 265 | } 266 | prev = t; 267 | t = t->next; 268 | } 269 | if (flag == 1) 270 | { 271 | prev->next=t->next; 272 | t->next=NULL; 273 | delete t; 274 | cout << "\nMember with PRN No: " << no << " is deleted."; 275 | } 276 | else 277 | cout << "\nMember not found in List./President or Secretary cannot be deleted."; 278 | } 279 | } 280 | void list:: 281 | deleteAtEnd() 282 | { 283 | node * t, *prev; 284 | t = start; 285 | if (start == NULL) 286 | cout << "\nClub is Empty.."; 287 | else 288 | { 289 | 290 | while (t->next != NULL) 291 | { 292 | prev = t; 293 | t = t->next; 294 | } 295 | prev->next = NULL; 296 | delete 297 | t; 298 | cout << "\nSecretary Deleted."; 299 | } 300 | } 301 | int 302 | list::computeTotal() 303 | { 304 | node * t; 305 | int 306 | count = 0; 307 | t = start; 308 | if (start == NULL) 309 | { 310 | cout << "\nList is empty."; 311 | return 0; 312 | } 313 | while (t != NULL) 314 | { 315 | count + +; 316 | t = t->next; 317 | } 318 | return count; 319 | } 320 | void 321 | list::sortList() 322 | { 323 | node * i, *j, *last = NULL; 324 | int 325 | tprn; 326 | string 327 | tname; 328 | if (start == NULL) 329 | { 330 | cout << "\nList is empty."; 331 | return; 332 | } 333 | for (i=start;i->next != NULL;i=i->next) 334 | { 335 | for (j=start;j->next != last;j=j->next) 336 | { 337 | 338 | if ((j->prn) > (j->next->prn)) 339 | 340 | { 341 | tprn = j->prn; 342 | tname = j->name; 343 | j->prn = j->next->prn; 344 | j->name = j->next->name; 345 | j->next->prn = tprn; 346 | j->next->name = tname; 347 | } 348 | } 349 | } 350 | cout << "\n List is sorted."; 351 | 352 | display(); 353 | 354 | } 355 | void 356 | list::concatList(list & q1) 357 | { 358 | 359 | node * t, *p; 360 | t = q1.start; 361 | if (t == NULL) 362 | { 363 | 364 | cout << "\nList 2 is empty"; 365 | 366 | return; 367 | } 368 | p = start; // first 369 | list 370 | while (p->next != NULL) 371 | { 372 | p = p->next; 373 | } 374 | 375 | p->next = t; 376 | q1.start = NULL; // second 377 | list is set 378 | to 379 | null 380 | cout << "\nAfter concatenation list : \n"; 381 | 382 | display(); 383 | } 384 | int 385 | main() 386 | { 387 | list * l; 388 | int 389 | choice, selectList; 390 | list 391 | l1, l2; 392 | l = & l1; 393 | X: cout << "\nSelect List\n1.List 1\n2.List 2\nEnter choice : "; 394 | 395 | cin >> selectList; 396 | if (selectList == 1) 397 | { 398 | l = & l1; 399 | } 400 | else if (selectList == 2) 401 | { 402 | l = & l2; 403 | } 404 | else 405 | { 406 | 407 | cout << "\nWrong list Number."; 408 | goto 409 | X; 410 | } 411 | do 412 | { 413 | 414 | cout << "\n1. Create\n2. Insert President\n3. Insert secretary\n4. Insert after position(member)\n"; 415 | cout<<"5. Display list\n6. Delete President\n7.Delete Secretary\n8. Delete Member\n9. Find total No. of members\n10. Sort list\n11. Reselect List"; 416 | cout<< "\n12. Combine lists\n13.Reverse Display\n0. Exit\nEnter your choice :\t"; 417 | cin >> choice; 418 | switch(choice) 419 | 420 | { 421 | 422 | case 423 | 1: l->create(); 424 | break; 425 | case 426 | 2: l->insertAtBeginning(); 427 | 428 | break; 429 | case 430 | 3: l->insertAtEnd(); 431 | 432 | break; 433 | case 434 | 435 | 4: l->insertAfter(); 436 | break; 437 | case 438 | 5: l->display(); 439 | 440 | break; 441 | case 442 | 6: l->deleteAtFirst(); 443 | 444 | break; 445 | case 446 | 447 | 7: l->deleteAtEnd(); 448 | 449 | break; 450 | 451 | case 452 | 453 | 8: l->deleteByValue(); 454 | 455 | break; 456 | case 457 | 9: cout << "\nTotal members(including President & Secretary) : " << l->computeTotal(); 458 | break; 459 | case 460 | 10: l->sortList(); 461 | 462 | break; 463 | case 464 | 11: 465 | goto 466 | X; 467 | break; 468 | case 469 | 12: 470 | l1.concatList(l2); 471 | 472 | break; 473 | case 474 | 13: 475 | l->reverseDisplay(); 476 | break; 477 | deafult: 478 | cout << "Wrong choice"; 479 | } 480 | 481 | }while (choice != 0); 482 | cout << "\n=============== GOOD BYE ===============\n"; 483 | return 0; 484 | 485 | } 486 | 487 | -------------------------------------------------------------------------------- /GroupC_Practical20(C++).cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | The ticket booking system of Cinemax theater has to 5 | be implemented using C++ program. 6 | There are 10 rows and 7 seats in each row. Doubly 7 | circular linked list has to be maintained 8 | to keep track of free seats at rows. Assume some 9 | random booking to start with. Use array to store 10 | pointers (Head pointer) to each row. On demand 11 | a) The list of available seats is to be displayed 12 | b) The seats are to be booked 13 | c) The booking can be cancelled 14 | */ 15 | 16 | #include 17 | #include 18 | using namespace std; 19 | class node 20 | { public: 21 | node* next; 22 | node* prev; 23 | int seat; 24 | string id; 25 | int status; 26 | }; 27 | class cinemax 28 | { 29 | public: 30 | node* head,* tail ,* temp; 31 | cinemax() 32 | { 33 | head=NULL; 34 | } 35 | void create_list(); 36 | void display(); 37 | void book(); 38 | void cancel(); 39 | void avail(); 40 | 41 | }; 42 | void cinemax::create_list() 43 | { 44 | int i=1; 45 | temp=new node; 46 | temp->seat=1; 47 | temp->status=0; 48 | temp->id="null"; 49 | tail=head=temp; 50 | for(int i=2;i<=70;i++) 51 | { 52 | node *p; 53 | p= new node; 54 | p->seat=i; 55 | p->status=0; 56 | p->id="null"; 57 | tail->next=p; 58 | p->prev=tail; 59 | tail=p; 60 | tail->next=head; 61 | head->prev=tail; 62 | 63 | } 64 | } 65 | void cinemax::display() 66 | { 67 | { int r=1; 68 | node* temp; 69 | temp=head; 70 | int count=0; 71 | cout<<"\n------------------------------------------------------------------------------------\n"; 72 | cout<<" Screen 73 | this way \n"; 74 | cout<<"------------------------------------------------------------------------------------\n"; 75 | while(temp->next!=head) 76 | { 77 | if(temp->seat/10==0) 78 | cout<<"S0"<seat<<" :"; 79 | else 80 | cout<<"S"<seat<<" :"; 81 | 82 | if(temp->status==0) 83 | cout<<"|___| "; 84 | else 85 | cout<<"|_B_| "; 86 | count++; 87 | if(count%7==0) 88 | { 89 | cout<next; 93 | } 94 | cout<<"S"<seat<<" :"; 95 | if(temp->status==0) 96 | cout<<"|___| "; 97 | else 98 | cout<<"|_B_| "; 99 | } 100 | } 101 | void cinemax::book() 102 | { int x; 103 | string y; 104 | label: 105 | cout<<"\n\n\nEnter seat number to be booked\n"; 106 | cin>>x; 107 | cout<<"Enter your ID number\n"; 108 | cin>>y; 109 | if(x<1||x>70) 110 | { 111 | cout<<"Enter correct seat number to book (1-70)\n"; 112 | goto label; 113 | } 114 | node *temp; 115 | temp=new node; 116 | temp=head; 117 | while(temp->seat!=x) 118 | { 119 | temp=temp->next; 120 | } 121 | 122 | if(temp->status==1) 123 | cout<<"Seat already booked!\n"; 124 | else{ 125 | temp->status=1; 126 | temp->id=y; 127 | cout<<"Seat "<>x; 138 | cout<<"Enter you ID\n"; 139 | cin>>y; 140 | if(x<1||x>70) 141 | { 142 | cout<<"Enter correct seat number to cancel (1-70)\n"; 143 | goto label1; 144 | } 145 | node *temp; 146 | temp=new node; 147 | temp=head; 148 | while(temp->seat!=x) 149 | { 150 | temp=temp->next; 151 | } 152 | if(temp->status==0) 153 | { 154 | cout<<"Seat not booked yet!!\n"; 155 | } 156 | else 157 | { 158 | if(temp->id==y) 159 | { 160 | temp->status=0; 161 | cout<<"Seat Cancelled!\n"; 162 | } 163 | 164 | else 165 | cout<<"Wrong User ID !!! Seat cannot be cancelled!!!\n"; 166 | } 167 | } 168 | void cinemax::avail() 169 | { 170 | int r=1; 171 | node* temp; 172 | temp=head; 173 | int count=0; 174 | cout<<"\n\n\n\n"; 175 | cout<<"\n------------------------------------------------------------------------------------\n"; 176 | cout<<" Screen this way \n"; 177 | cout<<"------------------------------------------------------------------------------------\n"; 178 | while(temp->next!=head) 179 | { 180 | { 181 | if(temp->seat/10==0) 182 | cout<<"S0"<seat<<" :"; 183 | else 184 | cout<<"S"<seat<<" :"; 185 | if(temp->status==0) 186 | cout<<"|___| "; 187 | else if(temp->status==1) 188 | cout<<" "; 189 | 190 | count++; 191 | if(count%7==0) 192 | 193 | { 194 | 195 | cout<next; 201 | } 202 | if(temp->status==0) 203 | { 204 | cout<<"S"<seat<<" :"; 205 | 206 | if(temp->status==0) 207 | cout<<"|___| "; 208 | } 209 | 210 | } 211 | int main() 212 | { cinemax obj; 213 | obj.create_list(); 214 | int ch; 215 | char c='y'; 216 | while(c=='y') 217 | { obj.display(); 218 | cout<<"\n*********************************************\n"; 219 | cout<<" CINEMAX MOVIE THEATRE\n"; 220 | cout<<"*********************************************\n"; 221 | cout<<"\nEnter Choice\n1.Current SeatStatus\n2.Book Seat \n3.Available Seat\n4.CancelSeat\n"; 222 | cin>>ch; 223 | switch(ch) 224 | { 225 | case 1:obj.display(); 226 | break; 227 | case 2: obj.book(); 228 | break; 229 | case 3:obj.avail(); 230 | break; 231 | case 4: obj.cancel(); 232 | break; 233 | default: cout<<"Wrong choice input\n"; 234 | } 235 | cout<<"\nDo you want to perform any other operation : (y/n)\n"; 236 | cin>>c; 237 | } 238 | return 0; 239 | } 240 | 241 | 242 | 243 | -------------------------------------------------------------------------------- /GroupD_Practical25(C++).cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | 5 | A palindrome is a string of character that‘s the same forward and backward. Typically, punctuation, capitalization, 6 | and spaces are ignored. For example, “Poor Dan is in a droop” is a palindrome, as can be seen by examining the characters 7 | “poor danisina droop” and observing that they are the same forward and backward. One way to check for a palindrome is to reverse 8 | the characters in the string and then compare with them the original-in a palindrome, the sequence will be identical. Write C++ program 9 | with functions- 10 | a) To print original string followed by reversed string using stack 11 | b) To check whether given string is palindrome or not 12 | 13 | */ 14 | 15 | #include 16 | #include 17 | #define max 50 18 | using namespace std; 19 | 20 | class STACK 21 | { 22 | private: 23 | char a[max]; 24 | int top; 25 | 26 | public: 27 | STACK() 28 | { 29 | top=-1; 30 | } 31 | 32 | void push(char); 33 | void reverse(); 34 | void convert(char[]); 35 | void palindrome(); 36 | }; 37 | 38 | void STACK::push(char c) 39 | { 40 | top++; 41 | a[top] = c; 42 | a[top+1]='\0'; 43 | 44 | cout<=0; i--,j++) 54 | { 55 | cout<= 97 && (int)str[j] <=122 ) || ( (int)str[j] >= 65 && (int)str[j] <=90 )) 70 | { 71 | if( (int)str[j] <=90 ) 72 | { 73 | str[k] = (char)( (int)str[j] + 32 ); 74 | }else 75 | { 76 | str[k] = str[j]; 77 | } 78 | 79 | k++; 80 | } 81 | } 82 | str[k]='\0'; 83 | 84 | cout<=0; i--,j++) 96 | { 97 | str[j]=a[i]; 98 | } 99 | str[j]='\0'; 100 | 101 | 102 | if(strcmp(str,a) == 0) 103 | cout<<"\n\nString is palindrome..."; 104 | else 105 | cout<<"\n\nString is not palindrome..."; 106 | } 107 | 108 | 109 | int main() 110 | { 111 | STACK stack; 112 | 113 | char str[max]; 114 | int i=0; 115 | 116 | cout<<"\nEnter string to be reversed and check is it palindrome or not : \n\n"; 117 | 118 | cin.getline(str , 50); 119 | 120 | stack.convert(str); 121 | 122 | while(str[i] != '\0') 123 | { 124 | stack.push(str[i]); 125 | i++; 126 | } 127 | 128 | stack.palindrome(); 129 | 130 | stack.reverse(); 131 | 132 | } 133 | 134 | 135 | -------------------------------------------------------------------------------- /GroupD_Practical26(C++).cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | 4 | In any language program mostly syntax error occurs due to unbalancing delimiter such as 5 | (),{},[]. Write C++ program using stack to check whether given expression is well parenthesized or not. 6 | */ 7 | 8 | 9 | #include 10 | using namespace std; 11 | #define size 10 12 | 13 | class stackexp 14 | { 15 | int top; 16 | char stk[size]; 17 | public: 18 | stackexp() 19 | { 20 | top=-1; 21 | } 22 | void push(char); 23 | char pop(); 24 | int isfull(); 25 | int isempty(); 26 | }; 27 | 28 | void stackexp::push(char x) 29 | { 30 | top=top+1; 31 | stk[top]=x; 32 | } 33 | 34 | char stackexp::pop() 35 | { 36 | char s; 37 | s=stk[top]; 38 | top=top-1; 39 | return s; 40 | } 41 | 42 | int stackexp::isfull() 43 | { 44 | if(top==size) 45 | return 1; 46 | else 47 | return 0; 48 | } 49 | 50 | int stackexp::isempty() 51 | { 52 | if(top==-1) 53 | return 1; 54 | else 55 | return 0; 56 | } 57 | 58 | int main() 59 | { 60 | stackexp s1; 61 | char exp[20],ch; 62 | int i=0; 63 | cout << "\n\t!! Parenthesis Checker..!!!!" << endl; // prints !!!Hello World!!! 64 | cout<<"\nEnter the expression to check whether it is in well form or not : "; 65 | cin>>exp; 66 | if((exp[0]==')')||(exp[0]==']')||(exp[0]=='}')) 67 | { 68 | cout<<"\n Invalid Expression.....\n"; 69 | return 0; 70 | } 71 | else 72 | { 73 | while(exp[i]!='\0') 74 | { 75 | ch=exp[i]; 76 | switch(ch) 77 | { 78 | case '(':s1.push(ch);break; 79 | case '[':s1.push(ch);break; 80 | case '{':s1.push(ch);break; 81 | case ')':s1.pop();break; 82 | case ']':s1.pop();break; 83 | case '}':s1.pop();break; 84 | } 85 | i=i+1; 86 | } 87 | } 88 | if(s1.isempty()) 89 | { 90 | cout<<"\nExpression is well parenthesised...\n"; 91 | } 92 | else 93 | { 94 | cout<<"\nSorry !!! Invalid Expression or not in well parenthesized....\n"; 95 | } 96 | return 0; 97 | } 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /GroupE_Practical29(C++).cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Queues are frequently used in computer programming, and a typical example is the creation of a job queue by an operating system. 3 | If the operating system does not use priorities, then the jobs are processed in the order they enter the system. 4 | Write C++ program for simulating job queue. Write functions to add job and delete job from queue. 5 | */ 6 | 7 | #include 8 | #define MAX 10 9 | using namespace std; 10 | struct queue 11 | { int data[MAX]; 12 | int front,rear; 13 | }; 14 | class Queue 15 | { struct queue q; 16 | public: 17 | Queue(){q.front=q.rear=-1;} 18 | int isempty(); 19 | int isfull(); 20 | void enqueue(int); 21 | int delqueue(); 22 | void display(); 23 | }; 24 | int Queue::isempty() 25 | { 26 | return(q.front==q.rear)?1:0; 27 | } 28 | int Queue::isfull() 29 | { return(q.rear==MAX-1)?1:0;} 30 | void Queue::enqueue(int x) 31 | {q.data[++q.rear]=x;} 32 | int Queue::delqueue() 33 | {return q.data[++q.front];} 34 | void Queue::display() 35 | { int i; 36 | cout<<"\n"; 37 | for(i=q.front+1;i<=q.rear;i++) 38 | cout<>ch; 45 | switch(ch) 46 | { case 1: if (!obj.isfull()) 47 | { cout<<"\n Enter data : \n"; 48 | cin>>x; 49 | obj.enqueue(x); 50 | cout< 8 | #include 9 | #define MAX 10 10 | using namespace std; 11 | 12 | struct que 13 | { 14 | int arr[MAX]; 15 | int front,rear; 16 | }; 17 | 18 | void init(struct que *q) 19 | { 20 | q->front=-1; 21 | q->rear=-1; 22 | } 23 | 24 | void print(struct que q) 25 | { 26 | int i; 27 | i=q.front; 28 | while(i!=q.rear) 29 | { 30 | cout<<"\t"<front=q->rear=0; 51 | q->arr[q->front]=data; 52 | } 53 | else 54 | { 55 | q->front=(q->front-1+MAX)%MAX; 56 | q->arr[q->front]=data; 57 | } 58 | } 59 | 60 | void addr(struct que *q,int data) 61 | { 62 | if(isempty(*q)) 63 | { 64 | q->front=q->rear=0; 65 | q->arr[q->rear]=data; 66 | } 67 | else 68 | { 69 | q->rear=(q->rear+1)%MAX; 70 | q->arr[q->rear]=data; 71 | } 72 | } 73 | 74 | int delf(struct que *q) 75 | { 76 | int data1; 77 | data1=q->arr[q->front]; 78 | if(q->front==q->rear) 79 | init(q); 80 | else 81 | q->front=(q->front+1)%MAX; 82 | return data1; 83 | } 84 | 85 | int delr(struct que *q) 86 | { 87 | int data1; 88 | data1=q->arr[q->rear]; 89 | if(q->front==q->rear) 90 | init(q); 91 | else 92 | q->rear=(q->rear-1+MAX)%MAX; 93 | return data1; 94 | } 95 | 96 | int main() 97 | { 98 | struct que q; 99 | int data,ch; 100 | init(&q); 101 | while(ch!=6) 102 | { 103 | cout<<"\t\n1.Insert front" 104 | "\t\n2.Insert rear" 105 | "\t\n3.Delete front" 106 | "\t\n4.Delete rear" 107 | "\t\n5.Print" 108 | "\t\n6.Exit"; 109 | cout<<"\nEnter your choice : "; 110 | cin>>ch; 111 | switch(ch) 112 | { 113 | case 1: 114 | cout<<"\nEnter data to insert front : "; 115 | cin>>data; 116 | addf(&q,data); 117 | break; 118 | 119 | case 2: 120 | cout<<"\nEnter the data to insert rear : "; 121 | cin>>data; 122 | addr(&q,data); 123 | break; 124 | 125 | case 3: 126 | if(isempty(q)) 127 | cout<<"\nDequeue is empty!!!"; 128 | else 129 | { 130 | data=delf(&q); 131 | cout<<"\nDeleted data is : "< 8 | #include 9 | using namespace std; 10 | class pizza 11 | { 12 | int front,rear,q[5]; 13 | public: 14 | pizza() 15 | { 16 | front=-1; 17 | rear=-1; 18 | } 19 | int isfull() 20 | { 21 | 22 | if((front==0&&rear==4)||front==rear+1) 23 | { 24 | return 1; 25 | } 26 | else 27 | { 28 | return 0; 29 | } 30 | } 31 | int isempty() 32 | { 33 | if(front==-1&&rear==-1) 34 | { 35 | return 1; 36 | } 37 | else 38 | { 39 | return 0; 40 | } 41 | } 42 | void add() 43 | { 44 | if(isfull()==0) 45 | { 46 | cout<<"\n Enter the Pizza ID: "; 47 | if(front==-1&&rear==-1) 48 | { 49 | front=0; 50 | rear=0; 51 | cin>>q[rear]; 52 | } 53 | else 54 | { 55 | rear=(rear+1)%5; 56 | cin>>q[rear]; 57 | } 58 | char c; 59 | cout<<" Do you want to add another order ? "; 60 | cin>>c; 61 | if(c=='y'||c=='Y') 62 | add(); 63 | } 64 | else 65 | { 66 | cout<<"\n Orders are full "; 67 | } 68 | 69 | } 70 | void serve() 71 | { 72 | if(isempty()==0) 73 | { 74 | if(front==rear) 75 | { 76 | cout<<"\n Order served is : "<>ch; 114 | switch(ch) 115 | { 116 | case 1: 117 | add(); 118 | break; 119 | 120 | case 2: 121 | 122 | display(); 123 | break; 124 | 125 | case 3: 126 | 127 | serve(); 128 | break; 129 | 130 | case 4: 131 | 132 | exit(0); 133 | 134 | default: 135 | cout<<"Invalid choice "; 136 | 137 | check(); 138 | } 139 | char ch1; 140 | cout<<"\n Do you want to continue? "; 141 | cin>>ch1; 142 | if(ch1=='y'||ch1=='Y') 143 | check(); 144 | } 145 | }; 146 | int main() 147 | { 148 | pizza p1; 149 | p1.check(); 150 | return 0; 151 | } 152 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SPPU-2019-Pattern-SE-COMP-Fundamentals-of-Data-Structures-Practicals 2 | 3 | GroupA_Practical1(python) : 4 | Experiment No. 1 : In a second year computer engineering class, group A students play cricket, group B students play 5 | badminton and group C students play football. 6 | Write a python program using functions to compute following: 7 | a) List of students who play both cricket and badminton. 8 | b) List of students who play either cricket or badminton but not both. 9 | c) Number of students who play neither cricket nor badminton. 10 | d) Number of students who play cricket and football but not badminton. 11 | (NOTE : While realising the group, duplicate entries should be avoided. Do not use SET built-in functions) 12 | 13 | 14 | 15 | GroupA_Practical2(python) : 16 | Experiment Number 2 : Write a python program to store marks stored in subject "Fundamentals of Data Structure" by 17 | N students in the class. Write functions to compute following: 18 | 1. The average score of the class. 19 | 2. Highest score and lowest score of the class. 20 | 3. Count of students who were absent for the test. 21 | 4. Display mark with highest frequency. 22 | 23 | 24 | 25 | GroupA_Practical7(python) : 26 | Experiment No. 7 : Write a python program for MAGIC SQUARE. 27 | A magic square is an n*n matrix of the integers 1 to (n^2) such that the sum of each row, 28 | column and diagonalis the same. 29 | The figure given below is an example of the magic square for case n=5. In this example 30 | the common sum is 65. 31 | 32 | 9 | 3 | 22 | 16 | 15 | 33 | 2 | 21 | 20 | 14 | 8 | 34 | 25 | 19 | 13 | 7 | 1 | 35 | 18 | 12 | 6 | 5 | 24 | 36 | 11 | 10 | 4 | 23 | 17 | 37 | 38 | Conditions for placing the values in the matrix in appropriate manner (CIRCULAR ARRAY) : 39 | 40 | 1. The position of next number is calculated by decrementing row number of previous number by 1, and incrementing 41 | the column number of previous number by 1. At any time, if the calculated row position becomes -1, it will wrap 42 | around to n-1. Similarly, if the calculated column position becomes n, it will wrap around to 0. 43 | 44 | 2. If the magic square already contains a number at the calculated position, calculated column position will be 45 | decremented by 2, and calculated row position will be incremented by 1. 46 | 47 | 3. If the calculated row position is -1 & calculated column position is n, the new position would be: (0, n-2). 48 | 49 | 50 | 51 | GroupB_Practical13(python) : 52 | Experiment No. 13 : Write a python program to maintain club members, sort on roll numbers in ascending order. 53 | Write function “Ternary_Search” to search whether particular student is member of club or not. 54 | Ternary search is modified binary search that divides array into 3 halves instead of two. 55 | 56 | 57 | 58 | GroupB_Practical14(python) : 59 | Experiment Number 14: Write a python program to store first year percentage of students in an array. 60 | Write function for sorting array of floating point numbers in ascending order using: 61 | a) Selection Sort 62 | b) Bubble Sort and display top five scores 63 | 64 | 65 | 66 | GroupB_Practical16(python) : 67 | Experiment No. 16 : Write a python program to store first year percentage of students in array. 68 | Write function for sorting array of floating point numbers in ascending order using 69 | quick sort and display top five scores. 70 | 71 | 72 | GroupC_Practical19(C++) : 73 | Experiment No. 19 : Department of Computer Engineering has student's club named 74 | 'Pinnacle Club'. Students of Second, third and final year of 75 | department can be granted membership on request. Similarly one 76 | may cancel the membership of club. First node is reserved for 77 | president of club and last node is reserved for secretary of 78 | club. Write C++ program to maintain club member‘s information 79 | using singly linked list. Store student PRN and Name. Write 80 | functions to 81 | a) Add and delete the members as well as president or even 82 | secretary. 83 | b) Compute total number of members of club 84 | c) Display members 85 | d) Display list in reverse order using recursion 86 | e) Two linked lists exists for two divisions. Concatenate two 87 | lists 88 | 89 | 90 | GroupC_Practical20(C++) : 91 | Experiment No. 20 : The ticket booking system of Cinemax theater has to 92 | be implemented using C++ program. 93 | There are 10 rows and 7 seats in each row. Doubly 94 | circular linked list has to be maintained 95 | to keep track of free seats at rows. Assume some 96 | random booking to start with. Use array to store 97 | pointers (Head pointer) to each row. On demand 98 | a) The list of available seats is to be displayed 99 | b) The seats are to be booked 100 | c) The booking can be cancelled 101 | 102 | 103 | GroupD_Practical25(C++) : 104 | Experiment No. 25 : A palindrome is a string of character that‘s the same forward and backward. 105 | Typically, punctuation, capitalization, and spaces are ignored. For example, “Poor Dan is in a droop” is a palindrome, 106 | as can be seen by examining the characters “poor danisina droop” and observing that they are the same forward and backward. 107 | One way to check for a palindrome is to reverse the characters in the string and then compare with them the original-in a 108 | palindrome, the sequence will be identical. Write C++ program with functions- 109 | a) To print original string followed by reversed string using stack 110 | b) To check whether given string is palindrome or not 111 | 112 | 113 | GroupD_Practical26(C++) : 114 | Experiment No. 26 : In any language program mostly syntax error occurs due to unbalancing delimiter such as (),{},[]. 115 | Write C++ program using stack to check whether given expression is well parenthesized or not. 116 | 117 | 118 | GroupE_Practical29(C++) : 119 | Experiment No. 29 : Queues are frequently used in computer programming, and a typical example is the creation of a job queue by an operating system. 120 | If the operating system does not use priorities, then the jobs are processed in the order they enter the system. 121 | Write C++ program for simulating job queue. Write functions to add job and delete job from queue. 122 | 123 | 124 | GroupE_Practical31(C++) : 125 | Experiment No. 31 : A double-ended queue (deque) is a linear list in which additions and deletions may be made at either end. Obtain a data 126 | representation mapping a deque into a one-dimensional array. Write C++ program to simulate deque with functions to add 127 | and delete elements from either end of the deque. 128 | 129 | 130 | GroupE_Practical32(C++) : 131 | Experiment No. 32 : Pizza parlor accepting maximum M orders. 132 | Orders are served in first come first served basis. Order once placed can not be cancelled. 133 | Write C++ program to simulate the system using circular queue using array. 134 | 135 | --------------------------------------------------------------------------------