0% found this document useful (0 votes)
6 views30 pages

Is C Computer

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)
6 views30 pages

Is C Computer

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/ 30

KUSHAL MEHRA

XII – J
ROLL NUMBER: 22
ISC 2026
COMPUTER PROJECT
Q1) DESIGN A PROGRAM WHICH ACCEPTS
YOUR DATE OF BIRTH IN DD MM YYYY
FORMAT. CHECK WHETHER THE DATE
ENTERED IS A VALID DATE OR NOT. IF VALID
DISPLAY THE TOTAL NUMBER OF DAYS

ALGORITHM: To check if a given date is valid


and calculate the day number of the year.

Step 1: Start
Step 2: Initialize an array a with the number
of days in each month:
a = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,
31}
Step 3: Declare variables d (day), m (month),
y (year), s (sum), and i (loop counter)
Step 4: Input the values of d, m, and y
Step 5: Set s = 0
Step 6: If the year y is a leap year (i.e., y % 4
== 0), then set a[1] = 29
Step 7: If m>12 or d>a[m-1], then
Print "INVALID DATE"
Step 8: Else
Print "VALID DATE" and total number of days
Step 9: End
Program:

Output:
Variable description table (VDT):

Variab Data Purpose / Description


le Type
a int[] Array storing number of days in
each month
d int Day input by the user
m int Month input by the user
y int Year input by the user
s int Stores total number of days from
January 1st
i int Loop counter used to traverse the
array a
br Scanner Scanner object used to read input
from the user
Q2) A Smith number is a composite number,
whose sum of the digits is equal to the sum
of its prime factors. (For example: 4, 22, 27,
58, 85, 94, 121 ………. are Smith numbers).
Write a program in Java to enter a number
and check whether it is a Smith number or
not.

ALGORITHM: To find the smith number.


Step 1: Start
Step 2: Input number n
Step 3: If n <= 0, print "Not a Smith
Number" and stop
Step 4: Check if n is a composite number
• If not, print "Not a Smith Number" and stop
Step 5: Calculate the sum of digits of n and
store in sumDigits
Step 6: Initialize sumPrimeDigits = 0
Step 7: Factorize the number n into prime
factors
• For each prime factor, add the sum of its
digits to sumPrimeDigits
Step 8: If sum of digits of prime factors
equals sumDigits, print "Smith Number"
• Else, print "Not a Smith Number"
Step 9: End

PROGRAM:
OUTPUT:

VARIABLE DESCRIPTON TABLE (VDT):


Variable Data Purpose / Description
Type
in Scanne Scanner object for user input
r
n int Number input by the user
isComposite boolea Flag to check if number is
n composite
i int Loop counter used in various
loops
sumDigits int Sum of digits of the original
number
sumPrimeDigi int Sum of digits of prime factors of
ts the number
t int Temporary variable for
manipulating number or factors
d int Stores individual digits while
extracting
temp int Temporary variable for storing
and breaking prime factors
Q8) Find the sum of numbers larger than
a number in an int array using
Recursion.

ALGORITHM: To find the sum of numbers


greater than first Number in a subarray using
recursion:
Step 1: Start
Step 2: Input array elements, integers
startIndex, endIndex, and firstNumber
Step 3: Initialize count = 0
Step 4: If startIndex == endIndex, then
→ If elements[startIndex] > firstNumber, add
elements[startIndex] to count
→ Return count
Step 5: Else
→ If elements[endIndex] > firstNumber, add
elements[endIndex] to count
→ Add the result of the recursive call
sumOfNumbersLargerThanFirst(elements,
startIndex, endIndex - 1, firstNumber) to count
→ Return count
Step 6: End
PROGRAM:
OUTPUT:

VARIABLE DESCRIPTION TABLE (VDT):


Variable Data Purpose / Description
Type
elements int[] The array of integers
startIndex int Starting index of the subarray to be
checked
endIndex int Ending index of the subarray to be
checked
firstNumb int Number to compare each element with
er
count int Stores sum of numbers greater than
firstNumber
Q4) A class DeciOct has been defined to
convert a decimal number into its equivalent
octal number. Some of the members of the
class are given below.
Class name : DeciOct
Data members / instance variables:
 n - stores the decimal number
 oct - stores the octal equivalent number
Member functions:
 DeciOct(): constructor to initialize the data members n = 0, oct=0
 void getnum(int nn): assign nn to n
 void deci_oct(): calculates the octal equivalent of 'n' and stores it in oct
using the Recursive Technique
 void show () : displays the decimal number 'n', calls the function deci_oct()
and displays its octal equivalent.
Also define a main () function to create an object and call the
functions accordingly to enable the task.

ALGORITHM: To convert a decimal


number to octal using recursion.
Step 1: Start
Step 2: Create an object of the class
Step 3: Input a decimal number n
Step 4: If n == 0, set oct = "0"
Step 5: Else, call recursive method decioct(n)
Step 6: In the decioct(p) method:
• If p > 0, recursively call decioct(p / 8)
• Append (p % 8) to the string oct
Step 7: After recursion ends, display the final octal
value stored in oct
Step 8: End
PROGRAM:
OUTPUT:

