Sunday, October 20, 2019

ISC COMPUTER SCIENCE QUESTION PRACTICAL PAPER 2019 | QUESTION NUMBER 1 | Follow on youtube for more |


                                   


Question 1

Design a program to accept a day number (between 1 and 366), year (in 4 digits) from the user
to generate and display the corresponding date. Also, accept ‘N’ (1 <= N <= 100) from the
user to compute and display the future date corresponding to ‘N’ days after the generated date.
Display an error message if the value of the day number, year and N are not within the limit or
not according to the condition specified.

Test your program with the following data and some random data:

Example 1
INPUT: DAY NUMBER: 255
YEAR: 2018
DATE AFTER (N DAYS): 22
OUTPUT: DATE: 12 TH SEPTEMBER, 2018
DATE AFTER 22 DAYS: 4 TH OCTOBER, 2018

Example 2
INPUT: DAY NUMBER: 360
YEAR: 2018
DATE AFTER (N DAYS): 45
OUTPUT: DATE: 26 TH DECEMBER, 2018
DATE AFTER 45 DAYS: 9 TH FEBRUARY, 2019

Example 3
INPUT: DAY NUMBER: 500
YEAR: 2018
DATE AFTER (N DAYS): 33
OUTPUT: DAY NUMBER OUT OF RANGE.
Example 4

INPUT: DAY NUMBER: 150
YEAR: 2018
DATE AFTER (N DAYS): 330
OUTPUT: DATE AFTER (N DAYS) OUT OF RANGE.

-----------------------------------------------------CODE-------------------------------------------------------

