Keshav PPL
Keshav PPL
LAB
ETCS-458
Semester: 8th
Group:8C13
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
The 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 sciencediscipline
to inculcate professional behaviour, strong ethical values, innovative research
capabilities and leadership abilities which enable them to become successful
entrepreneurs in this globalized world.
3. WAP in C to implement
iterative Towers of Hanoi
8. Write a program in to
prepare a list of 50 questions
and their answers.
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
VIVA QUESTIONS
Q1. What is the use of the string.h header file and where is it stored?
A1. The string.h header file is used for string manipulation functions in C programming. It is a
standard library header file stored in the C library.
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: -
VIVA QUESTIONS
Q1. What is the difference between iterative and recursive function call?
A1. Iterative function calls use loops to repeatedly execute a block of code, while recursive
function calls refer to a function calling itself to solve a problem by breaking it down into
smaller subproblems.
Q5. Why do we need to store the address of the starting node of a linked list for reversing a list?
A5. The address of the starting node is needed to reverse a linked list because it acts as the
entry point for traversing and manipulating the list, allowing us to rearrange the connections
between nodes and update the references accordingly.
Experiment 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: -
VIVA QUESTIONS
Q1. What is the tower of Hanoi problem?
- The Tower of Hanoi problem is a mathematical puzzle that involves moving a stack of disks
from one peg to another, using a third peg as an intermediary, while following certain rules.
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: -
VIVA QUESTIONS
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: -
VIVA QUESTIONS
Q2. The levels of acceptance of any language depend on the language description.
- The acceptance of a language is influenced by its description, including its features, syntax, and
capabilities, which determine its usability and popularity among developers.
Q3. Write the differences between lexical syntax and concrete syntax of the language.
- Lexical syntax refers to the rules that define how tokens are formed in a programming
language, while concrete syntax refers to the rules that define the structure and organization of
statements and expressions in the language.
Q5. Write the differences between array and enumerated data types in imperative languages?
- Arrays are homogeneous collections of elements accessed by index, while enumerated data
types define a set of named values that can be assigned to a variable, providing a limited set of
choices.
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: -
VIVA QUESTIONS
Q1. List the benefits of modular development approach.
- Modular development approach offers improved code reusability, easier maintenance and
debugging, and enhanced scalability and flexibility in software development.
Q2. Give some reasons why computer scientists and professional software developers should
study general concepts of language design and evaluation.
- Studying general concepts of language design and evaluation equips computer scientists and
software developers with a deeper understanding of programming languages, enabling them to
design efficient and expressive languages, optimize performance, and evaluate trade-offs in
language features.
Q5. How do type declaration statements affect the readability of programming language?
- Type declaration statements enhance the readability of programming languages by providing
clear and explicit information about the data types used in variables, parameters, and functions,
enabling easier understanding of code and detecting potential type-related errors.
EXPERIMENT – 7
Aim: Implement simple multi-threaded server to perform all mathematics operation parallel in
Java.
CODE:
SERVER
import java.io.*;
import java.net.*;
class Server {
try {
server.setReuseAddress(true);
// client request
while (true) {
// to server
+ client.getInetAddress()
.getHostAddress());
ClientHandler clientSock
= new ClientHandler(client);
// separately
new Thread(clientSock).start();
catch (IOException e) {
e.printStackTrace();
finally {
if (server != null) {
try {
server.close();
catch (IOException e) {
e.printStackTrace();
}
}
// ClientHandler class
// Constructor
this.clientSocket = socket;
BufferedReader in = null;
try {
// get the outputstream of client
clientSocket.getOutputStream(), true);
// get the inputstream of client
in = new BufferedReader(
new InputStreamReader(
clientSocket.getInputStream()));
String line;
// client
System.out.printf(
line);
out.println(line);
catch (IOException e) {
e.printStackTrace();
finally {
try {
if (out != null) {
out.close();
if (in != null) {
in.close();
clientSocket.close();
catch (IOException e) {
e.printStackTrace();
import java.io.*;
import java.net.*;
import java.util.*;
// Client class
class Client {
// driver code
// number
// writing to server
socket.getOutputStream(), true);
BufferedReader in
socket.getInputStream()));
while (!"exit".equalsIgnoreCase(line)) {
// reading from user
line = sc.nextLine();
out.println(line);
out.flush();
+ in.readLine());
sc.close();
catch (IOException e) {
e.printStackTrace();
}
VIVA QUESTIONS
Q2. Describe any one method for bridging the gap between high-level language and machine
language.
- One method for bridging the gap between high-level language and machine language is
through the use of compilers, which translate high-level code into machine language instructions
that can be understood and executed by the computer's hardware.
Q3. Explain language evaluation criteria and the characteristics that affect them.
- Language evaluation criteria refer to the factors used to assess programming languages, such
as readability, writability, reliability, and cost.
- Characteristics like simplicity, expressiveness, portability, and efficiency can significantly
impact these evaluation criteria.
HTML (index.html):
<!DOCTYPE html>
<html>
<head>
<title>Questions and Answers</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>Questions and Answers</h1>
<div id="question-list"></div>
<script src="script.js"></script>
</body>
</html>
CSS (styles.css):
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h1 {
text-align: center;
}
.question {
margin-bottom: 10px;
}
.question h3 {
margin: 0;
}
.answer {
margin-bottom: 20px;
}
JavaScript (script.js):
document.addEventListener("DOMContentLoaded", function() {
var questions = [
{
question: "What is HTML?",
answer: "HTML stands for HyperText Markup Language. It is the standard markup language used for
creating the structure and presentation of web pages."
},
{
question: "What is CSS?",
answer: "CSS stands for Cascading Style Sheets. It is a stylesheet language used for describing the
presentation of a document written in HTML or XML."
},
// Add more questions and answers here...
];
questions.forEach(function(qa, index) {
var question = document.createElement("div");
question.classList.add("question");
questionList.appendChild(question);
});
});
OUTPUT:
VIVA QUESTIONS
Q1. What is printed by the print statements in the program P1 assuming call by reference
parameter passing?
Program P1:
```
Pl()
{
x = 10;
y = 3;
func1(y, x, x);
print x; // Output: 12
print y; // Output: 7
}
func1(x, y, z)
{
y = y + 4;
z = x + y + z;
}
```
Answer: Assuming call by reference parameter passing, the program P1 will print 12 (the
updated value of x) and 7 (the updated value of y).
Answer:
X: Indirect addressing matches with 2: Pointers.
Y: Immediate addressing matches with 3: Constants.
Z: Auto decrement addressing matches with 1: Loops.
Answer: Memory is allocated dynamically by using functions like malloc() or new in languages
like C/C++ or using the new operator in languages like Java. This allows for dynamic allocation
and deallocation of memory during program execution.
Answer: Pointers are used to store memory addresses, allowing direct access and manipulation of
data stored in memory. They are commonly used for tasks such as dynamic memory allocation,
accessing arrays and strings efficiently, and implementing data structures like linked lists and
trees.
Experiment 9
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: -
VIVA QUESTIONS
Q2. What is the use of functions? How are actual parameters different from formal parameters?
A2. Functions are used to perform specific tasks or operations. Actual parameters are the values
passed to a function, while formal parameters are the placeholders in the function definition that
receive those values.
CODE: -
import java.util.LinkedList;
public class Threadexample
{
public static void main(String[] args)
throws InterruptedException
{
final PC pc = new PC();
catch(InterruptedException e)
{
e.printStackTrace();
}
}
});
catch(InterruptedException e)
{
}
}
});
t1.start();
t2.start();
t1.join();
t2.join();
e
.
p
r
i
n
t
S
t
a
c
k
T
r
a
c
e
(
)
;
}
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);
}
}
}
+ val);
notify();
Thread.sleep(1000);
}
}
}
}
}
OUTPUT: -
VIVA QUESTIONS
Q1. What is the role of producer and consumer in the producer consumer problem?
- In the producer-consumer problem, the role of the producer is to generate data or items, while the role
of the consumer is to consume or process those items.
CODE: -
public class Program1 {
OUTPUT: -
Experiment 12
AIM: - Write a Program where it may or may not print counter value in sequence and every
time we run it, it produces a different result based on CPU availability to a thread.
CODE: -
import java.util.concurrent.atomic.AtomicInteger;
@Override
public void run() {
// Perform some calculations or tasks
for (int i = 0; i < 10; i++) {
// Get the current value of the counter
int currentValue = counter.get();
}
}
}
}
OUTPUT: -
Experiment 13
AIM: - Two polynomials are entered by the user in the form of : ax2 + bx + c where the powers
of x can be any integer value and a,b& c are constants. Now WAP in C and JAVA which
calculates the sum, product and difference of the two polynomials.
CODE: -
C program:
#include <stdio.h>
int main() {
int a1, b1, c1; // Coefficients of the first polynomial
int a2, b2, c2; // Coefficients of the second polynomial
printf("Enter the coefficients of the first polynomial (a1x^2 + b1x + c1): ");
scanf("%d %d %d", &a1, &b1, &c1);
printf("Enter the coefficients of the second polynomial (a2x^2 + b2x + c2): ");
scanf("%d %d %d", &a2, &b2, &c2);
Java program:
import java.util.Scanner;
System.out.print("Enter the coefficients of the first polynomial (a1x^2 + b1x + c1): ");
int a1 = scanner.nextInt();
int b1 = scanner.nextInt();
int c1 = scanner.nextInt();
System.out.print("Enter the coefficients of the second polynomial (a2x^2 + b2x + c2): ");
int a2 = scanner.nextInt();
int b2 = scanner.nextInt();
int c2 = scanner.nextInt();
OUTPUT: -
Experiment 14
AIM: - In June a baseball team that played 60 games had won 30% of its game played. After
a phenomenal winning streak this team raised its average to 50% . WAP which calculates how
many games must the team have won in a row to attain this average.
CODE: -
OUTPUT:
Experiment 15
AIM: - A company contracts to paint 3 houses. Mr. Brown can paint a house in 6 days while
Mr. Black would take 8 days and Mr. Blue 12 days. After 8 days Mr. Brown goes on vacation
and Mr. Black begins to work for a period of 6 days. Write a program in java which calculates
how days will it take Mr. Blue to complete the contract.
CODE: -
// Calculate the remaining work to be done after Mr. Black starts working
remainingWork -= blackWork;
// Calculate the number of days Mr. Blue will take to complete the remaining work
int blueDays = remainingWork * blueRate;
System.out.println("Mr. Blue will take " + blueDays + " days to complete the contract.");
}
}
OUTPUT: