The Programming Project

Saturday, April 12, 2014

ISC Computer Science Practicals, 2012 Solved


/*
Write a program to accept a sentence as input. The words in the string are to be separated by a blank.
Each word must be in upper case. The sentence is terminated by either '.','!' or '?'.
Perform the following tasks:
1. Obtain the length of the sentence (measured in words)
2. Arrange the sentence in alphabetical order of the words.
Test your program with the sample data and some random data:
Example 1:
INPUT: NECESSITY IS THE MOTHER OF INVENTION.
OUTPUT:
Length: 6
Rearranged Sentence:
INVENTION IS MOTHER NECESSITY OF THE
Example 2:
INPUT: BE GOOD TO OTHERS.
OUTPUT:
Length: 4
Rearranged Sentence: BE GOOD OTHERS TO
*/
// ISC Computer Science Practicals, 2012 


ISC Computer Science Practical Solved, 2011


/*Design a program which accepts your date of birth in dd mm yyyy format. Check whether the date entered is valid or not.
If it is valid, display "VALID DATE", also compute and display the day number of the year for the date of birth.
If it is invalid, display "INVALID DATE" and then terminate the program.
Testing of the program
Input: Enter your date of birth in dd mm yyyy format 05 01 2010
Output: VALID DATE 5
Input: Enter your date of birth in dd mm yyyy format 03 04 2010
Output: VALID DATE 93
Input: Enter your date of birth in dd mm yyyy format 34 06 2010
Output: INVALID DATE */
// ISC Computer Science 2011, Practicals

ISC Computer Science Practical Solved, 2010


/*
Input a paragraph containing 'n' number of sentences where (1<=n<=4). The words are to be separated with single blank space and are in upper case. A sentence may be terminated either with a full stop (.) or question mark (?). Perform the followings:

(i) Enter the number of sentences, if it exceeds the limit show a message.
(ii) Find the number of words in the paragraph
(iii) Display the words in ascending order with frequency.

Example 1:

INPUT:
Enter number of sentences:
1
Enter sentences:
TO BE OR NOT TO BE.

OUTPUT:
Total number of words: 6
WORD FREQUENCY
OR 1
NOT 1
TO 2
BE 2


Example 2:

INPUT: Enter number of sentences:
3
Enter sentences:
THIS IS A STRING PROGRAM. IS THIS EASY? YES, IT IS.

OUTPUT:
Total number of words: 11
WORD FREQUENCY
A                       1
STRING            1
PROGRAM        1
EASY                1
YES                  1
IT                      1
THIS                 2
IS                      3
*/

Friday, April 11, 2014

ISC Computer Science Practical 2013


An ISBN ( International Stanadar Book Number) is a ten digit code which uniquely identifies a book. The first nine digits represent the Group, Publisher and Title of the book and the last digit is used to check whehter ISBN is correct or not. Each of the first nine digits of the code can take a value between 0 and 9. Sometimes it is necessary to make the last digit equal to ten; this is done by writing the last digit of the code as X. To verify an ISBN, calculate 10 times the first digit, plus 9 times the second digit, plus 8 times the third and so on until we add 1 time the last digit. If the final number leaves no remainder when divided by 11, the code is a valid ISBN. 


For example:
Example 1
INPUT CODE : 0201530821
OUTPUT : SUM = 99
LEAVES NO REMAINDER - VALID ISBN CODE
Example 2
INPUT CODE : 035680324
OUTPUT : INVALID INPUT
Example 1
INPUT CODE : 0231428031
OUTPUT : SUM = 122
LEAVES REMAINDER - INVALID ISBN CODE
ISC 2013 ~ Computer Science Practicals  

Sorting using Stacks

This program implements the Collection Framework classes Stack a subclass of class Vector to sort a intial array using two stacks and their standard operations viz., push(), pop(), peek() and empty().

Thursday, April 10, 2014

Rational Numbers representation Using classes and structures


Basic operations on Rational Numbers using C, C++ and Java.
The same program is written in the above languages, helping you to grasp the basic principles of classes and objects in C++ and Java. Students moving from C++ to Java will be able to relate the similarities at the same time the major differences between them.

Code in C
#include<stdio.h>
#define TRUE 1
#define FALSE 0
typedef struct
{
int numerator;
int denominator;
} RATIONAL;
void multiply(RATIONAL *frst,RATIONAL *scnd);
void add(RATIONAL *frst,RATIONAL *scnd);
void subtract(RATIONAL *frst,RATIONAL *scnd);
int equality(RATIONAL *frst,RATIONAL *scnd);
void divide(RATIONAL *frst,RATIONAL *scnd);
void reduce(RATIONAL *rat);

int main()
{
RATIONAL x,y;
int choice;
printf("\n Enter the numerator and denominator of the first rational:");
scanf("%d %d",&x.numerator,&x.denominator);
printf("\n Enter the numerator and denominator of the second rational:");
scanf("%d %d",&y.numerator,&y.denominator);
//printf("\n Reduced form of the input rationals are:");
reduce(&x);
//printf("\n %d / %d ",x.numerator,x.denominator);
reduce(&y);
//printf("\n %d / %d ",y.numerator,y.denominator);
printf("\n Press 1 for addition:");
printf("\n Press 2 for subtraction:");
printf("\n Press 3 for multiplication:");
printf("\n Press 4 for divison:");
printf("\n Press 5 to check for equatilty");
printf("\n Enter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
add(&x,&y);
break;
case 2:
subtract(&x,&y);
break;
case 3:
multiply(&x,&y);
break;
case 4:
divide(&x,&y);
break;
case 5:
equality(&x,&y)==TRUE ? printf("\n They are equal:\n") : printf("\n They are unequal:\n");
break;
default:
break;
}
return 0;
}
void divide(RATIONAL *frst,RATIONAL *scnd)
{
RATIONAL sum;
sum.numerator = (frst->numerator)*(scnd->denominator);
sum.denominator = (frst->denominator)*(scnd->numerator);
reduce(&sum);
printf("\n After dividing the new rational is: %d / %d \n",sum.numerator,sum.denominator);
}
void multiply(RATIONAL *frst,RATIONAL *scnd)
{
RATIONAL sum;
sum.numerator = (frst->numerator)*(scnd->numerator);
sum.denominator = (frst->denominator)*(scnd->denominator);
reduce(&sum);
printf("\n Product of the rationals is: %d / %d \n",sum.numerator,sum.denominator);
}
int equality(RATIONAL *frst,RATIONAL *scnd)
{
return ( (frst->numerator == scnd->numerator && frst->denominator == scnd->denominator) ? TRUE : FALSE );
}
void subtract(RATIONAL *frst,RATIONAL *scnd)
{
int lcm=1,i;
for(i=1;;i++)
{
if (frst->denominator % i == 0 && scnd->denominator % i== 0)
break;
}
lcm = ((frst->denominator)*(scnd->denominator))/i;
RATIONAL sum;
sum.numerator = (frst->numerator)*(lcm/frst->denominator)-(scnd->numerator)*(lcm/scnd->denominator);
sum.denominator = lcm;
reduce(&sum);
printf("\n Sum of the rationals is: %d / %d \n",sum.numerator,sum.denominator);
}
void add(RATIONAL *frst,RATIONAL *scnd)
{
int lcm=1,i;
for(i=1;;i++)
{
if (frst->denominator % i == 0 && scnd->denominator % i== 0)
break;
}
lcm = ((frst->denominator)*(scnd->denominator))/i;
RATIONAL sum;
sum.numerator = (frst->numerator)*(lcm/frst->denominator)+ (scnd->numerator)*(lcm/scnd->denominator);
sum.denominator = lcm;
reduce(&sum);
printf("\n Sum of the rationals is: %d / %d \n",sum.numerator,sum.denominator);
}
void reduce(RATIONAL *rat)
{
int a,b,rem;
if(rat->numerator > rat->denominator) {
a = rat->numerator;
b = rat->denominator;
}
else {
a = rat->denominator;
b = rat->numerator;
}
while(b!=0) {
rem = a%b;
a = b;
b = rem;
}
rat->numerator /= a;
rat->denominator /= a;
}



Code in C++

#include<iostream>
using namespace std;
#define TRUE 1
#define FALSE 0
class Rational {
private:
int numerator;
int denominator;
public:
Rational() { numerator = 1; denominator = 1;}
void setValues()
{
cout<<"\n Enter the numerator:";
cin>>numerator;
cout<<"\n Enter the denominator:";
cin>>denominator;
}
void dispValue()
{
cout<<"\n"<<numerator<<"/"<<denominator<<"\n";
}
void reduce();
void add(Rational r);
void subtract(Rational r);
void multiply(Rational r);
void divide(Rational r);
int equality(Rational r);
};
int Rational::equality(Rational r)
{
return ( (numerator == r.numerator && denominator == r.denominator) ? TRUE : FALSE );
}
void Rational::divide(Rational r)
{
Rational sum;
sum.numerator = (numerator)*(r.denominator);
sum.denominator = (denominator)*(r.numerator);
sum.reduce();
cout<<"\n On divison the rationals:";
sum.dispValue();
}
void Rational::multiply(Rational r)
{
Rational sum;
sum.numerator = (numerator)*(r.numerator);
sum.denominator = (denominator)*(r.denominator);
sum.reduce();
cout<<"\n Product of the rationals is:";
sum.dispValue();
}
void Rational::subtract(Rational r)
{
int lcm=1,i;
for(i=1;;i++)
{
if (denominator % i == 0 && r.denominator % i== 0)
break;
}
lcm = ((denominator)*(r.denominator))/i;
Rational sum;
sum.numerator = numerator*(lcm/denominator)-(r.numerator)*(lcm/r.denominator);
sum.denominator = lcm;
sum.reduce();
cout<<"\n Difference of the rationals is:";
sum.dispValue();
}
void Rational::add(Rational r)
{
int lcm=1,i;
for(i=1;;i++)
{
if (denominator % i == 0 && r.denominator % i== 0)
break;
}
lcm = ((denominator)*(r.denominator))/i;
Rational sum;
sum.numerator = numerator*(lcm/denominator)+(r.numerator)*(lcm/r.denominator);
sum.denominator = lcm;
sum.reduce();
cout<<"\n Sum of the rationals is:";
sum.dispValue();
}
void Rational::reduce()
{
int a,b,rem;
if(numerator > denominator) {
a = numerator;
b = denominator;
}
else {
a = denominator;
b = numerator;
}
while(b!=0) {
rem = a%b;
a = b;
b = rem;
}
numerator /= a;
denominator /= a;
}
int main()
{
int choice;
Rational x,y;
x.setValues();
y.setValues();
x.reduce();
y.reduce();
cout<<"\n Press 1 for addition:";
cout<<"\n Press 2 for subtraction:";
cout<<"\n Press 3 for multiplication:";
cout<<"\n Press 4 for divison:";
cout<<"\n Press 5 to check for equatilty";
cout<<"\n Enter your choice:";
cin>>choice;
switch(choice)
{
case 1:
x.add(y);
break;
case 2:
x.subtract(y);
break;
case 3:
x.multiply(y);
break;
case 4:
x.divide(y);
break;
case 5:
x.equality(y)==TRUE ? cout<<"\n They are equal:\n" : cout<<"\n They are unequal:\n";
break;
default:
break;
}
return 0;
}


Code in JAVA

import java.util.*;
public class Rational
{
public static void main(String[] args)
{
int choice;
Scanner in = new Scanner(System.in);
OperationRational x = new OperationRational();
OperationRational y = new OperationRational();
x.setValues();
y.setValues();
x.reduce();
y.reduce();
System.out.println("You have entered the following rationals:");
x.dispValue();
y.dispValue();
System.out.println("Press 1 for addition:");
System.out.println("Press 2 for subtraction:");
System.out.println("Press 3 for multiplication:");
System.out.println("Press 4 for divison:");
System.out.println("Press 5 to check for equatilty");
System.out.println("Enter your choice:");
choice = in.nextInt();
switch(choice)
{
case 1:
x.add(y);
break;
case 2:
x.subtract(y);
break;
case 3:
x.multiply(y);
break;
case 4:
x.divide(y);
break;
case 5:
if (x.equality(y) == true)
System.out.println("They are equal:");
else
System.out.println("They are unequal:");
break;
default:
break;
}
}
}
class OperationRational
{
OperationRational()
{
numerator = 1;
denominator = 1;
}
public void setValues()
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the numerator:");
numerator = in.nextInt();
System.out.println("Enter the denominator:");
denominator = in.nextInt();
}
public void dispValue()
{
System.out.println(numerator+"/"+denominator);
}
public void reduce()
{
int a,b,rem;
if(numerator > denominator) {
a = numerator;
b = denominator;
}
else {
a = denominator;
b = numerator;
}
while(b!=0) {
rem = a%b;
a = b;
b = rem;
}
numerator /= a;
denominator /= a;
}
public void add(OperationRational r)
{
int lcm=1,i;
for(i=1;;i++)
{
if (denominator % i == 0 && r.denominator % i== 0)
break;
}
lcm = ((denominator)*(r.denominator))/i;
OperationRational sum = new OperationRational();
sum.numerator = numerator*(lcm/denominator)+(r.numerator)*(lcm/r.denominator);
sum.denominator = lcm;
sum.reduce();
System.out.println("Sum of the rationals is:");
sum.dispValue();
}
public void subtract(OperationRational r)
{
int lcm=1,i;
for(i=1;;i++)
{
if (denominator % i == 0 && r.denominator % i== 0)
break;
}
lcm = ((denominator)*(r.denominator))/i;
OperationRational sum = new OperationRational();
sum.numerator = numerator*(lcm/denominator)-(r.numerator)*(lcm/r.denominator);
sum.denominator = lcm;
sum.reduce();
System.out.println("Difference of the rationals is:");
sum.dispValue();
}
public void multiply(OperationRational r)
{
OperationRational sum = new OperationRational();;
sum.numerator = (numerator)*(r.numerator);
sum.denominator = (denominator)*(r.denominator);
sum.reduce();
System.out.println("Product of the rationals is:");
sum.dispValue();
}
public void divide(OperationRational r)
{
OperationRational sum = new OperationRational();;
sum.numerator = (numerator)*(r.denominator);
sum.denominator = (denominator)*(r.numerator);
sum.reduce();
System.out.println("On divison the rationals:");
sum.dispValue();
}
public boolean equality(OperationRational r)
{
return ( (numerator == r.numerator && denominator == r.denominator) ? true : false );
}
private int numerator;
private int denominator;
}

Get the pdf file, click here

Sunday, April 6, 2014

8085 Programming


Program to ADD the 8-bits N numbers stored sequentially from m/m location 0001H, the value of N being stored at 0000H if D6 is 1
LXI H, 0000H
MOV B,M
XRA A
MOV D,A ; To store the sum
MOV E,A ; To store the carry
INX H ; Pointing to the first 8-bit number
LOOP: MOV A,M
ANI 40H ****
CPI 40H
JNZ SKIP
MOV A,M
ADD D
MOV D,A
JNC SKIP
INR E
SKIP: INX H
DCR B
JNZ LOOP
LXI H, 2000H
MOV M,D ; Store the sum at 2000H
INX H
MOV M,E ; Store the carry at 2001H
RST5

****
D7D6D5D4D3D2D1D0
40H 0 1 0 0 0 0 0 0 AND operation
0 1 0 0 0 0 0 0 40H