import java.util.*;
public class qstn_1
{
static int[] daycheck(int day_number, int year)
{

int dd[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  boolean leap = false;
        if(year % 4 == 0)
        {
            if( year % 100 == 0)
            {
                // year is divisible by 400, hence the year is a leap year
                if ( year % 400 == 0)
                    leap = true;
                else
                    leap = false;
            }
            else
                leap = true;
        }
        else
            leap = false;
        if(leap!=false)
        dd[1] = 29;
        int res = day_number;
        int flag = 0;
        int result [] = {0,0};
        while(res>31)
        {
        res = res-dd[flag++];
        }
        result[0] = res;//date
        result[1] = flag++;//month
       return result;
}
static int[] after_check(int day,int day_after,int year,int month)
{
int dd[] = {31,28,31,30,31,30,31,31,30,31,30,31};
  boolean leap = false;
        if(year % 4 == 0)
        {
            if( year % 100 == 0)
            {
                // year is divisible by 400, hence the year is a leap year
                if ( year % 400 == 0)
                    leap = true;
                else
                    leap = false;
            }
            else
                leap = true;
        }
        else
            leap = false;
        if(leap!=false)
        dd[1] = 29;
        int res = day;
        int flag = month--;//as as array index starts from 0
     
     
        int left = dd[flag]-day;
        if(left==day_after)
        day+=dd[flag];
        else if(left<day_after)
        {
        day_after= day_after -left;
        day = dd[flag++];// Giving the maximum day of the month
        }
        else if(left>day_after)
        {
        day +=day_after;// adding the after day to  current day
        day_after = 0;
        }
        int yc = 0;
        //for change in year
        if(flag==12)
        {
        flag=0;
        yc = 1;
        }
   
        while(day_after!=0)
        {
        // if there is a month change so year has to change
        if(flag==11&&day_after!=0)
        {
        flag=0;
        yc = 1;
        }
        // when finally day after is less than the days in that particular month
        if(day_after<dd[flag])
        {
        day = day_after;
        day_after = 0;
        }
        //when day afer is exactly as number of days in month
        else if(day_after==dd[flag])
        {
        day = day_after;
        day_after = 0;
        }
        //when day after is greater than the number of days in month we add the days
        //we subtract the day after from number of days in the month and also
        //add the days for calculation in the current period.
        else if(day_after>dd[flag])
        {
        day = day_after-dd[flag];
        day_after-=dd[flag++];
        }        
        }
        if(yc==1)
        year +=1;
        else
        year = year;
     
        int result[] = new int[3];
        result[0] = day;
        result[1] = flag;// month
        result[2] = year;
        return result;
}
public static void main(String[] args)
{
Scanner sc  = new Scanner(System.in);
System.out.println("Enter the day number");
int n = sc.nextInt();
System.out.println("Enter the year");
int y = sc.nextInt();
System.out.println("Enter the date after (N days) ");
int a = sc.nextInt();
if(n<1 || n>366)
{
System.out.println("DAY NUMBER OUT OF RANGE");
System.exit(0);
}
if(a<1 || a>100)
{
System.out.println("DATE AFTER (N DAYS) OUT OF RANGE");
System.exit(0);
}
String year = Integer.toString(y);
int length = year.length();
if(length!=4)
{
System.out.println("INVALID YEAR");
System.exit(0);
}
int day[] = daycheck(n,y);
//System.out.println(day[0]);
int after[] =after_check(day[0],a,y,day[1]);
String mon1 = "",mon2 ="";
String month[] = {"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};

if(day[0]>3)
{
mon1 = "TH";

}
if( after[0]>3)
{
mon2="TH";
}

if(day[0]==1)
{
mon1 = "ST";

}
if(after[0]==1)
{
mon2 = "ST";
}
if(day[0]==2)
{
mon1 = "ND";

}
if(after[0]==2)
{
mon2 = "ND";
}
if(day[0]==3)
{
mon1 = "RD";

}
if (after[0]==3)
{
mon2 = "RD";
}
// else
// {
// mon1 = "TH";
// mon2 = "TH";
// }
System.out.println(day[0]+" "+mon1+" "+month[day[1]]+","+y );
System.out.println(after[0]+" "+mon2+" "+month[after[1]]+","+after[2]);

}

}


ISC COMPUTER SCIENCE QUESTION PRACTICAL PAPER 2019 | QUESTION NUMBER 3 | Follow on youtube for more |


3. Write a program to accept a sentence which may be terminated by either ‘.’ , ‘?’ or
‘!’ only. The words are to be separated by a single blank space and are in UPPER
CASE.
Perform the following tasks:
(a) Check for the validity of the accepted sentence.

(b) Convert the non-palindrome words of the sentence into palindrome words by
concatenating the word by its reverse (excluding the last character).
Example: The reverse of the word HELP would be LEH (omitting the last
alphabet) and by concatenating both, the new palindrome word is
HELPLEH. Thus, the word HELP becomes HELPLEH.
Note: The words which end with repeated alphabets, for example ABB
would become ABBA and not ABBBA and XAZZZ becomes
XAZZZAX.
[Palindrome word: Spells same from either side. Example: DAD, MADAM etc.]

(c) Display the original sentence along with the converted sentence.
Test your program for the following data and some random data:

Example 1
INPUT: THE BIRD IS FLYING.
OUTPUT: THE BIRD IS FLYING.
THEHT BIRDRIB ISI FLYINGNIYLF

Example 2
INPUT: IS THE WATER LEVEL RISING?
OUTPUT:  IS THE WATER LEVEL RISING?
                  ISI THEHT WATERETAW LEVEL RISINGNISIR

Example 3
INPUT: THIS MOBILE APP LOOKS FINE.
OUTPUT: THIS MOBILE APP LOOKS FINE.
                  THISIHT MOBILELIBOM APPA LOOKSKOOL FINENIF

Example 4 INPUT: YOU MUST BE CRAZY#
OUTPUT: INVALID INPUT

import java.util.*;
public class qstn_2
{
static String palincheck(String word)
{
int flag = 0;
String s1 = "",s2 = "",s3 = "";
String result = "";
// Reversing the word.
for(int i=word.length()-1;i>=0;i--)
{
char c = word.charAt(i);
s1 = s1+c;
}
//Compare the reverse word with original word.
if(s1.equalsIgnoreCase(word))
{
flag=1;
}

//When the word is not palindrome.
if(flag!=1)
{
int l  = word.length();
char last_char = word.charAt(l-1);
int dupli_length = 0;
int count = 0;

//To get the length when the word has repeated
//character ending
for(int i = l-1;i>=0;i--)
{
char c1 = word.charAt(i);
if(last_char==c1)
{
count++;
dupli_length = i;
}
//So that only last repeated character 
else
break;

}
//Change the length when the characters
//have repeated ending.
if(count<=1)
{
dupli_length  = l;
}
//We increase it  by 1 for array indexing purposes.
if(count>1)
{
dupli_length++;
}

for(int i = 0;i<dupli_length-1;i++) // hello hell lleh
{
char c = word.charAt(i);
s2=c+s2;
}
s3 = word+s2;
result = s3;
}
return result;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the sentence");
String s = sc.nextLine();
int l = s.length();
String words[] = new String[100];
String k = "";
int ins = 0;
if(s.charAt(l-1)=='?'||s.charAt(l-1)=='.'||s.charAt(l-1)=='!')
{
for(int i = 0;i<l;i++)
{
char c = s.charAt(i);
if(c==' '||c=='?'||c=='.'||c=='!')
{
words[ins++] = k;
k = "";
}
else 
{
k = k+c;
}
}
for(int i = 0;i<ins;i++)
{
String w = palincheck(words[i]);
words[i] = w;
}
System.out.println(s);
for(int i =0;i<ins;i++)
System.out.print(words[i]+" ");
}
else
System.out.println("INVALID INPUT");
}
}

ICSE COMPUTER SCIENCE SPECIMEN PAPER | QUESTION 7 | PLEASE DO WATCH THE VIDEO

  import  java.util.*; class icse_specimen_1 {     public static void main(String[] args)     {         Scanner sc1 = new Scanner(System.in)...