0% found this document useful (0 votes)
48 views78 pages

Data 1 To 8 Lab

This document appears to be a student workbook for a lab on programming in C++. It includes 3 programs with observations and results for each. It also includes 4 questions for the student to answer about interpreting programs, writing programs to solve engineering problems, designing software to meet requirements, and functioning as a group in the lab. The student is asked to describe what they learned from the experiment.

Uploaded by

Mudassar Virk
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)
48 views78 pages

Data 1 To 8 Lab

This document appears to be a student workbook for a lab on programming in C++. It includes 3 programs with observations and results for each. It also includes 4 questions for the student to answer about interpreting programs, writing programs to solve engineering problems, designing software to meet requirements, and functioning as a group in the lab. The student is asked to describe what they learned from the experiment.

Uploaded by

Mudassar Virk
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/ 78

Student Workbook

DATA STRUCTURE

Name: _________________
Reg. No.: _______________

Section: ________________

Revised By:
Faraz Hasan Khan

Department of Electrical Engineering


The University of Lahore, Lahore,
Pakistan 1-KM Raiwind Road, Lahore.

1
Lab # 1

TITLE: REVISION OF PROGRAMMING IN C++

Equipment:

________________________________________________________________________________

Pre-Lab Preparation:

________________________________________________________________________________

Procedure

2
Observation and Results

1. Develop a program that does the following and analyze output:

 Prompts the user to input five decimal numbers.



 Prints the five decimal numbers.

 Converts each decimal number to the nearest integer.

 Adds the five integers.

#include<iostream>
using namespace std;
int main(){
int array[5];
int sum=0;
for(int i=0;i<5;i++){
cout<<"please enter "<<i+1<<" mumber";
cin>>a[i];
}
for(int i=0;i<5;i++){
cout<<array[i]<<" ";
}
for(int i=0; i<5;i++){
sum=array[i]+sum;
}
cout<<endl<<"sum of all num is="<<sum;
}

3
2. Develop a program that prompts the capacity, in gallons, of an automobile fuel tank and the miles per gallons
the automobile can be driven. The program outputs the number of miles the automobile can be driven
without refueling. Analyze the output of the complete program.

#include <iostream>
using namespace std;
int main()
{
int milesPerGal, tankCap;
cout << "here enter the capacity of the tank: ";
cin >> tankCap;

cout << "here enter the miles per gallons: ";


cin >> milesPer;

cout << "This mean that you can drive " << tankCap * milesPerGel << " miles on a full tank."
<< endl;

return 0;
}

4
3. Develop a C++ program that prompts the user to input the elapsed time for an event in seconds. The program
then outputs the elapsed time in hours, minutes, and seconds. Analyze the output and compare the elapsed
time. (For example, if the elapsed time is 9630 seconds, then the output is 2:40:30.)

