Class Xii Computer Science Project Work
Class Xii Computer Science Project Work
COMPUTER SCIENCE
PROJECT WORK.
Name-Sreyan Saha
Class-12
Section-C
Roll No.-36
Subject-Computer Science
S.No
TOPIC Page No.
1 Program to check 4
Automorphic or Disarium
4 Stack operations 13
5 Queue operations 18
6 22
Circular queue operations
7 Date adder program 28
10 35
Decimal to octal and hexadecimal
13 45
Convert a matrix to spiral form
14 48
Sentence operation program
Program Coding:
import java.util.Scanner;
switch (choice) {
case 1:
// Check if the number is Automorphic
if (isAutomorphic(num)) {
System.out.println(num + " is an Automorphic number.");
} else {
System.out.println(num + " is not an Automorphic number.");
}
break;
case 2:
// Check if the number is Disarium
if (isDisarium(num)) {
System.out.println(num + " is a Disarium number.");
} else {
System.out.println(num + " is not a Disarium number.");
}
break;
default:
System.out.println("Invalid choice."); // Handle invalid choice
}
return sum == num; // Check if the sum is equal to the original number
}
}Output:
Program Coding:
import java.util.Scanner;
if (isPrime(matrix[i][j])) primeCount++;
if (isArmstrong(matrix[i][j])) armstrongCount++;
if (isPerfect(matrix[i][j])) perfectCount++;
return true;
temp /= 10;
int sum = 0;
if (num % i == 0) sum += i;
Variable Glossary:
sum int The sum used in Armstrong and perfect number checks.
Program Coding:
import java.util.Scanner;
Output:
Variable Glossary:
product int[][] The matrix to store the product of the two matrices.
import java.util.Scanner;
while (true) {
System.out.println("\nChoose an operation:");
System.out.println("1. Display Stack");
System.out.println("2. Pop");
System.out.println("3. Peek");
System.out.println("4. Search");
System.out.println("5. Exit");
int choice = scanner.nextInt();
switch (choice) {
case 1:
// Displaying stack
System.out.print("Stack: ");
for (int i = 0; i <= top; i++) {
System.out.print(stack[i] + " ");
}
System.out.println();
break;
case 2:
// Pop operation
if (top >= 0) {
System.out.println("Popped element: " + stack[top--]);
} else {
System.out.println("Stack is empty.");
}
break;
case 3:
// Peek operation
if (top >= 0) {
System.out.println("Top element: " + stack[top]);
} else {
System.out.println("Stack is empty.");
case 4:
// Search operation
System.out.println("Enter a name to search:");
String searchName = scanner.nextLine();
int position = -1;
for (int i = 0; i <= top; i++) {
if (stack[i].equals(searchName)) {
position = i;
break;
}
}
if (position != -1) {
System.out.println(searchName + " found at position: " + (position
+ 1));
} else {
System.out.println(searchName + " not found in the stack.");
}
break;
case 5:
// Exit
System.out.println("Exiting...");
return;
import java.util.Scanner;
while (true) {
System.out.println("\nChoose an operation:");
System.out.println("1. Display Queue");
System.out.println("2. Dequeue");
System.out.println("3. Peek");
System.out.println("4. Search");
System.out.println("5. Exit");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
// Displaying queue
System.out.print("Queue: ");
for (int i = front; i <= rear; i++) {
System.out.print(queue[i] + " ");
}
System.out.println();
18|Computer Science|Class XII Sreyan Saha|12C
break;
case 2:
// Dequeue operation
if (front <= rear) {
System.out.println("Dequeued element: " + queue[front++]);
if (front > rear) {
front = rear = -1; // Reset queue if empty
}
} else {
System.out.println("Queue is empty.");
}
break;
case 3:
// Peek operation
if (front <= rear) {
System.out.println("Front element: " + queue[front]);
} else {
System.out.println("Queue is empty.");
}
break;
case 4:
// Search operation
System.out.println("Enter a name to search:");
String searchName = scanner.nextLine();
int position = -1;
for (int i = front; i <= rear; i++) {
if (queue[i].equals(searchName)) {
position = i;
break;
}
}
if (position != -1) {
System.out.println(searchName + " found at position: " + (position - front +
1));
} else {
System.out.println(searchName + " not found in the queue.");
}
break;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}
Output:
Program Coding:
import java.util.Scanner
} else {
if (front == -1) {
front = 0;}
}}
while (true) {
System.out.println("\nChoose an operation:");
System.out.println("2. Dequeue");
System.out.println("3. Peek");
System.out.println("4. Search");
System.out.println("5. Exit");
switch (choice) {
case 1:
// Displaying queue
System.out.print("Queue: ");
if (front == -1) {
System.out.println("Queue is empty.");
} else {
int i = front;
while (true) {
if (i == rear) break;
i = (i + 1) % size;
System.out.println();
case 2:
// Dequeue operation
if (front == -1) {
System.out.println("Queue is empty.");
} else {
if (front == rear) {
} else {
}}
break
if (front == -1) {
System.out.println("Queue is empty.");
} else {
break;
case 4:
// Search operation
if (front != -1) {
int i = front;
while (true) {
if (queue[i].equals(searchName)) {
position = i;
break;
if (i == rear) break;
i = (i + 1) % size;
}}
if (position != -1) {
} else {
break;
case 5:
// Exit
System.out.println("Exiting...");
25|Computer Science|Class XII Sreyan Saha|12C
return;
default:
}}}}}
Output:
Program Coding:
import java.util.Scanner;
public class DateAdder1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Accepting the date from the user
System.out.println("Enter the date (dd mm yyyy):");
int day = scanner.nextInt();
int month = scanner.nextInt();
int year = scanner.nextInt();
// Accepting the number of days to add
System.out.println("Enter the number of days to add:");
int daysToAdd = scanner.nextInt();
// Adding days to the date
int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// Adjust for leap year
if (isLeapYear(year)) {
daysInMonth[1] = 29;
}
day += daysToAdd;
while (day > daysInMonth[month - 1]) {
day -= daysInMonth[month - 1];
month++;
if (month > 12) {
month = 1;
year++;
if (isLeapYear(year)) {
daysInMonth[1] = 29;
28|Computer Science|Class XII Sreyan Saha|12C
} else {
daysInMonth[1] = 28;
}
}
}
Output:
Output:
Variable glossary:
Program Coding:
import java.util.Scanner;
if (firstVowelIndex == -1) {
return word + "ay";
} else if (firstVowelIndex == 0) {
return word + "yay";
Output:
Variable Glossary:
Program coding:
import java.util.Scanner;
OUTPUT:
Program coding:
import java.util.Scanner;
// Check Wondrous
int nSq = n * n;
double validSum = 0.5 * n * (nSq + 1);
boolean wondrous = isWondrous(a);
if (wondrous) {
seenArr[arr[i][j] - 1] = true;
rSum += arr[i][j];
cSum += arr[j][i];
}
return c == 2;
}}
OUTPUT:
Program coding:
import java.util.Scanner;
// If the sums of the diagonals are not equal, it's not a magic square
if (sumDiagonal1 != sumDiagonal2) {
return false;
}
Variable Glossary:
import java.util.Scanner;
Variable Glossary:
import java.util.Scanner;
Variable Glossary:
import java.util.Scanner;
Variable Glossary:
****************************The End****************************