Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: December 2022

Saturday, December 31, 2022

ICSE Java Programming Array of Integers 2022 Q2 Specimen Paper Solved

 ICSE Java Programming Array of Integers 2022 Q2 Solved





import java.util.Scanner;

public class ICSEJava2022 {
    public static void main(String[] args) {
        int N, s;
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the size of the array:");
        N = in.nextInt();
        ArraySearch obj = new ArraySearch(N);
        obj.inputElements(in);
        System.out.println("Enter the name to be searched:");
        s = in.nextInt();
        obj.searchElement(s);
        in.close();
    }
}

class ArraySearch {
    public void searchElement(int s) {
        boolean flag = false;
        for (int i = 0; i < this.array_size; i++) {
            if (s == this.array[i]) {
                System.out.println("The entered element is at position " + (i + 1));
                flag = true;
            }
        }
        if (!flag)
            System.out.println("The entered element is not present in the array.");
    }

    public void inputElements(Scanner in) {
        System.out.println("Enter the elements of the array:");
        for (int i = 0; i < this.array_size; i++) {
            System.out.println("Enter the element at position:" + (i + 1));
            this.array[i] = in.nextInt();
        }
    }

    ArraySearch(int N) {
        this.array_size = N;
        this.array = new int[this.array_size];
    }

    private static int array_size;
    private int[] array;
}

ICSE Specimen paper 2023 Computer Application

 



Friday, December 30, 2022

ICSE Java Programming Array of Strings 2023 Q8 SPECIMEN PAPER Solved

ICSE Java Programming Array of Strings 2023 Q8 SPECIMEN PAPER solved


Define a class to accept the names of 10 students in an array and check for the existence of the given name in the array using linear search, if found print the position of the name, if not found print the appropriate message. Also print the names which begins with the word "SRI".






import java.util.Scanner;

public class ICSEJava2023 {
    public static void main(String[] args) {
        String s = "";
        Scanner in = new Scanner(System.in);
        Name obj = new Name();
        obj.inputNames();
        System.out.println("Enter the name to be searched:");
        s = in.nextLine();
        obj.searchName(s);
        obj.checkName();
        in.close();
    }
}

class Name {
    public void checkName() {
        for (int i = 0; i < this.total_students; i++) {
            if (this.names[i].charAt(0) == 'S' && this.names[i].charAt(1) == 'R' && this.names[i].charAt(2) == 'I')
                System.out.println(this.names[i] + " begins with SRI");
        }
    }
    public void inputNames() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the names:");
        for (int i = 0; i < this.total_students; i++) {
            System.out.println("Enter the name at position:" + (i + 1));
            this.names[i] = in.nextLine();
        }
    }
    public void searchName(String sname) {
        boolean flag = false;
        for (int i = 0; i < this.total_students; i++) {
            if (sname.equals(this.names[i])) {
                System.out.println("Position of the entered name in the array is: " + (i + 1));
                flag = true;
                break;
            }
        }
        if (flag == false)
            System.out.println("Name not found in the list");
    }
    Name() {
        this.names = new String[this.total_students];
    }
    private static int total_students = 10;
    private String[] names;
}

ICSE Java Programming Vowels in a String 2023 Q7 SPECIMEN PAPER

ICSE Java Programming Vowels in a String 2023 Q7 SPECIMEN PAPER

Question 7

Define a class to accept a string and print the same in reverse, also print the number of vowels in the string.

Eg:S="BEAUTIFUL"

Output - "LUFITUAEB" No. of vowels = 5


JAVA CODE ICSE Java programming Solved



import java.util.Scanner;

public class ICSEJava2023 {
    public static void main(String[] args) {
        StringReverse obj = new StringReverse();
        obj.inputString();
        obj.display();
    }
}

class StringReverse {
    public void inputString() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a word:");
        this.message = in.nextLine();
        in.close();
    }

    public void display() {
        char[] c = new char[this.message.length()];
        System.out.println("Output");
        for (int i = 0; i < this.message.length(); i++) {
            System.out.print(this.message.charAt(this.message.length() - 1 - i));
            c[i] = this.message.charAt(i);
            if (c[i] >= 'a' || c[i] <= 'z')
                c[i] = (char) (c[i] - 32);
            for (int j = 0; j < 5; j++) {
                if (c[i] == this.vowels[j])
                    this.number_of_vowels++;
            }
        }
        System.out.println();
        System.out.println("No. of vowels:" + this.number_of_vowels);
    }
    StringReverse() {
        this.number_of_vowels = 0;
        this.message = "";
    }

    private int number_of_vowels;
    private String message;
    private static char[] vowels = { 'A', 'E', 'I', 'O', 'U' };
}

ICSE Java Programming Range of Array 2023 Q6 SPECIMEN PAPER

ICSE Java Programming Range of Array 2023 Q6 SPECIMEN PAPER

Range of array in java example.






import java.util.Scanner;

public class ICSEJava2023 {
    public static void main(String[] args) {
        Range obj = new Range();
        obj.inputArray();
        System.out.println("Original Array;");
        obj.display();
        obj.sortArray();
        }
}

class Range {
    public void sortArray() {
        for (int i = 0; i < this.array_size - 1; i++)
            for (int j = 0; j < this.array_size - i - 1; j++)
                if (this.array[j] < this.array[j + 1]) {
                    double temp = this.array[j];
                    this.array[j] = this.array[j + 1];
                    this.array[j + 1] = temp;
                }
        System.out.println("Range of the array is:"+(this.array[0]-this.array[this.array_size-1]));
    }

    public void inputArray() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the elements of the array:");
        for (int i = 0; i < this.array_size; i++) {
            System.out.println("Enter the element:");
            this.array[i] = in.nextDouble();
        }
        in.close();
    }

    public void display() {
        for (int i = 0; i < this.array_size; i++)
            System.out.print(this.array[i] + " ");
        System.out.println();
    }
    Range() {
        this.range = 0;
    }
    private double[] array = new double[20];
    private double range;
    private static int array_size = 20;
}

ICSE Java Programming Bubble Sort 2023 Q5 SPECIMEN PAPER

ICSE Java Programming Bubble Sort 2023 Q5 SPECIMEN PAPER

Bubble sort in java.




import java.util.Scanner;

public class ICSEJava2023 {
    public static void main(String[] args) {
        BubbleSort obj = new BubbleSort();
        obj.inputArray();
        System.out.println("Original Array;");
        obj.display();
        obj.sortArray();
        System.out.println("Sorted Array;");
        obj.display();
    }
}

class BubbleSort {
    public void sortArray() {
        for (int i = 0; i < this.array_size - 1; i++)
            for (int j = 0; j < this.array_size - i - 1; j++)
                if (this.array[j] < this.array[j + 1]) {
                    int temp = this.array[j];
                    this.array[j] = this.array[j + 1];
                    this.array[j + 1] = temp;
                }
    }

    public void inputArray() {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the elements of the array:");
        for (int i = 0; i < this.array_size; i++) {
            System.out.println("Enter the element:");
            this.array[i] = in.nextInt();
        }
        in.close();
    }

    public void display() {
        for (int i = 0; i < this.array_size; i++)
            System.out.print(this.array[i] + " ");
        System.out.println();
    }

    private int[] array = new int[10];
    private static int array_size = 10;
}

ICSE Java Programming Function Overloading 2023 Q4 SPECIMEN PAPER

ICSE Java Programming  2023 Q3 SPECIMEN PAPER Solved.


Question 4

Define a class to overload the method print as follows:

void print ()-to print the format

1

2 3

4 5 6

7 8 9 10

boolean print (int n) -

to check whether the number is a Dudeney number,a number is dudeney if the cube of the sum of the digits is equal to the number itself.

Eg: 512(5+1+2)3 = (8)3 = 512

void print (int a, char ch) -

if ch = s or S print the square of the number else if

ch=c or C print the cube of the number.

Function Overloading in java example.




import java.util.Scanner;
public class ICSEJava2023 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        FunctionOverloading obj = new FunctionOverloading();
        int choice = 0;
        int n;
        char ch;
        System.out.println("Press 1 to print the format:");
        System.out.println("Press 2 to check for Dudeney number:");

        System.out.println("Press 3 to print the square or cube:");
        choice = in.nextInt();
        switch (choice) {
            case 1:
                obj.print();
                break;
            case 2:
                System.out.println("Enter the number:");
                n = in.nextInt();
                if (obj.print(n) == true)
                    System.out.println(" It's a Dudeney numer");
                else
                    System.out.println(" It's not a Dudeney numer");
                break;
            case 3:
                System.out.println("Enter the number:");
                n = in.nextInt();
                System.out.println("Enter the character (c/C or s/S):");
                ch = in.next().charAt(0);
                System.out.println("Enter the height of the cuboid:");
                obj.print(n, ch);
                break;
            default:
                System.out.println("Wrong Choice!");
                break;
        }
        in.close();
    }
}

class FunctionOverloading {
    public void print() {
        int counter = 1;
        for (int i = 1; i <= 4; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print((counter++) + " ");
            }
            System.out.println();
        }
    }

    public boolean print(int n) {
        int sum = 0;
        int temp;
        temp = n;
        while (temp > 0) {
            sum += temp % 10;
            temp /= 10;
        }
        if (sum * sum * sum == n)
            return (true);
        else
            return (false);
    }

    public void print(int a, char ch) {
        if (ch == 's' || ch == 'S')
            System.out.println(a * a);
        else if (ch == 'c' || ch == 'C')
            System.out.println(a * a * a);
        else
            System.out.println("Invalid input!");
    }
}

ICSE Java Programming Class employee 2023 Q3 SPECIMEN PAPER

 ICSE Java Programming Class employee 2023 Q3 SPECIMEN PAPER Solved.




import java.util.Scanner;

public class ICSEJava2023 {
    public static void main(String[] args) {
        employee obj = new employee();
        obj.accept();
        obj.calculate();
        obj.print();
    }
}

class employee {
    public void print() {
        System.out.println("Details of the employee:");
        System.out.println("Employee number:" + eno);
        System.out.println("Employee name:" + ename);
        System.out.println("Age of the employee:" + age);
        System.out.println("Basic pay of the employee:" + basic);
        System.out.println("Net pay of the employee:" + net);
    }

    public void calculate() {
        if (this.age > 50)
            this.net = allowance + (basic + (hra * basic + da * basic - pf * basic) / 100f);

        else
            this.net = basic + (hra * basic + da * basic - pf * basic) / 100f;

    }

    public void accept() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the employee number:");
        eno = in.nextInt();
        System.out.print("Enter the employee name:");
        ename = in.nextLine();
        in.nextLine();
        System.out.print("Enter the age of the employee:");
        age = in.nextInt();
        System.out.print("Enter the basic pay of the employee:");
        basic = in.nextFloat();
        in.close();
    }

    employee() {
        this.eno = 0;
        this.ename = "";
        this.age = 0;
        this.basic = 0;
        this.net = 0;
    }
    private int eno;
    private String ename;
    private int age;
    private float basic;
    private float net;
    private static float hra = 18.5f;
    private static float da = 17.45f;
    private static float pf = 8.10f;
    private static float allowance = 5000f;
}

Thursday, December 29, 2022

ICSE Java Programming Average Marks 2018 Q9

Question 9.
Write a program to accept name and total marks of N number of students in two single subscript array name[] and
totalmarks[ ].  
Calculate and print:
(i) The average of the total marks obtained by N Number of students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average.

[deviation = total marks of a student – average] 



import java.util.Scanner;