#include<iostream>
using namespace std;
int main(){
int t,s=0,h=0,m=0;
cout<<"please enter time in second";
cin>>t;
h=t/3600;
t=ti%3600;
m=t/60;
t=t%60;
s=t;
cout<<"The time in HH:MM:SS format is: "<<h<<":"
<<m<<":"<<s<<" seconds";

Question 1: Are you able to interpret programs given in the lab?

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

5
Question 2: Are you able to identify, formulate and write programs for electrical
engineering problems based on the techniques used in the lab?

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________
Question 3: Can you design an application/ software to fulfill certain
programming requirements?

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

Question 4: Were you able to function as a group in the lab?

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

Learning Outcomes

 What have you learnt from this experiment?



_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

6
GENERALIZED LAB RUBRICS

Component with Above Meeting Approaching Below Weight / Score


Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
Is able to build a
Is able to
given setup neatly
Psychomot

assemble a Is only able to Is not able to


and timely using
or

adapt to new /

given setup copy a given assemble a


Building correct hardware
using correct setup using given setup
(Hardware) components and / hardware correct using correct ☐
P4 or can reorganize / components hardware hardware
after minor components components
special
revisions
requirements
Is only able to
Recording
Is able to record Is able to record record Is unable to
Measurements
accurate accurate accurate record
(Hardware / ☐
measurements all measurements measurements accurate
Software)
the time most of the time on some measurements
C3
occasions
Is able to
Is partially
formulate /develop
Is able to able to
theories in
evaluate evaluate
Investigation addition to Is unable to
/conclude /conclude
(Hardware / evaluating comprehend
correctly about correctly ☐
Software) /concluding investigation
investigation about
C5 correctly about parameters
parameters by investigation
investigation
assessing data parameters by
parameters by
assessing data
assessing data
Is able to Is unable to
Design /
Development of Is able to design / Is able to design partially partially
develop the design / design /
Solution / develop the

Cogniti

solution of a given develop the develop the


ve

(Hardware / solution of a problem problem

problem and add solution of a solution of a


Software) given problem
features to it given given
C6
Is able to use
Is able to use
the software
Is adept in the use the software
Software Usage tool but Is unable to
of software tool tool effectively
(Software) and can access by accessing all cannot access use the ☐
C3 advanced features the required all the software tool
required
features
features
Is able to
efficiently
Is able to
complete a given
complete a
task using
given task using
Programming advanced Is able to Is unable to
required
Language programming partially partially
programming ☐
(Software) language complete a complete a
language
C3–C6 constructs / given task given task
constructs /
methods /
methods /
commands and/or
commands
add features to the
original task

7
Component with Above Meeting Approaching Below Weight / Score
Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
Complies Complies
Complies with
Safety Instructions Complies with all with some with very few
most EHS
(PLO6) EHS instructions EHS EHS ☐
instructions
A2 while in lab instructions instructions
while in lab
while in lab while in lab
Makes an
Does not
effort to
Exhibits Exhibits exhibit
exhibit
exemplary professional professional
professional
professional ethics ethics while ethics while
Professional Ethics while dealing with dealing with ethics while dealing with
(PLO8) ☐
fellow students, fellow students, dealing with fellow
A3 fellow
lab staff and lab staff and students, lab
students, lab
instructor all the instructor all staff and
staff and
time the time instructor all
instructor all
the time
the time
Shows some
Consistently
preparation
shows full Consistently
which is Shows very
preparation by shows full
mostly at little or no
completing all preparation by
Contribution superficial preparation in
agreed tasks and completing all
(PLO9) level in completing a ☐
provides agreed tasks
A5 completing a task and work
additional and work
task and work quality is
resources for the requires little or requires much poor
group and work no revisions
revisions and
quality is excellent
editing
Affective

Neither
Consistent helpful nor
Internalized positive damaging and Discouraging
Attitude positive behavior behavior
behavior most shows
(PLO9) and encourages towards other ☐
of the time disinterest in
A5 and helps other team
towards other the
team members members
team members performance
of others
Report on all
relevant
Report on all
sections
relevant
related to the
Report on all sections related
lab tasks is
relevant sections to the lab tasks completed but
related to the lab is completed Report on all
many
tasks is completed but few relevant
Report Writing deficiencies
(PLO10) accurately, deficiencies are are present in sections ☐
meeting the present in terms related to the
A2 terms of
requirements, in of accuracy / lab tasks is
accuracy /
prescribed time meeting the not completed
meeting the
and with good requirements /
language skills prescribed time requirements /
/ good language prescribed
time / good
skills
language
skills
Does not
Lab Task Completes
Completes tasks Completes tasks complete
Management tasks in an
well within given within given tasks even in ☐
(PLO11) extended
timeframe timeframe extended
A3 timeframe
timeframes
8
Lab # 2

TITLE: ARRAYS IN C++

Equipment:

________________________________________________________________________________

Pre-Lab Preparation:

________________________________________________________________________________

Procedure

9
Observation and Results

1. Develop the C++ statement that dynamically creates an array of 10 components of type int/float and num
contains the base address of the array. Point out the differences between data types.

#include <iostream>
using namespace std;
int main(){
int num[10];float num1[10];
int i,j;
for ( i = 0; i<2; i++ )
{
cout << "Enter value of n[" << i << "]"<< endl;
cin >> num[i];
}
for ( i = 0; i<2; i++ )
{
cout << "Enter value of n[" << i << "]"<< endl;
cin >> num1[i];
}
for (j = 0; j < 2; j++ )
{
cout << "n[" << j << "] = " << num[j] << endl;
}
for (j = 0; j < 2; j++ )
{
cout << "n[" << j << "] = " << num1[j] << endl;
}
return 0;
}
2. Develop a C++ code that inputs data into the array num from the standard input device and analyze the
input.

#include <iostream>
using namespace std;
int main(){
int num[10];float num1[10];
int i,j;
for ( i = 0; i<3; i++ )
{
cout << "Enter value of n[" << i << "]"<< endl;
cin >> num[i];
}
for (j = 0; j < 3; j++ )
{
num[j]= num[j]+5;
}
for (j = 0; j < 3; j++ )
{
cout << "n[" << j << "] = " << num[j] << endl;
}
return 0;
}
Learning Outcomes

 What have you learnt from this experiment?




_____________________________________________________________________________________


_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

z
Lab # 3

TITLE: SEARCHING (LINEAR,BINARY)


Equipment:

________________________________________________________________________________

Pre-Lab Preparation:

________________________________________________________________________________

Procedure
Observation and Results

1. Develop linear search on an Integer array and compare it with the outcome of above experiment.

#include<iostream>
using namespace std;
int main()
{
int a[20],n,x,i,flag=0;
cout<<"How many elements?";
cin>>n;
cout<<"\nEnter elements of the array\n";
for(i=0;i<n;++i)
cin>>a[i];
cout<<"\nEnter element to search:";
cin>>x;
for(i=0;i<n;++i)
{
if(a[i]==x)
{
flag=1;
break;
}
}
if(flag)
cout<<"\nElement is found at position "<<i+1;
else
cout<<"\nElement not found";
return 0;

}
2. Develop an algorithm which acts better than Binary Search and compare the outputs
#include<bits/stdc++.h>
using namespace std;
int interpolationSearch(int arr[], int n, int x)
{
int lo = 0, hi = (n - 1);
while (lo <= hi && x >= arr[lo] && x <= arr[hi])
{
if (lo == hi)
{
if (arr[lo] == x) return lo;
return -1;
}
int pos = lo + (((double)(hi - lo) /
(arr[hi] - arr[lo])) * (x - arr[lo]));
if (arr[pos] == x)
return pos;
if (arr[pos] < x)
lo = pos + 1;
else
hi = pos - 1;
}
return -1;
}
int main()
{
int arr[] = {10, 12, 13, 16, 18, 19, 20, 21,
22, 23, 24, 33, 35, 42, 47};
int n = sizeof(arr)/sizeof(arr[0]);
int x = 35;
int index = interpolationSearch(arr, n, x);
if (index != -1)
cout << "Element found at index " << index;
else
cout << "Element not found.";
return 0;
}
Learning Outcomes

 What have you learnt from this experiment?

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________
GENERALIZED LAB RUBRICS

Component with Above Meeting Approaching Below Weight / Score


Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
Is able to build a
Is able to
given setup neatly
assemble a Is only able to Is not able to
and timely using
tor

adapt to new /

given setup copy a given assemble a


Building correct hardware
using correct setup using given setup
(Hardware) components and / hardware correct using correct ☐
P4 or can reorganize / components hardware hardware
after minor components components
special
revisions
requirements
Is only able to
Recording
Is able to record Is able to record record Is unable to
Measurements
accurate accurate accurate record
(Hardware / ☐
measurements all measurements measurements accurate
Software)
the time most of the time on some measurements
C3
occasions
Is able to
Is partially
formulate /develop
Is able to able to
theories in
evaluate evaluate
Investigation addition to Is unable to
/conclude /conclude
(Hardware / evaluating comprehend
correctly about correctly ☐
Software) /concluding investigation
investigation about
C5 correctly about parameters
parameters by investigation
investigation
assessing data parameters by
parameters by
assessing data
assessing data
Is able to Is unable to
Design /
Development of Is able to design / Is able to design partially partially
develop the design / design /
Solution / develop the

Cogniti

solution of a given develop the develop the


ve

(Hardware / solution of a problem problem

problem and add solution of a solution of a


Software) given problem
features to it given given
C6
Is able to use
Is able to use
the software
Is adept in the use the software
Software Usage tool but Is unable to
of software tool tool effectively
(Software) and can access by accessing all cannot access use the ☐
C3 advanced features the required all the software tool
required
features
features
Is able to
efficiently
Is able to
complete a given
complete a
task using
given task using
Programming advanced Is able to Is unable to
required
Language programming partially partially
programming ☐
(Software) language complete a complete a
language
C3–C6 constructs / given task given task
constructs /
methods /
methods /
commands and/or
commands
add features to the
original task

20
Component with Above Meeting Approaching Below Weight / Score
Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
Complies Complies
Complies with
Safety Instructions Complies with all with some with very few
most EHS
(PLO6) EHS instructions EHS EHS ☐
instructions
A2 while in lab instructions instructions
while in lab
while in lab while in lab
Makes an
Does not
effort to
Exhibits Exhibits exhibit
exhibit
exemplary professional professional
professional
professional ethics ethics while ethics while
Professional Ethics while dealing with dealing with ethics while dealing with
(PLO8) ☐
fellow students, fellow students, dealing with fellow
A3 fellow
lab staff and lab staff and students, lab
students, lab
instructor all the instructor all the staff and
staff and
time time instructor all
instructor all
the time
the time
Shows some
Consistently
preparation
shows full Consistently
which is
preparation by shows full Shows very
mostly at
completing all preparation by little or no
Contribution superficial
(PLO9) agreed tasks and completing all level in preparation in ☐
provides agreed tasks completing a
A5 completing a
additional and work task and work task and work
resources for the requires little or requires much quality is poor
group and work no revisions
revisions and
quality is excellent
editing
Affective

Neither
Consistent helpful nor
Internalized positive damaging and Discouraging
Attitude positive behavior behavior
behavior most shows
(PLO9) and encourages towards other ☐
of the time disinterest in
A5 and helps other team
towards other the
team members members
team members performance
of others
Report on all
relevant
Report on all
sections
relevant
related to the
Report on all sections related
lab tasks is
relevant sections to the lab tasks
related to the lab is completed completed but Report on all
many
tasks is completed but few relevant
Report Writing deficiencies
accurately, deficiencies are sections
(PLO10) meeting the present in terms are present in related to the ☐
A2 requirements, in of accuracy / terms of lab tasks is
accuracy /
prescribed time meeting the not completed
meeting the
and with good requirements /
language skills prescribed time requirements /
/ good language prescribed
time / good
skills
language
skills
Does not
Lab Task Completes
Completes tasks Completes tasks complete
Management tasks in an
well within given within given tasks even in ☐
(PLO11) extended
timeframe timeframe extended
A3 timeframe
timeframes

21
Lab # 4

TITLE: SORTING (BUBBLE , INSERTION , SELECTION )

Equipment:

________________________________________________________________________________

Pre-Lab Preparation:

________________________________________________________________________________

Procedure

22
Observation and Results

1. Develop a program to take input of 10 integers from user. Implement Bubble Sort Algorithm on this array in
ascending order and descending order and analyze the outputs.
#include<iostream>
using namespace std;
int main()
{
int length,temp;
cout<<"Enter size= ";
cin>>length;
int arr[length];
for(int i=0;i<length;i++)
{
cin>>arr[i];
}
for (int i = 0; i < length; i++)
{
for(int j=0;j<length-1;j++)
{
if(arr[j]>arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
for(int i=0;i<length;i++)
{
cout<<arr[i]<<" ";
}
for (int i = 0; i < length; i++)
{
for(int j=0;j<length-1;j++)
{
if(arr[j]<arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
cout<<endl;
for(int i=0;i<length;i++)
{
23
cout<<arr[i]<<" ";
}
}

2. Develop a program to take input of 10 integers from user. Implement Selection Sort Algorithm on this array in
ascending order and descending order and analyze the outputs.

#include<iostream>
using namespace std;
int main(){
int a[10];
int b,c,j;
for(int i=0; i<10; i++){
cout<<"enter number "<<i<<":";
cin>>a[i];
}
for(int i=0; i<4; i++){
for( j=0; j<10; j++){
if(a[i]>a[j]){
b=j;
}
}
c=a[b];
a[b]=a[i];
a[i]=c;

24
}

for (int k=0; k<10; k++){


cout<<a[k]<<" ";
}
for(int i=0; i<4; i++){
for( j=0; j<10; j++){
if(a[i]<a[j]){
b=j;
}
}
c=a[b];
a[b]=a[i];
a[i]=c;
}
cout<<endl;
for (int k=0; k<10; k++){
cout<<a[k]<<" ";
}
}

25
3. Develop a program to take input of 10 integers from user. Implement Insertion Sort Algorithm on this array in
ascending order and descending order and analyze the outputs.
#include<iostream>
using namespace std;
int main()
{
int length;
cout<<"Enter an length array";
cin>>length;
int arr[length];

for(int i=0;i<length;i++)
{
//Cout<<"Enter number"<<i;
cin>>arr[i];
}
int j, temp;

for (int i = 0; i < length; i++)


{
j = i;

while (j > 0 && arr[j] < arr[j-1])


{
temp = arr[j];
arr[j] = arr[j-1];
arr[j-1] = temp;
j--;
}
}
for(int i=0;i<length;i++)
{
cout<<arr[i]<<" ";
}
for (int i = 0; i < length; i++)
{
j = i;

while (j > 0 && arr[j] > arr[j-1])


{
temp = arr[j];
arr[j] = arr[j-1];
arr[j-1] = temp;
j--;
}
}
cout<<endl;
26
for(int i=0;i<length;i++)
{
cout<<arr[i]<<" ";
}
}

4. Develop a program to take input of 10 integers from user. Implement Selection Sort Algorithm on this array.
Your program should points out the largest number in the array and put this largest element at the end of the
array.

#include<iostream>
using namespace std;
int main(){
int a[10];
int b,c,j;
for(int i=0; i<10; i++){
cout<<"enter number "<<i<<":";
cin>>a[i];
}
for(int i=0; i<4; i++){
for( j=0; j<10; j++){
if(a[i]>a[j]){
b=j;
}
}
c=a[b];
a[b]=a[i];
a[i]=c;
}

27
cout<<"larget number of array"<<a[j-1];

5. Develop a program to take input of 10 integers from user. Implement Bubble Sort Algorithm on this array in
ascending order and descending order and analyze the outputs.
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n, i, arr[50], j, temp;
cout<<"Enter total number of elements :";
cin>>n;
cout<<"Enter "<<n<<" numbers :";
for(i=0; i<n; i++)
{
cin>>arr[i];
}
cout<<"Sorting array using bubble sort technique...\n";
for(i=0; i<(n-1); i++)
{
for(j=0; j<(n-i-1); j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
28
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
cout<<"Elements sorted successfully..!!\n";
cout<<"Sorted list in ascending order :\n";
for(i=0; i<n; i++)
{
cout<<arr[i]<<" ";
}
getch();
}

#include<iostream>
#include<conio.h>
using namespace std;
int main(){
int array[50], n, i, j, temp;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for(i = 0; i < n; i++)
scanf("%d", &array[i]);
for (i = 0 ; i < ( n - 1 ); i++){
for (j= 0 ; j < n - i - 1; j++){
if(array[j] < array[j+1]){
temp=array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
printf("Sorted list in descending order:\n");
for ( i = 0 ; i < n ; i++ )
printf("%d\n", array[i]);
return 0;
}
29
6. Develop a function that takes three parameters: an array of integers, the number of elements in the array, and
an integer (say, removeItem). The function should point out and delete the first occurrence of removeItem in
the array. If the value does not exist or the array is empty, output an appropriate message. If the removeItem
is in the array then delete this element and then perform the bubble sort operation on the resultant array.

30
7. Suppose you have the following array.
15, 5, 4, 18, 12, 19, 14, 10, 8, 20
Select the option which represents the sorted array after three passes of Insertion Sort?

a. 4, 5, 12, 15, 14, 10, 8, 18, 19, 20


b. 15, 5, 4, 10, 12, 8, 14, 18, 19, 20
c. 4, 5, 15, 18, 12, 19, 14, 10, 8, 20
d. 15, 5, 4, 18, 12, 19, 14, 10, 8, 20

8. Suppose you have the following array.


11, 7, 12, 14, 19, 1, 6, 18, 8, 20
Select the option which represents the sorted array after three passes of Selection Sort?
a. 7, 11, 12, 1, 6, 14, 8, 18, 19, 20
b. 7, 11, 12, 14, 19, 1, 6, 18, 8, 20
c. 11, 7, 12, 14, 1, 6, 8, 18, 19, 20
d. 11, 7, 12, 14, 8, 1, 6, 18, 19, 20

31
9. Suppose you have the following array.
19, 1, 9, 7, 3, 10, 13, 15, 8, 12
Select which of the following represents the sorted array after three complete passes of Bubble Sort?
a. 1, 9, 19, 7, 3, 10, 13, 15, 8, 12
b. 1, 3, 7, 9, 10, 8, 12, 13, 15, 19
c. 1, 7, 3, 9, 10, 13, 8, 12, 15, 19
d. 1, 9, 19, 7, 3, 10, 13, 15, 8, 12

32
Learning Outcomes

 What have you learnt from this experiment?

_______________________________________________________________________________

_______________________________________________________________________________

_______________________________________________________________________________

______________________________________________________________________________

_______________________________________________________________________________
Lab # 5

TITLE: SORTING (QUICK , MERGE, RADIX)

Equipment:

________________________________________________________________________________

Pre-Lab Preparation:

________________________________________________________________________________

Procedure

36
Observation and Results

 Develop a program to take input of 10 integers from user. Implement Radix Sort Algorithm on this array
in ascending order and descending order and analyze the outputs.

#include<iostream>
using namespace std;
int getMax(int arr[], int n)
{
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > mx)
mx = arr[i];
return mx;
}
void countSort(int arr[], int n, int exp)
{
int output[n];
int i, count[10] = {0};
for (i = 0; i < n; i++)
count[ (arr[i]/exp)%10 ]++;
for (i = 1; i < 10; i++)
count[i] += count[i - 1];
for (i = n - 1; i >= 0; i--)
{
output[count[ (arr[i]/exp)%10 ] - 1] = arr[i];
count[ (arr[i]/exp)%10 ]--;
}
for (i = 0; i < n; i++)
arr[i] = output[i];
}
void radixsort(int arr[], int n)
{
int m = getMax(arr, n);
for (int exp = 1; m/exp > 0; exp *= 10)
countSort(arr, n, exp);
}
void print(int arr[], int n)
{
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
}
int main()
{
int arr[10];
for(int i=0; i<10; i++){
37
cout<<"Enter number"<<i<<" ";
cin>>arr[i];
}
int n = sizeof(arr)/sizeof(arr[0]);
radixsort(arr, n);
print(arr, n);
return 0;
}

 Develop a program to take input of 10 alphabets from user. Implement Merge Sort Algorithm on this
array in ascending order and descending order and analyze the outputs.

#include<iostream>
using namespace std;
void merge_sort(int [],int ,int );
void merge(int [],int,int ,int );
int main()
{
int n;
cout<<"Enter the size of the array"<<endl;
cin>>n;
int a[n];
cout<<"Enter the elements in the array"<<endl;
for(int i=0;i<n;i++)
{
cin>>a[i];
}

cout<<"sorting using merge sort"<<endl;


int p=0,r=n-1;

merge_sort(a,p,r);

cout<<"sorted form"<<endl;
38
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
return 0;
}
void merge_sort(int a[],int first,int last)
{
int mid;
if(first<last)
{
mid=(first+last)/2;
merge_sort(a,first,mid);
merge_sort(a,mid+1,last);
merge(a,first,mid,last);
}
}
void merge(int a[],int first,int mid,int last)
{
int n1=(mid-first)+1;
int n2=last-mid;
int L[n1+1];
int R[n2+1];
for(int i=1;i<=n1;i++)
{
L[i]=a[first+i-1];
}
for(int j=1;j<=n2;j++)
{
R[j]=a[mid+j];
}
L[n1+1]=999;
R[n2+1]=999;
int i=1, j=1;
for(int k=first;k<=last;k++)
{
if(L[i]<=R[j])
{
a[k]=L[i];
i++;
}
else
{
a[k]=R[j];
j++;
}
}
39
}

 Develop a program to take input of 10 integers from user. Implement Quick Sort Algorithm on this array.
Select the rightmost element as pivot. Sort the array in ascending order.

#include <iostream>
using namespace std;
void quick_sort(int a[],int low,int high);
int partition(int[],int,int);
int main()
{
int n;
cout<<"Enter length of array= ";
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cout<<"Enter elements in array:"<<i<<" ";
cin>>a[i];
}
quick_sort(a,0,n-1);
cout<<"\nArray after sorting:\n";
for(int i=0;i<n;i++)
{
cout<<a[i]<<" ";
}

return 0;
}
void quick_sort(int a[],int low,int high)
{
int mid;
if(low<high)
{
40
mid=partition(a,low,high);
quick_sort(a,low,mid-1);
quick_sort(a,mid+1,high);
}
}
int partition(int a[],int low,int high)
{
int v,i,j,temp;
v=a[low];
i=low;
j=high+1;
do
{
do
{
i++;
}
while(a[i]<v&&i<=high);
do
{
j--;
}
while(v<a[j]);
if(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}while(i<j);

a[low]=a[j];
a[j]=v;
return(j);
}

41
 Develop a program to take input of 10 integers from user. Implement Quick Sort Algorithm on this array.
Select the leftmost element as Pivot and arrange the resultant array in the descending order.

#include<iostream>
using namespace std;
int getMax(int arr[], int n)
{
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] < mx)
mx = arr[i];
return mx;
}
void countSort(int arr[], int n, int exp)
{
int output[n];
int i, count[10] = {0};
for (i = 0; i < n; i++)
count[ (arr[i]/exp)%10 ]++;
for (i = 1; i < 10; i++)
count[i] += count[i - 1];
for (i = n - 1; i >= 0; i--)
{
output[count[ (arr[i]/exp)%10 ] - 1] = arr[i];
count[ (arr[i]/exp)%10 ]--;
}
for (i = 0; i < n; i++)
arr[i] = output[i];
}
void radixsort(int arr[], int n)
{
int m = getMax(arr, n);
for (int exp = 1; m/exp > 0; exp *= 10)
countSort(arr, n, exp);
}
void print(int arr[], int n)
{
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
}
int main()
{
int arr[10];
for(int i=0; i<10; i++){
cout<<"Enter number"<<i<<" ";
cin>>arr[i];
}
42
int n = sizeof(arr)/sizeof(arr[0]);
radixsort(arr, n);
print(arr, n);
return 0;
}

 Develop a program to take input of 10 integers from user. Implement Radix Sort Algorithm on this array
in ascending order and descending order and analyze the outputs.

#include<iostream>
using namespace std;

int getMax(int arr[], int n)


{
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > mx)
mx = arr[i];
return mx;
}

void countSort(int arr[], int n, int exp)


{
int output[n];
int i, count[10] = {0};

for (i = 0; i < n; i++)


count[ (arr[i]/exp)%10 ]++;

for (i = 1; i < 10; i++)


count[i] += count[i - 1];

for (i = n - 1; i >= 0; i--)


{
output[count[ (arr[i]/exp)%10 ] - 1] = arr[i];
43
count[ (arr[i]/exp)%10 ]--;
}

for (i = 0; i < n; i++)


arr[i] = output[i];
}
void radixsort(int arr[], int n)
{
int m = getMax(arr, n);
for (int exp = 1; m/exp > 0; exp *= 10)
countSort(arr, n, exp);
}

void print(int arr[], int n)


{
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
}

int main()
{

int arr[10];
cout<<"Enter 10 numbers in array:\n";
for(int i=0;i<10;i++){
cout<<"Enter number "<<i+1<<": ";
cin>>arr[i];
}
int n = sizeof(arr)/sizeof(arr[0]);
radixsort(arr, n);
print(arr, n);
return 0;
}

44
Learning Outcomes

 What have you learnt from this experiment?

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

GENERALIZED LAB RUBRICS

Component with Above Meeting Approaching Below Weight / Score


Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
Is able to build a
Is able to
given setup neatly
Psychomoto

assemble a Is only able to Is not able to


and timely using
given setup copy a given assemble a
r

adapt to new /

Building correct hardware


using correct setup using given setup
(Hardware) components and / hardware correct using correct ☐
P4 or can reorganize / components hardware hardware
after minor components components
special
revisions
requirements
Is only able to
Recording
Is able to record Is able to record record Is unable to
Measurements
accurate accurate accurate record
(Hardware / ☐
measurements all measurements measurements accurate
Software)
the time most of the time on some measurements
C3
occasions
Cognitive

Investigation Is able to Is partially Is unable to


formulate /develop Is able to able to
theories in evaluate evaluate
addition to /conclude /conclude
(Hardware / comprehend
evaluating correctly about correctly ☐
Software) investigation
/concluding investigation about
C5 parameters
correctly about parameters by investigation
investigation assessing data parameters by
parameters by assessing data
45
Component with Above Meeting Approaching Below Weight / Score
Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
assessing data
Is able to Is unable to
Design /
Development of Is able to design / Is able to design partially partially
develop the design / design /
Solution / develop the
solution of a given develop the develop the ☐
(Hardware / solution of a
problem and add solution of a solution of a
Software) given problem
features to it given given
C6
problem problem
Is able to use
Is able to use
the software
Is adept in the use the software
Software Usage tool but Is unable to
of software tool tool effectively
(Software) and can access by accessing all cannot access use the ☐
C3 advanced features the required all the software tool
required
features
features
Is able to
efficiently
Is able to
complete a given
complete a
task using
given task using
Programming advanced Is able to Is unable to
required
Language programming partially partially
programming ☐
(Software) language complete a complete a
language
C3–C6 constructs / given task given task
constructs /
methods /
methods /
commands and/or
commands
add features to the
original task

Component with Above Meeting Approaching Below Weight / Score


Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
Complies Complies
Complies with
Safety Instructions Complies with all with some with very few
most EHS
(PLO6) EHS instructions EHS EHS ☐
instructions
A2 while in lab instructions instructions
while in lab
while in lab while in lab
Makes an
Does not
effort to
Exhibits Exhibits exhibit
exhibit
exemplary professional professional
professional
professional ethics ethics while ethics while
Professional Ethics while dealing with dealing with ethics while dealing with
(PLO8) ☐
fellow students, fellow students, dealing with
Affective

fellow
A3 fellow
lab staff and lab staff and students, lab
students, lab
instructor all the instructor all the staff and
staff and
time time instructor all
instructor all
the time
the time
Consistently Consistently Shows some
shows full shows full preparation Shows very
preparation by preparation by which is little or no
Contribution
(PLO9) completing all completing all mostly at preparation in ☐
agreed tasks and agreed tasks superficial completing a
A5
provides and work level in task and work
additional requires little or completing a quality is poor
resources for the no revisions task and work

46
group and work requires much
quality is excellent revisions and
editing
Neither
Consistent helpful nor
Internalized positive damaging and Discouraging
Attitude positive behavior behavior
behavior most shows
(PLO9) and encourages towards other ☐
of the time disinterest in
A5 and helps other team
towards other the
team members members
team members performance
of others
Report on all
relevant
Report on all
sections
relevant
related to the
Report on all sections related
lab tasks is
relevant sections to the lab tasks
related to the lab is completed completed but Report on all
tasks is completed but few many relevant
Report Writing deficiencies
accurately, deficiencies are sections
(PLO10) meeting the present in terms are present in related to the ☐
A2 requirements, in of accuracy / terms of lab tasks is
accuracy /
prescribed time meeting the not completed
meeting the
and with good requirements /
language skills prescribed time requirements /
/ good language prescribed
time / good
skills
language
skills
Does not
Lab Task Completes
Completes tasks Completes tasks complete
Management tasks in an
well within given within given tasks even in ☐
(PLO11) extended
timeframe timeframe extended
A3 timeframe
timeframes

47
Lab # 6
Title: STACK
Equipment:

________________________________________________________________________________

Pre-Lab Preparation:

________________________________________________________________________________

Procedure

48
Observation and Results
1. Develop the definition of the function that takes as a parameter a stack object and returns the selected (second)
element of the stack. The original stack remains unchanged.

#include<iostream>
#include<stdlib.h>
using namespace std;
class Stack
{
private:
static const int max = 100;
int arr[max];
int top;
public:
Stack() { top = -1; }
bool isEmpty();
bool isFull();
int pop();
void push(int x);
};

bool Stack::isEmpty()
{
if(top == -1)
return true;
return false;
}

bool Stack::isFull()
{
if(top == max - 1)
return true;
return false;
}

int Stack::pop()
{
if(isEmpty())
{
cout<<"Stack Underflow";
abort();
}
int x = arr[top];
top--;
return x;
}

49
void Stack::push(int x)
{
if(isFull())
{
cout<<"Stack Overflow";
abort();
}
top++;
arr[top] = x;
}

class SpecialStack: public Stack


{
Stack min;
public:
int pop();
void push(int x);
};

void SpecialStack::push(int x)
{
if(isEmpty()==true)
{
Stack::push(x);
}
else
{
Stack::push(x);
}
}

int SpecialStack::pop()
{
int x = Stack::pop();
return x;
}

SpecialStack StackFunction (SpecialStack s){


s.pop();s.pop();s.pop();
cout<<"Second number of stack is: "<<s.pop();
}
int main()
{
SpecialStack s;
int arr[5];
cout<<"Enter 5 values in stack:\n";
for(int i=0;i<5;i++){
50
cout<<"Enter number "<<i+1<<": ";
cin>>arr[i];
s.push(arr[i]);
}

StackFunction(s);
return 0;
}

2. Develop a program to input 10 numbers from user and push them onto stack using push operation. Then select
the smallest element in the stack and remove that element from the stack.

#include<iostream>
#include<stdlib.h>
using namespace std;
class Stack
{
private:
static const int max = 100;
int arr[max];
int top;
public:
Stack() { top = -1; }
bool isEmpty();
bool isFull();
int pop();
void push(int x);
};

bool Stack::isEmpty()
{
if(top == -1)
return true;
return false;
}

bool Stack::isFull()
{
51
if(top == max - 1)
return true;
return false;
}

int Stack::pop()
{
if(isEmpty())
{
cout<<"Stack Underflow";
abort();
}
int x = arr[top];
top--;
return x;
}

void Stack::push(int x)
{
if(isFull())
{
cout<<"Stack Overflow";
abort();
}
top++;
arr[top] = x;
}

class SpecialStack: public Stack


{
Stack min;
public:
int pop();
void push(int x);
int getMin();
};

void SpecialStack::push(int x)
{
if(isEmpty()==true)
{
Stack::push(x);
min.push(x);
}
else
{
Stack::push(x);
52
int y = min.pop();
min.push(y);
if( x < y )
min.push(x);
else
min.push(y);
}
}

int SpecialStack::pop()
{
int x = Stack::pop();
min.pop();
return x;
}
int SpecialStack::getMin()
{
int x = min.pop();
min.push(x);
return x;
}
int main()
{
SpecialStack s;
int arr[5];
cout<<"Enter 5 values in stack:\n";
for(int i=0;i<5;i++){
cout<<"Enter number "<<i+1<<": ";
cin>>arr[i];
s.push(arr[i]);
}
int a = s.getMin();
cout<<"Minimum Number is: "<<a;
return 0;
}

53
3. Develop a program to input 10 numbers from user and push them onto stack using push operation. Your
program should point out the squares of even numbers saved in the stack.

#include<stdio.h>
#define max 5
int top,a[max];
void push(void)
{
int x,i;
if(top==max-1)
{
printf("stack overflow\n");
return;
}
printf("Enter 10 Element into Stack\n");
for(int i=0;i<10;i++){
scanf("%d",&x);
a[++top]=x;
}
printf("Elements inserted into Stack\n");
return;
}
void pop(void)
{

if(top==-1)
{
printf("stack underflow\n");
return;
}

a[top--]=0;

return;
}
void display(void)
{
int i;
if(top==-1)
{
printf("\n Stack is empty\n");
return;
}
printf("\n Elements of Stack are :\n");
for(i=0;i<=top;i++)

54
{
printf("%d\n",a[i]);
}
return;
}

void popeven(void)
{
int i,t=0,temp[max],temptop=0;
if(top==-1)
{
printf("\n Stack is empty ! \n");
return;
}

for(i=0;i<=top;i++)
{
if((i+1)%2 != 0)
{
temp[t]=a[i];
t++;
}

temptop=top;

for(i=0;i<=temptop;i++)
{
pop();
}

for(i=0;i<=t;i++)
{
top++;
a[i]=temp[i];
}
printf("Even Elements of Stack are :\n");
top--;
for(i=0;i<=top;i++)
{
printf("%d\n",a[i]);
}

return;

55
}
int main()
{

push();
popeven();

4. Develop a program to input numbers from user until user wants and push them onto stack using push operation.
If the top of the stack is even, then select even numbers and calculate the sum of even numbers stored in the
stack else calculate the odd numbers sum.

56
5. Develop the following postfix expressions and analyze the output:
a. 8 2 + 3 * 16 4 / - =
b. 12 25 5 1 / / * 8 7 + - =

6. Convert the following infix expressions to postfix notations and analyze the output.
a. (A + B) * (C + D) – E
b. A - (B + C) * D + E / F

57
7. Develop the equivalent infix expression for the following postfix expressions and analyze the output.
a. A B * C +
b. A B + C D - *

Learning Outcomes

 What have you learnt from this experiment?

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

58
_____________________________________________________________________________________

_____________________________________________________________________________________

GENERALIZED LAB RUBRICS

Component with Above Meeting Approaching Below Weight / Score


Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
Is able to build a
Is able to
given setup neatly
Psychomoto

assemble a Is only able to Is not able to


and timely using
given setup copy a given assemble a
r

adapt to new /

Building correct hardware


using correct setup using given setup
(Hardware) components and / hardware correct using correct ☐
P4 or can reorganize / components hardware hardware
after minor components components
special
revisions
requirements
Is only able to
Recording
Is able to record Is able to record record Is unable to
Measurements
accurate accurate accurate record
(Hardware / ☐
measurements all measurements measurements accurate
Software)
the time most of the time on some measurements
C3
occasions
Is able to
Is partially
formulate /develop
Is able to able to
theories in
evaluate evaluate
Investigation addition to Is unable to
/conclude /conclude
(Hardware / evaluating comprehend
correctly about correctly ☐
Software) /concluding investigation
investigation about
C5 correctly about parameters
parameters by investigation
investigation
assessing data parameters by
Cogniti

Development of parameters by Is able to design partially partially


ve

Is able to des ign /

assessing data assessing data


Is able to Is unable to
Design /
develop the design / design /
Solution / develop the
solution of a given develop the develop the ☐
(Hardware / solution of a
problem and add solution of a solution of a
Software) given problem
features to it given given
C6
problem problem
Is able to use
Is able to use
the software
Is adept in the use the software
Software Usage tool but Is unable to
of software tool tool effectively
(Software) and can access by accessing all cannot access use the ☐
C3 advanced features the required all the software tool
required
features
features
Programming Is able to Is able to Is able to Is unable to

Language efficiently complete a partially partially

59
Component with Above Meeting Approaching Below Weight / Score
Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
(Software) complete a given given task using complete a complete a
C3–C6 task using required given task given task
advanced programming
programming language
language constructs /
constructs / methods /
methods / commands
commands and/or
add features to the
original task

Component with Above Meeting Approaching Below Weight / Score


Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
Complies Complies
Complies with
Safety Instructions Complies with all with some with very few
most EHS
(PLO6) EHS instructions EHS EHS ☐
instructions
A2 while in lab instructions instructions
while in lab
while in lab while in lab
Makes an
Does not
effort to
Exhibits Exhibits exhibit
exhibit
exemplary professional professional
professional
professional ethics ethics while ethics while
Professional Ethics while dealing with dealing with ethics while dealing with
(PLO8) ☐
fellow students, fellow students, dealing with fellow
A3 fellow
lab staff and lab staff and students, lab
students, lab
instructor all the instructor all the staff and
staff and
time time instructor all
instructor all
the time
the time
Shows some
Consistently
preparation
shows full Consistently
which is
Affective

preparation by shows full Shows very


mostly at
completing all preparation by little or no
Contribution superficial
(PLO9) agreed tasks and completing all level in preparation in ☐
provides agreed tasks completing a
A5 completing a
additional and work task and work task and work
resources for the requires little or requires much quality is poor
group and work no revisions revisions and
quality is excellent
editing
Neither
Consistent helpful nor
Internalized positive damaging and Discouraging
Attitude positive behavior behavior most behavior
shows
(PLO9) and encourages towards other ☐
of the time disinterest in
A5 and helps other team
towards other the
team members members
team members performance
of others
Report on all Report on all Report on all Report on all
relevant sections relevant relevant relevant
Report Writing
related to the lab sections related sections sections
(PLO10) tasks is completed to the lab tasks related to the related to the ☐
A2 accurately, is completed lab tasks is lab tasks is
meeting the but few completed but not completed
60
requirements, in deficiencies are many
prescribed time present in terms deficiencies
and with good of accuracy / are present in
language skills meeting the terms of
requirements / accuracy /
prescribed time meeting the
/ good language requirements /
skills prescribed
time / good
language
skills
Does not
Lab Task Completes
Completes tasks Completes tasks complete
Management tasks in an
well within given within given tasks even in ☐
(PLO11) extended
timeframe timeframe extended
A3 timeframe
timeframes

61
Lab # 7

TITLE: QUEUE (OPEN ENDED LAB-1)

Equipment:

________________________________________________________________________________

Pre-Lab Preparation:

________________________________________________________________________________

Procedure

62
Observation and Results

1. Develop a Priority Queue Data Structure by modifying simple queue and compare its output with simple queue.
You may implement queue either by using array or by using linked list. Also choose the size of queue according
to your own choice.

#include <iostream>
#include <queue>
using namespace std;
int main ()
{
priority_queue <int> pqueue;
int qlength,qvalue;
cout<<"Enter length of queue: ";
cin>>qlength;
cout<<"Enter values in queue:-\n";
for(int i=0; i<qlength; i++)
{
cin>>qvalue;
pqueue.push(qvalue);
}
cout << "The priority queue is : ";
while (!pqueue.empty())
{
cout << '\t' << pqueue.top();
pqueue.pop();
}
return 0;
}

63
2. Develop the Circular Queue by using single ended Queue. You may implement queue either by using array or
by using linked list. Also choose the size of queue according to your own choice.

#include<iostream>
#include <bits/stdc++.h>
using namespace std;
struct Node
{
int data;
struct Node* link;
};
struct Queue
{
struct Node *front, *rear;
};
void enQueue(Queue *q, int value)
{
struct Node *temp = new Node;
temp->data = value;
if (q->front == NULL)
q->front = temp;
else
q->rear->link = temp;

q->rear = temp;
q->rear->link = q->front;
}
int deQueue(Queue *q)
{
if (q->front == NULL)
{
cout<<"Queue is empty";
return INT_MIN;
}
int value;
if (q->front == q->rear)
{
value = q->front->data;
free(q->front);
q->front = NULL;
q->rear = NULL;
}
else
{
struct Node *temp = q->front;
value = temp->data;
q->front = q->front->link;
q->rear->link= q->front;
64
free(temp);
}

return value ;
}
void displayQueue(struct Queue *q)
{
struct Node *temp = q->front;
cout<<"\nElements in Circular Queue are: ";
while (temp->link != q->front)
{
cout<<temp->data;
cout<<"\t";
temp = temp->link;
}
cout<<temp->data;
cout<<"\t";
}
int main()
{
Queue *q = new Queue;
q->front = q->rear = NULL;
enQueue(q, 14);
enQueue(q, 22);
enQueue(q, 6);
displayQueue(q);
printf("\nDeleted value = %d", deQueue(q));
displayQueue(q);
enQueue(q, 9);
enQueue(q, 20);
displayQueue(q);
return 0;
}

65
Learning Outcomes

 What have you learnt from this experiment?

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

GENERALIZED LAB RUBRICS

Component with Above Meeting Approaching Below Weight / Score


Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
Is able to build a
Is able to
given setup neatly
Psychomotor

assemble a Is only able to Is not able to


and timely using
adapt to new /

given setup copy a given assemble a


Building correct hardware
using correct setup using given setup
(Hardware) components and / hardware correct using correct ☐
P4 or can reorganize / components hardware hardware
after minor components components
special
revisions
requirements
Recording Is able to record Is able to record Is only able to Is unable to

ogni

ti

Measurements accurate accurate record record

66
Component with Above Meeting Approaching Below Weight / Score
Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
(Hardware / measurements all measurements accurate accurate
Software) the time most of the time measurements measurements
C3 on some
occasions
Is able to
Is partially
formulate /develop
Is able to able to
theories in
evaluate evaluate
Investigation addition to Is unable to
/conclude /conclude
(Hardware / evaluating comprehend
correctly about correctly ☐
Software) /concluding investigation
investigation about
C5 correctly about parameters
parameters by investigation
investigation
assessing data parameters by
parameters by
assessing data
assessing data
Is able to Is unable to
Design /
Development of Is able to design / Is able to design partially partially
develop the design / design /
Solution / develop the
solution of a given develop the develop the ☐
(Hardware / solution of a
problem and add solution of a solution of a
Software) given problem
features to it given given
C6
problem problem
Is able to use
Is able to use
the software
Is adept in the use the software
Software Usage tool but Is unable to
of software tool tool effectively
(Software) and can access by accessing all cannot access use the ☐
C3 advanced features the required all the software tool
required
features
features
Is able to
efficiently
Is able to
complete a given
complete a
task using
given task using
Programming advanced Is able to Is unable to
required
Language programming partially partially
programming ☐
(Software) language complete a complete a
language
C3–C6 constructs / given task given task
constructs /
methods /
methods /
commands and/or
commands
add features to the
original task

Component with Above Meeting Approaching Below Weight / Score


Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
Complies Complies
Complies with
Safety Instructions Complies with all with some with very few
most EHS
(PLO6) EHS instructions EHS EHS ☐
instructions
A2 while in lab instructions instructions
while in lab
Affective

while in lab while in lab


Exhibits Exhibits Makes an Does not
exemplary professional effort to exhibit
Professional Ethics professional ethics ethics while exhibit professional
(PLO8) ☐
while dealing with dealing with professional ethics while
A3
fellow students, fellow students, ethics while dealing with
lab staff and lab staff and dealing with fellow

67
instructor all the instructor all the fellow students, lab
time time students, lab staff and
staff and instructor all
instructor all the time
the time
Shows some
Consistently
preparation
shows full Consistently
which is
preparation by shows full Shows very
mostly at
completing all preparation by little or no
Contribution superficial
(PLO9) agreed tasks and completing all level in preparation in ☐
provides agreed tasks completing a
A5 completing a
additional and work task and work task and work
resources for the requires little or requires much quality is poor
group and work no revisions revisions and
quality is excellent
editing
Neither
Consistent helpful nor
Internalized positive damaging and Discouraging
Attitude positive behavior behavior
behavior most shows
(PLO9) and encourages towards other ☐
of the time disinterest in
A5 and helps other team
towards other the
team members members
team members performance
of others
Report on all
relevant
Report on all
sections
relevant
related to the
Report on all sections related
lab tasks is
relevant sections to the lab tasks
related to the lab is completed completed but Report on all
tasks is completed but few many relevant
Report Writing deficiencies
accurately, deficiencies are sections
(PLO10) meeting the present in terms are present in related to the ☐
A2 terms of
requirements, in of accuracy / lab tasks is
accuracy /
prescribed time meeting the not completed
meeting the
and with good requirements /
language skills prescribed time requirements /
/ good language prescribed
time / good
skills
language
skills
Does not
Lab Task Completes
Completes tasks Completes tasks complete
Management tasks in an
well within given within given tasks even in ☐
(PLO11) extended
timeframe timeframe extended
A3 timeframe
timeframes

68
Lab # 8

TITLE: LINKKED LIST&DOUBLYLINKED LIST


(OPEN ENDED LAB-2)

Equipment:

________________________________________________________________________________

Pre-Lab Preparation:

________________________________________________________________________________

Procedure

69
Observation and Results
1. Develop a program that reads students’ names followed by their test scores. The program should output
each student’s name followed by the test scores and the relevant grade. It should also point out and print
the highest test score and the name of the students having the highest test score.

#include<iostream>
#include<string>
using namespace std;

struct StudentData
{
string SFname;
string SLname;
int scores;
char grade;
};
void Sinfo();
char AssGrade(int);
void highestScore(int);
void printHighestscore(int);
void outputRecord();

StudentData s[20]; //instance of StudentData to store the data of 20 student

int highest_score[20], highest;

int main(){
Sinfo();//calling of a function to take the data from the user
printHighestscore(highest);//print the higest test score
outputRecord();//prints the record system("pause");

return 0;
}
void Sinfo()//function that inputs the data from the user
{
for (int i = 0; i < 5; i++)
{
cout << "Student No." << i + 1 << endl;
cout << " First name :";
cin >> s[i].SFname;
cout << " Last name :";
cin >> s[i].SLname;
cout << " Test score :";
cin >> s[i].scores;

if (s[i].scores >= 0 && s[i].scores <= 100)

70
s[i].grade = AssGrade(s[i].scores);
else
{
do{
cout << " Entered invalid test scores" << endl;
cout << " AGAIN Enter the test score" << i + 1 << "
:"; cin >> s[i].scores;
} while (s[i].scores < 0 || s[i].scores >
100); s[i].grade = AssGrade(s[i].scores);
}
cout << endl;
highestScore(i);
}
}
char AssGrade(int num)
{
char grade;
if (num >= 90)
grade = 'A';
else if (num >= 80)
grade = 'B';
else if (num >= 70)
grade = 'C';
else if (num >= 60)
grade = 'D';
else
grade = 'F';
return grade;
}
void highestScore(int j)
{
if (j == 0)
{
highest_score[0] = s[j].scores;
highest = s[j].scores;
}
else if (s[j].scores >= highest)
{
highest_score[j] = s[j].scores;
highest = s[j].scores;
}
}
void printHighestscore(int h)
{
cout << "Higest test Score= " << h << endl;
cout << "STUDENT(s) got the Highest score are" << endl;

71
for (int i = 0; i < 5; i++)
{
if (highest_score[i] == h)
{
cout << s[i].SFname << endl;

}
}

}
void outputRecord()
{
cout << " First Name" << "LAST NAME" << " \t\tTEST SCORE" << "\tGRADE" << endl;
for (int i = 0; i < 5; i++)
{
cout << s[i].SFname << ", " << s[i].SLname << " \t\t\t " << s[i].scores << " \t\t " << s[i].grade <<
endl;
}
}

72
2. Develop the code of the insert function to store data in descending order in the link list and compare the
output.

#include<iostream>
#include<stdlib.h>
using namespace std;
struct Node
{
int data;
struct Node* next;
};

void sortedInsert(struct Node** head_ref, struct Node* new_node)


{
struct Node* current;
if (*head_ref == NULL || (*head_ref)->data >= new_node->data)
{
new_node->next = *head_ref;
*head_ref = new_node;
}
else
{
current = *head_ref;
while (current->next!=NULL &&
current->next->data < new_node->data)
{
current = current->next;
}
new_node->next = current->next;
current->next = new_node;
}
}

struct Node *newNode(int new_data)


{

struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));


new_node->data = new_data;
new_node->next = NULL;
return new_node;
}

void printList(struct Node *head)


{
struct Node *temp = head;
while(temp != NULL)
{

73
cout<<temp->data<<" ";
temp = temp->next;
}
}

int main()
{
int length, number;
struct Node* head = NULL;
cout<<"Enter length of link list: ";
cin>> length;
struct Node *new_node = newNode(length);
cout<<"Enter numbers in link list\n";
for(int i=0; i<length; i++)
{
cin>> number;
new_node = newNode(number);
sortedInsert(&head, new_node);
}
cout<<"\nCreated Linked List\n";
printList(head);
return 0;
}

74
3. Develop the code of link list to store the student record in the data part instead of info and compare the
output.

#include<bits/stdc++.h>
using namespace std;
struct Node
{
int data;
struct Node *next;
};
struct Node *addToEmpty(struct Node *last, int data)
{
if (last != NULL)
return last;
struct Node *temp =
(struct Node*)malloc(sizeof(struct Node));
temp -> data = data;
last = temp;
last -> next = last;
return last;
}

struct Node *addBegin(struct Node *last, int data)


{
if (last == NULL)
return addToEmpty(last, data);

struct Node *temp =


(struct Node *)malloc(sizeof(struct Node));

temp -> data = data;


temp -> next = last -> next;
last -> next = temp;

return last;
}

struct Node *addEnd(struct Node *last, int data)


{
if (last == NULL)
return addToEmpty(last, data);
struct Node *temp =
(struct Node *)malloc(sizeof(struct Node));

temp -> data = data;


temp -> next = last -> next;
last -> next = temp;

75
last = temp;

return last;
}

struct Node *addAfter(struct Node *last, int data, int item)


{
if (last == NULL)
return NULL;

struct Node *temp, *p;


p = last -> next;
do
{
if (p ->data == item)
{
temp = (struct Node *)malloc(sizeof(struct Node));
temp -> data = data;
temp -> next = p -> next;
p -> next = temp;

if (p == last)
last = temp;
return last;
}
p = p -> next;
} while(p != last -> next);

cout << item << " not present in the list." << endl;
return last;

void traverse(struct Node *last)


{
struct Node *p;
if (last == NULL)
{
cout << "List is empty." << endl;
return;
}
p = last -> next;
do
{
cout << p -> data << " ";
p = p -> next;

76
}
while(p != last->next);

}
int main()
{
struct Node *last = NULL;

last = addToEmpty(last, 6);


last = addBegin(last, 4);
last = addBegin(last, 2);
last = addEnd(last, 8);
last = addEnd(last, 12);
last = addAfter(last, 10, 8);
traverse(last);
return 0;
}

4. Develop a program that selects only data part of the whole link list (except the address part of each node)
in the file.

#include <iostream>
#include <fstream>

using namespace std;

struct Node{
int data;
Node *next;
};

typedef Node* NodePtr;

NodePtr& addHeadNode(NodePtr& head, int NewData);

void printList(NodePtr& head);

int main(){

77
int a;
ifstream fin;
ofstream fout;
NodePtr head = NULL;

fin.open("numbers.txt");

while(fin>>a) addHeadNode(head,a);

fin.close();

cout<< "SINGLY LINKED LIST: " << endl;

printList(head);

return 0;
}

NodePtr& addHeadNode(NodePtr& head, int NewData)


{
NodePtr NewPtr = new Node();
NewPtr->data = NewData;
NewPtr->next = NULL;

NodePtr p = head;

if(p == NULL) head = NewPtr;


else
{
while(p->next != NULL) p = p->next;
p->next = NewPtr;
}

return head;
}

void printList(NodePtr& head)


{
NodePtr p = head;

while(p != NULL)
{
cout<< p->data << endl;
p = p->next;
}
}

78
1. (open ended)Develop the class circular Linked List by using single linked list and its member functions. (You
may assume that the elements of the circular linked list are in ascending order or descending order.)

2. (open ended)Round-robin (RR) is one of the algorithms employed by process and network schedulers in
computing. As the term is generally used, time units are assigned to each process in equal portions and in
circular order, handling all processes without priority (also known as cyclic executive). Each process cannot
execute more than some predefined value of time units (known as quantum) in single turn. If the process time
units which require completing execution is more than quantum the remaining time units are executed in next
turn. And if, it complete execution the process is terminated. According to scenario which data structure is most
suitable and explains why and also develop algorithm for this scenario. (Choose different values of quantum
and time units assigned to processor to verify your algorithm)?
79
Learning Outcomes

 What have you learnt from this experiment?

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

_____________________________________________________________________________________

80
GENERALIZED LAB RUBRICS

Component with Above Meeting Approaching Below Weight / Score


Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
Is able to build a
Is able to
given setup neatly
Psychomot

assemble a Is only able to Is not able to


and timely using
or

adapt to new /

given setup copy a given assemble a


Building correct hardware
using correct setup using given setup
(Hardware) components and / hardware correct using correct ☐
P4 or can reorganize / components hardware hardware
after minor components components
special
revisions
requirements
Is only able to
Recording
Is able to record Is able to record record Is unable to
Measurements
accurate accurate accurate record
(Hardware / ☐
measurements all measurements measurements accurate
Software)
the time most of the time on some measurements
C3
occasions
Is able to
Is partially
formulate /develop
Is able to able to
theories in
evaluate evaluate
Investigation addition to Is unable to
/conclude /conclude
(Hardware / evaluating comprehend
correctly about correctly ☐
Software) /concluding investigation
investigation about
C5 correctly about parameters
parameters by investigation
investigation
assessing data parameters by
parameters by
assessing data
assessing data
Is able to Is unable to
Design /
Development of Is able to design / Is able to design partially partially
develop the design / design /
Solution / develop the

Cogniti

C6 solution of a given develop the develop the


ve

(Hardware / solution of a problem problem

problem and add solution of a solution of a


Software) given problem
features to it given given

Is able to use
Is able to use
the software
Is adept in the use the software
Software Usage tool but Is unable to
of software tool tool effectively
(Software) and can access by accessing all cannot access use the ☐
C3 advanced features the required all the software tool
required
features
features
Is able to
efficiently
Is able to
complete a given
complete a
task using
given task using
Programming advanced Is able to Is unable to
required
Language programming partially partially
programming ☐
(Software) language complete a complete a
language
C3–C6 constructs / given task given task
constructs /
methods /
methods /
commands and/or
commands
add features to the
original task

81
Component with Above Meeting Approaching Below Weight / Score
Domain Expectation Expectation Expectation Expectation Used 100
Taxonomy (4) (3) (2) (1) (Optional) (1–4)
Complies Complies
Complies with
Safety Instructions Complies with all with some with very few
most EHS
(PLO6) EHS instructions EHS EHS ☐
instructions
A2 while in lab instructions instructions
while in lab
while in lab while in lab
Makes an
Does not
effort to
Exhibits Exhibits exhibit
exhibit
exemplary professional professional
professional
professional ethics ethics while ethics while
Professional Ethics while dealing with dealing with ethics while dealing with
(PLO8) ☐
fellow students, fellow students, dealing with fellow
A3 fellow
lab staff and lab staff and students, lab
students, lab
instructor all the instructor all the staff and
staff and
time time instructor all
instructor all
the time
the time
Shows some
Consistently
preparation
shows full Consistently
which is
preparation by shows full Shows very
mostly at
completing all preparation by little or no
Contribution superficial
(PLO9) agreed tasks and completing all level in preparation in ☐
provides agreed tasks completing a
A5 completing a
additional and work task and work task and work
resources for the requires little or requires much quality is poor
group and work no revisions revisions and
quality is excellent
editing
Affectiv

Neither
e

Consistent helpful nor


Internalized positive damaging and Discouraging
Attitude positive behavior behavior
behavior most shows
(PLO9) and encourages towards other ☐
of the time disinterest in
A5 and helps other team
towards other the
team members members
team members performance
of others
Report on all
relevant
Report on all
sections
relevant
related to the
Report on all sections related
lab tasks is
relevant sections to the lab tasks
related to the lab is completed completed but Report on all
tasks is completed but few many relevant
Report Writing deficiencies
accurately, deficiencies are sections
(PLO10) meeting the present in terms are present in related to the ☐
A2 requirements, in of accuracy / terms of lab tasks is
accuracy /
prescribed time meeting the not completed
meeting the
and with good requirements /
language skills prescribed time requirements /
/ good language prescribed
time / good
skills
language
skills
Does not
Lab Task Completes
Completes tasks Completes tasks complete
Management tasks in an
well within given within given tasks even in ☐
(PLO11) extended
timeframe timeframe extended
A3 timeframe
timeframes

82

You might also like