VARIABLE DESCRIPTION TABLE (VDT):


Variab Data Purpose / Description
le Type
n int Stores the decimal number entered by
the user
oct String Stores the resulting octal number as a
string
ob Scanne Scanner object to take user input
r
p int Local parameter used in recursion for
octal conversion
Q5) Define a class SUPPLY in Java with the
following :
 Data Members are:
 int type
 String FoodName
 String Sticker
 String FoodType.
 Member Functions:
 A member function GetType(): to assign the following values for FoodType as per the
given sticker:

 A function FoodIn(): to allow user to enter values for Code, FoodName, Sticker and
call function GetType() to assign respective FoodType.
 A function FoodOut(): to allow user to view the content of all the data members.

ALGORITHM: To determine food type from


sticker color
Step 1: Start
Step 2: Create a SUPPLY class with variables: Code,
FoodName, Sticker, FoodType
Step 3: In the method FoodIn()
• Accept user input for Code, FoodName, and Sticker
• Call GetType() method
Step 4: In GetType() method:
• If Sticker == "Green" → Set FoodType = "Vegetarian"
• If Sticker == "Yellow" → Set FoodType = "Contains Egg"
• If Sticker == "Red" → Set FoodType = "Non Vegetarian"
Step 5: In method FoodOut()
• Display all values of Code, FoodName, Sticker, and FoodType
Step 6: In main(), create an object of class SUPPLY
• Call FoodIn() and FoodOut()
Step 7: End
PROGRAM:
OUTPUT:

VARIABLE DESCRIPTION TABLE (VDT):


Variable Data Purpose / Description
Type
Code int Stores the numeric code of the food item
FoodName String Stores the name of the food item
Sticker String Stores the color of the sticker on the
food item
FoodType String Stores the category of food determined
from the sticker
sc Scanner Scanner object for taking user input
ob SUPPLY Object of the SUPPLY class used in the
main() method
Q6) Create a class employee which accepts
name, year of joining, salary and address of
three employees. Now display the output as
follows:

ALGORITHM: for EmployeeData Program


Step 1: Start
Step 2: Define a class Details with data members:
Name, Yoj, and Address
Step 3: Create a constructor to initialize the data
members with the given values
Step 4: Define a method DisplayInfo() to display
the employee details in a formatted way
Step 5: In the EmployeeData class (main class),
create three objects of class Details with specific
values
Step 6: Print the header line: “Name Year of
Joining Address”
Step 7: Call the DisplayInfo() method for each
object to print their details
Step 8: End
PROGRAM:
OUTPUT:
VARIABLE DESCRIPTION TABLE (VDT):
Variable Data Description
Name Type
Name String Stores the name of the employee
Yoj String Stores the year of joining of the
employee
Address String Stores the address of the employee
n int Stores the number of employees to
be entered by the user
i int Loop counter used to iterate
through employee entries
emp Details[ An array of Details objects to store
] each employee's data
sc Scanner Used to take input from the user
Q7) Write a menu-driven program in Java
to perform operations on a Double
Ended Queue (Dequeue) using an array.
ALGORITHM: Dequeue
Main Flow:
1.Start program and initialize front (f) and rear
(r) as -1.
2.Display menu to the user:
a.'P' to Push (insert element)
b.'D' to Pop (remove element)
c. 'Q' to Quit
3.Based on user choice, do the following:
a.Push:
i. Ask for location: front or rear.
ii. Ask for value to insert.
iii. If inserting at front, shift elements and
insert.
iv. If inserting at rear, insert at next
position.
b.Pop:
i. Ask for location: front or rear.
ii. Remove the element from that side.
iii. Adjust front/rear pointers accordingly.
c. Display: Show current queue contents.
4.Loop until user presses 'Q'.
PROGRAM:
OUTPUT:

VARIABLE DESCRIPTION TABLE (VDT):


Variabl Data Type Description
e
arr int[] Array to hold deque elements
(size 10)
f int Front index of the deque
r int Rear index of the deque
i int Loop variable for shifts
n int Value to be inserted into the
deque
str String Stores whether user chose "front"
or "rear"
br BufferedReade Used for taking input from the
r user
op char User's selected operation:
push/pop/quit
ob dequeue Object of the class to access
methods

Q8) Write a program in java to create


a linked list and let the user enter
values.
ALGORITHM: linked list
1. Start
2. Create a Scanner object for input.

3. Prompt the user to enter a name for the

list.
4. Store the list name in a String variable.

5. Create an empty LinkedList of type

String.
6. Display instructions to the user: they can

enter items or type 'N'/'n' to stop.


7. Repeat:

8. Ask the user to enter a string item.

9. If the input is 'N' or 'n', exit the loop.

10. Otherwise, add the item to the


LinkedList.
11. After the loop ends, print the list
name and all items in the LinkedList.
12. End
PROGRAM:
OUTPUT:
VARIABLE DESCRIPTION TABLE (VDT):
Variabl Data Description
e Name Type
sc Scanner Used to take input from the user.
listNam String Stores the name of the list given by
e the user.
list LinkedLis Stores all the string items entered by
t<String> the user.
input String Stores each item input by the user in
each iteration.

You might also like