public class ICSEJava2018 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] name;
        float[] totalmarks;
        int N;
        float averageMarks = 0;
        System.out.println("Enter the number of students:");
        N = in.nextInt();
        in.nextLine();
        name = new String[N];
        totalmarks = new float[N];
        for (int i = 0; i < N; i++) {
            name[i] = "";
            System.out.print("Enter the name of student:");
            name[i] = in.nextLine();
            System.out.print("Enter the total marks of " + name[i] + ":");
            totalmarks[i] = in.nextFloat();
            in.nextLine();
            averageMarks += totalmarks[i];
        }
        System.out.println("The average of the total marks obtained by N Number of students:" + averageMarks / N);
        for (int j = 0; j < N; j++)
            System.out.println("Deviation for " + name[j] + "=" + (totalmarks[j] - (averageMarks / N)));
        in.close();

    }
}

ICSE Java Programming Pattern Print 2018 Q8

Question 8.
Write a menu driven program to display the pattern as per user’s choice.
ICSE Computer Applications Question Paper 2018 Solved for Class X
For an incorrect option, an appropriate error message should be displayed.



import java.util.Scanner;

public class ICSEJava2018 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int choice = 0;
        char[] array1 = { 'A', 'B', 'C', 'D', 'E' };
        char[] array2 = { 'B', 'L', 'U', 'E' };
        System.out.println("Press 1 to generate the first pattern:");
        System.out.println("Press 2 to generate the second pattern::");
        System.out.println("Enter your choice:");
        choice = in.nextInt();
        switch (choice) {
            case 1:
                for (int i = 0; i < 5; i++) {
                    for (int j = 5 - i; j >= 1; j--) {
                        System.out.print(array1[5 - j]);
                    }
                    System.out.println();
                }
                break;
            case 2:
                int counter = 0;
                for (int i = 1; i <= 4; i++) {
                    for (int j = 1; j <= i; j++) {
                        System.out.print(array2[counter]);
                    }
                    counter++;
                    System.out.println();
                }
                break;
            default:
                System.out.println("WRONG CHOICE!:");
                break;
        }
    in.close();
    }
}

 

ICSE Java Programming Function Overload 2018 Q7

Question 7.

Design a class to overload a function volume() as follows : 

(i) double volume (double R) — with radius (R) as an argument, returns the volume of sphere using the formula.

V = 4/3 × 22/7 × R3

(ii) double volume (double H, double R) – with height(H) and radius(R) as the arguments, returns the volume of a cylinder using the formula.

V = 22/7 × R2 × H

(iii) double volume (double L, double B, double H) – with length(L), breadth(B) and Height(H) as the arguments, returns the volume of a cuboid using the formula.





import java.util.Scanner;

public class ICSEJava2018 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        VolumeOfObjects obj = new VolumeOfObjects();
        int choice = 0;
        double R = 0, H = 0, B = 0;
        System.out.println("Press 1 to calculate the volume of a sphere:");
        System.out.println("Press 2 to calculate the volume of a cylinder:");
        System.out.println("Press 3 to calculate the volume of a cuboid:");
        choice = in.nextInt();
        switch (choice) {
            case 1:
                System.out.println("Enter the radius of the sphere:");
                R = in.nextDouble();
                System.out.println("Volume of the sphere:" + obj.volume(R)+" cubic units");
                break;
            case 2:
                System.out.println("Enter the radius of the cylinder:");
                R = in.nextDouble();
                System.out.println("Enter the height of the cylinder:");
                H = in.nextDouble();
                System.out.println("Volume of the cylinder:" + obj.volume(H, R)+" cubic units");
                break;
            case 3:
                System.out.println("Enter the length of the cuboid:");
                R = in.nextDouble();
                System.out.println("Enter the breadth of the cuboid:");
                H = in.nextDouble();
                System.out.println("Enter the height of the cuboid:");
                B = in.nextDouble();
                System.out.println("Volume of the cylinder:" + obj.volume(R, H,B)+" cubic units");
                break;
            default:
                System.out.println("Wrong Choice!");
                break;
        }
    in.close();
    }
}

class VolumeOfObjects {
    public double volume(double R) {
        return (4 * 22 * R * R * R) / (21);
    }

    public double volume(double H, double R) {
        return (22 * R * R * H) / 7;
    }

    public double volume(double L, double B, double H) {
        return (L * B * H);
    }

}