Thursday, 27 October 2016

ISC Computer 2014 Theory Part II : Section C Fully Solved



Section C : 2014 Solved Theory


Question :11
A super class Stock………………need not be written.
public class Stock
{
    String item;
intqty;
    double rate,amt;
Stock(String i,intq,double r)
    {
        item=i;
qty=q;
        rate=r;
amt=qty*rate;
    }
    void display()
    {
System.out.println("Name of item : "+item);
System.out.println("Quantity : "+qty);
System.out.println("Rate per unit : "+rate);
System.out.println("Amount : "+amt);
    }
}



public class Purchase extends Stock
{
intpqty;
    double prate;
Purchase(String si,intsq,doublesr,intpq,doublepr)
    {
        super(si,sq,sr);
pqty=pq;
        prate=pr;
    }
    void update()
    {
qty=qty+pqty;
        rate=prate;
amt=amt+(pqty*prate);
    }
    void display()
    {
System.out.println("Stock Details before updation : ");
super.display();
System.out.println("Stock Details after updation : ");
update();
super.display();
    }
}


Question :12
A stack is linear data structure………need not be written.
import java.util.*;
public class Array_to_Stack
{
intm[]=new int[50];
intst[]=new int[50];
intcap,top;
Array_to_Stack(int n)
    {
        cap=n;
        top=-1;
    }
    void input_marks()
    {
        Scanner in=new Scanner(System.in);
System.out.println("Enter "+cap+" elements in array in ascending order : ");
inti;
        for(i=0;i<cap;i++)
        {
            m[i]=in.nextInt();
pushmarks(m[i]);
        }
    }
    void pushmarks(int v)
    {
        if((top+1)==cap)
        {
System.out.println("Not Passible");
        }
        else
        {
st[++top]=v;
        }
    }
intpopmarks()
    {
        if(top==-1)
        {
            return (-999);
        }
        else
        {
            return (st[top--]);
        }
    }
    void display()
    {
System.out.println("Stack Elements : ");
inti;
        for(i=top;i>=0;i--)
        {
System.out.println(st[i]);
        }
    }
}

No comments:

Post a Comment