PPL File DHRUV GOEL 44114802717
PPL File DHRUV GOEL 44114802717
PPL File DHRUV GOEL 44114802717
LAB
ETCS-458
Semester: 8th
Group: C8
MISSION
The Institute shall endeavour to incorporate the following basic missions in the teaching
methodology:
Engineering Hardware – Software Symbiosis
Practical exercises in all Engineering and Management disciplines shall be carried out by
Hardware equipment as well as the related software enabling deeper understanding of basic
concepts and encouraging inquisitive nature.
Life – Long Learning
The Institute strives to match technological advancements and encourage students to keep
updating their knowledge for enhancing their skills and inculcating their habit of continuous
learning.
Liberalization and Globalization
The Institute endeavour’s to enhance technical and management skills of students so that they
are intellectually capable and competent professionals with Industrial Aptitude to face the
challenges of globalization.
Diversification
Engineering, Technology and Management disciplines have diverse fields of studies with
different attributes. The aim is to create a synergy of the above attributes by encouraging
analytical thinking.
Digitization of Learning Processes
The Institute provides seamless opportunities for innovative learning in all Engineering and
Management disciplines through digitization of learning processes using analysis, synthesis,
simulation, graphics, tutorials and related tools to create a platform for multi-disciplinary
approach.
Entrepreneurship
The Institute strives to develop potential Engineers and Managers by enhancing their skills and
research capabilities so that they become successful entrepreneurs and responsible citizens.
MAHARAJA AGRASEN INSTITUTE OF
TECHNOLOGY
MISSION
To provide an excellent learning environment across the computer science discipline
to inculcate professional behaviour, strong ethical values, innovative research
capabilities and leadership abilities which enable them to become
successful entrepreneurs in this globalized world.
Overall Comments:
CODE: -
#include<stdio.h>
#include<string.h>
void main(){
char str[50];
char temp[20];
char choice, ch;
//printf("For ")
puts("To get the length of string, choose 'L'."); //strlen();//
puts("To convert the whole string in lower case, choose 'l'."); //strlwr();
puts("To convert the whole string in upper case, choose 'U'."); //strupr();
puts("To append a string behind other, choose 'A'."); //strcat();//
puts("To copy a string into another, choose 'c'."); //strcpy();//
puts("To compare two strings, choose 'C'."); //strcmp();//
puts("To find out first ocurence of given character in a string, choose 'O'"); //strchr();
puts("To find out first ocurence of given string in another string, choose 'S'");
//strstr();
puts("To reverse the string, choose 'R'"); //strrev();//
printf("\nEnter Your Choice: ");
scanf("%c", &choice);
switch(choice){
case 'L':
printf("\nEnter The String To Get Its Length: ");
scanf("%s", str);
printf("The Length Of The Entered String Is: %d", strlen(str));
break;
case 'l':
printf("\nEnter The String To Convert It Into Lower Case : ");
scanf("%s", str);
printf("The Entered String In Lowercase: %s", strlwr(str));
break;
case 'U':
printf("\nEnter The String To Convert It Into Upper Case : ");
scanf("%s", str);
printf("\nThe Entered String In Lowercase: %s", strupr(str));
break;
case 'A':
printf("\nEnter The First String: ");
scanf("%s", str);
printf("Enter The Second String To Append It Behind First One: ");
scanf("%s", temp);
strcat(str, temp);
printf("\nNow, The First String Is: %s", str);
break;
case 'c':
printf("\nEnter The First String: ");
scanf("%s", str);
printf("Enter The Second String: ");
scanf("%s", temp);
strcpy(str, temp);
printf("\nNow, The First String Is: %s", str);
printf("\nAnd, The Second String Is: %s", temp);
break;
case 'C':
printf("\nEnter The First String: ");
scanf("%s", str);
printf("Enter The Second String: ");
scanf("%s", temp);
if(strcmp(str, temp)==0)printf("\nBoth Strings Are Similar.");
else printf("\nBoth Strings Are Different.");
break;
case 'O':
printf("\nEnter The String: ");
scanf("%s", str);
printf("Enter The Character To Be Searched: ");
scanf("%c", &ch);
printf("\nThe First Occurence of Character Is At: %s", strchr(str, ch));
break;
case 'S':
printf("\nEnter The String: ");
scanf("%s", str);
printf("Enter The String To Be Searched: ");
scanf("%s", temp);
printf("\nThe First Occurence of Character Is At: %s", strstr(str,
temp));
break;
case 'R':
printf("\nEnter The String To Get Its Reverse: ");
scanf("%s", str);
printf("\nThe Reverse Of The Entered String Is: %s", strrev(str));
break;
default:
printf("\nYou Entered A Wrong Choise.");
break;
}
}
OUTPUT
EXPERIMENT NO. 2
AIM: - Write a program (WAP) in C to reverse a linked list iterative and recursive.
CODE: -
int main()
{
/* Start with the empty list */
struct Node* head = NULL;
push(&head, 20);
push(&head, 4);
push(&head, 15);
push(&head, 85);
//reverse(&head);
printf("\n\nReversing LinkedList Recursivly....\n");
recursiveReverse(head, &head);
OUTPUT: -
EXPERIMENT NO. 3
AIM: - WAP in C to implement iterative Towers of Hanoi.
CODE: -
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
else if (i % 3 == 2)
moveDisksBetweenTwoPoles(src, aux, s, a);
else if (i % 3 == 0)
moveDisksBetweenTwoPoles(aux, dest, a, d);
}
}
// Driver Program
int main()
{
// Input: number of disks
unsigned num_of_disks = 3;
OUTPUT: -
EXPERIMENT NO. 4
AIM: - WAP in C++ to count the nos. of an object of a class with the help of static data
members, function and constructor.
CODE: -
#include <iostream>
using namespace std;
class Counter
{
private:
//static data member as count
static int count;
public:
//default constructor
Counter()
{ count++; }
//static member function
static void Print()
{
cout<<"\nTotal objects are: "<<count;
}
};
int main()
{
Counter OB1;
OB1.Print();
Counter OB2;
OB2.Print();
Counter OB3;
OB3.Print();
return 0;
}
OUTPUT: -
EXPERIMENT NO. 5
AIM: - WAP in C++ & Java to declare a class Time with data members mm for minutes, ss
for seconds and hh for hours. Define a parameterized constructor to assign time to its objects.
Add two-time objects using member function and assign to third objects. Implement all
possible cases of time.
CODE: -
#include<iostream>
using namespace std;
class Time
{
int hh,mm,ss;
public:
Time(){}
Time(int hh, int mm, int ss)
{
this->hh=hh;
this->mm=mm;
this->ss=ss;
}
void disp()
{
cout<<hh<<":"<<mm<<":"<<ss;
}
void sum(Time t1,Time t2)
{
ss=t1.ss+t2.ss;
mm=ss/60;
ss=ss%60;
mm=mm+t1.mm+t2.mm;
hh=mm/60;
mm=mm%60;
hh=hh+t1.hh+t2.hh;
}
};
int main(){
Time t1(2,22,34);
cout<<"The Time T1 Is: ";
t1.disp();
Time t2(4, 33, 50);
cout<<"\n\nThe Time T2 Is: ";
t2.disp();
Time t3;
t3.sum(t1,t2);
cout<<"\n\nThe Resultant Time Is: ";
t3.disp();
}
OUTPUT: -
EXPERIMENT NO. 6
AIM: - WAP in C++ to define a class Complex to represent a set of all complex numbers.
Overload ‘+’ operator to add two complex numbers using member function of the class and
overload ‘*’ operator to multiply two complex numbers using the friend function of the class
complex.
CODE: -
#include<iostream>
using namespace std;
class Complex
{
int real,img;
public:
Complex(){};
Complex(int i,int j)
{
real=i;
img=j;
}
void show()
{
cout<<real<<" + i"<<img;
}
Complex operator +(Complex obj){
Complex temp;
temp.real=real+obj.real;
temp.img=img+obj.img;
return(temp);
}
Complex operator *(Complex);
};
Complex Complex::operator *(Complex c)
{
double real1,real2;
real1=real;
real2=c.real;
real=(real*c.real)-(img*c.img);
img=(real1*c.img)+(img*real2);
Complex temp;
temp.real=real;
temp.img=img;
return temp;
}
int main()
{
Complex c1(5,6), c2(7,8), c3, c4;
cout<<"The 1st no. is: ";
c1.show();
cout<<"\n\nThe 2nd no. is: ";
c2.show();
c3=c1+c2;
cout<<"\n\nSum is: ";
c3.show();
c4=c1*c2;
cout<<"\n\nMultiplication is: ";
c4.show();
}
OUTPUT: -
EXPERIMENT NO. 7
AIM: - Write a program to display 10 questions at random out of exp.8-50 questions (do not
display the answer of these questions to the user now).
CODE: -
import csv
quiz_dic={}
i=1
with open('output.csv', newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print("\nQue#%d: "%i, end="")
print(row['Questions'])
i=i+1
OUTPUT: -
EXPERIMENT NO. 8
AIM: - Implement producer-consumer problem using threads.
CODE: -
import java.util.LinkedList;
public class Threadexample
{
public static void main(String[] args)
throws InterruptedException
{
final PC pc = new PC();
Thread t1 = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
pc.produce();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
});
Thread t2 = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
pc.consume();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
});
t1.start();
t2.start();
t1.join();
t2.join();
}
public static class PC
{
LinkedList<Integer> list = new LinkedList<>();
int capacity = 2;
public void produce() throws InterruptedException
{
int value = 0;
while (true)
{
synchronized (this)
{
while (list.size()==capacity)
wait();
System.out.println("Producer produced-"
+
value);
list.add(value++);
notify();
Thread.sleep(1000);
}
}
}
public void consume() throws InterruptedException
{
while (true)
{
synchronized (this)
{
while (list.size()==0)
wait();
int val = list.removeFirst();
System.out.println("Consumer consumed-"
+ val);
notify();
Thread.sleep(1000);
}
}
}
}
}
OUTPUT: -
EXPERIMENT NO. 9
AIM: - There are 200 questions on a 3hr examination. Among these questions are 50
mathematics problems. It is suggested that twice as much time be spent on each maths problem
as for each other's questions. WAP which calculates how many minutes should be spent on
mathematics problems.
CODE: -
public class Program1 {
OUTPUT: -
EXPERIMENT NO. 10
AIM: - User enters the elements in a m x n matrix, where m is the number of rows and n is
the number of columns. Values of m and n are also entered by the user. Now WAP in C and
JAVA which find out the position of the element which is smallest in the row and largest in
the column.
CODE: -
import java.util.Scanner;
}
}
OUTPUT: -