0% found this document useful (0 votes)
15 views

Ilovepdf - Merged (

The document describes an experiment to implement concepts related to trees. It includes the aim, objectives, and code to solve two problems - checking if two binary trees are the same and finding the lowest common ancestor of two nodes in a binary tree.

Uploaded by

privyanshu rajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Ilovepdf - Merged (

The document describes an experiment to implement concepts related to trees. It includes the aim, objectives, and code to solve two problems - checking if two binary trees are the same and finding the lowest common ancestor of two nodes in a binary tree.

Uploaded by

privyanshu rajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 2.1

Student Name:Privyanshu Rajan UID: 21BCS4742


Branch: CSE Section/Group: SC-902-A
Semester: 6 Date of Performance: February 8,2024
Subject: Mobile Application Development with Lab
Subject Code: 21CSH-355

1. Aim:
To create an Android app that uses Intent and one button to create a page and passes values
from one activity to another.

2. Objective:
The objective of this experiment is to understand the concept of Intents in Android app
development and learn how to pass data between different activities within an application.
By implementing this, students will grasp the fundamental mechanism of interactivity and
data exchange in Android apps.

3. Apparatus/Requirements:
Android Studio installed and configured.
Android device or emulator for testing the application.

4. Procedure:
1. Launch Android Studio and create a new Android project.
2. Design the user interface with at least one Button.
3. Implement an OnClickListener for the Button to handle user clicks.
4. Within the OnClickListener, create an Intent to switch to another activity.
5. Pass values from the current activity to the destination activity using Intent extras.
6. Retrieve the passed values in the destination activity.
7. Display the received values or perform any desired operation with them.

AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.experiment12">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

android:theme="@style/Theme.Experiment12">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
<activity android:name=".DisplayMessageActivity"></activity>
</application>
</manifest>

MainActivity.java:
package com.example.experiment12;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

EditText editTextName = findViewById(R.id.editTextName);


Button buttonOK = findViewById(R.id.buttonOK);

buttonOK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = editTextName.getText().toString();
if (!name.isEmpty()) {
Intent intent = new Intent(MainActivity.this, DisplayMessageActivity.class);
intent.putExtra("NAME", name); // Pass the name to the next activity
startActivity(intent);
}
}
});
}
}
DisplayMessageActivity.java:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

package com.example.experiment12;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class DisplayMessageActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
String name = getIntent().getStringExtra("NAME");
TextView textViewMessage = findViewById(R.id.textViewMessage);
textViewMessage.setText("Hello, " + name + "!");
}
}

activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/editTextName"
android:layout_width="258dp"
android:layout_height="42dp"
android:layout_centerHorizontal="true"
android:hint="@string/enter_your_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/buttonOK"
android:layout_width="128dp"
android:layout_height="54dp"
android:layout_below="@id/editTextName"
android:layout_centerHorizontal="true"
android:text="OK"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

app:layout_constraintTop_toBottomOf="@+id/editTextName" />

</androidx.constraintlayout.widget.ConstraintLayout>

activity_display_message.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DisplayMessageActivity">
<TextView
android:id="@+id/textViewMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="24sp"/>
</RelativeLayout>

5. Observations/Outcome:
 Successful creation of the user interface with at least one Button.
 Implementation of OnClickListener to handle button clicks.
 Proper usage of Intent to switch between activities.
 Successful passing of values from one activity to another using Intent extras.
 Correct retrieval and utilization of the passed values in the destination activity.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

6. Learning Outcome:
Through this experiment, one will gain practical experience in using Intents for inter-
activity communication and data transfer in Android applications. They will learn how to
navigate between different screens/pages within an app and exchange relevant information,
which is a crucial skill for building interactive and dynamic mobile applications.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment 1. 4
Student Name: Privyanshu Rajan UID: 21BCS4742
Branch: CSE Section/Group:SC-902-A
Semester: 6th Date of Performance: 5/2/24
Subject Name: Advanced Programming lab2 Subject Code: 21CSP-251

1. Aim:
• To Solve Missing Number
• To Solve Word Pattern

2. Objective:
• Given an array nums containing n distinct numbers in the range [0, n], return the
only number in the range that is missing from the array.
Example 1:
Input: nums = [3,0,1]
Output: 2
Explanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the
missing number in the range since it does not appear in nums.
Example 2:
Input: nums = [0,1]
Output: 2
Explanation: n = 2 since there are 2 numbers, so all numbers are in the range [0,2]. 2 is the
missing number in the range since it does not appear in nums.
• Given a pattern and a string s, find if s follows the same pattern.
Here follow means a full match, such that there is a bijection between a letter in
pattern and a non-empty word in s.
Example 1:
Input: pattern = "abba", s = "dog cat cat
dog" Output: true Example 2:
Input: pattern = "abba", s = "dog cat cat
fish" Output: false Example 3:
Input: pattern = "aaaa", s = "dog cat cat dog"
Output: false

3. Script and Output:

Missing Number
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

class Solution { public:


int missingNumber(vector<int>& nums) {
int n = nums.size(); int total =
((n+1)*(n))/2; for(int i=0; i<n; i++){
total = total - nums[i];
}
return total;
}
};

Word Pattern
class Solution { public:
bool wordPattern(string pattern, string s) {
unordered_map<char, int> p2i;
unordered_map<string, int> w2i;
istringstream in(s); string word; int i =
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

0, n = pattern.size(); for(word;
in>>word; i++){
if(i==n || p2i[pattern[i]] != w2i[word])
return false;
p2i[pattern[i]] = w2i[word] = i+1; }
return i==n;}
};
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment 2.1

Student Name: Naresh Yogi UID: 21BCS2178


Branch: BE-CSE Section/Group: 21BCS_FL-601‘A’
Semester: 6th Date of Performance: 16/02/2024
Subject Name: AP Lab - II Subject Code: 21CSP-351

Aim: To implement the concept of Trees.

Objectives: To understand the concept of Trees.


Problem 1: Same Tree | LeetCode

Given the roots of two binary trees p and q, write a function to check if they are the
same or not.
Two binary trees are considered the same if they are structurally identical, and the
nodes have the same value.

Code:

class Solution
{
public boolean isSameTree(TreeNode p, TreeNode q) {
if (p == null || q == null) return p == q;
return p.val == q.val && //
isSameTree(p.left, q.left) && //
isSameTree(p.right, q.right);
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Output:

Problem 2: Symmetric Tree | LeetCode

Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric
around its center).

Code:
class Solution { public boolean
isSymmetric(TreeNode root) { return
isSymmetric(root, root);
}
private boolean isSymmetric(TreeNode p, TreeNode q) {
if (p == null || q == null) return p == q;

return p.val == q.val && isSymmetric(p.left, q.right) &&


isSymmetric(p.right, q.left);
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

}
}

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy