Monday, 8 July 2019

ASSIGNMENT-1 JAVA NETBEANS CLASS-12


CLASS-XII
ASSIGNMENT-1  OF JAVA PROGRAMMING


A. Output Finding Questions:
Q.1. Write the output of the following code:
int x,y=0;
for(x=1;x<=5;++x)
y=x++;
--y  

Q.2. Write the output of the following code
Int f=1,i=2;
do{
f*=I;
}while(++i<5);
System.out.println(f); 


Q.3. What will be the value of j and k after execution of the following code:
int j=10,k=12;
if(k>=j)
{
k=j;
j=k;

Q.4. How many times ,the following loop gets executed?
 i=0;
while(i>20)
{
//statements

Q,5, How many times ,the following loop gets executed?
i=0;
do{
//statements
}while(i>20); 

Q.6. What will be the contents of TextField after exec uting the following statement:
int num=4;
num=num+1;
if(num>5)
jTextField1.setText(Integer.toString(num));
else
jTextField1.setText(Integer.toString(num*4)); 

Q.7.find the output
int number1=7,number2=8;
int second=73;
if(number1>0||number2>5)
if(number1>7)
jTextField1.setText(“code worked”);
else
jTextField1.setText(“code might work”);
else
jTextField1.setText(“code will not work ”); 

Q.8. How many times will the following loop get executed?
 x=5; y=36;
while(x<=y)
{
x+=6;
}

Q.9. What will be the content of the jTextArea1 after executing the following code?
 int num=1;
do
{
jTextArea1.setText(Integer.to String(++num)+”\n”);
num=num+1;
}while(num<=10); 

Q.10. Give the output for the following code fragment:
v=20;
do{
jOptionPane.showMessageDialog(numm,v+””);
}while(v<50);
jOptionPane.showMessageDialog(numm,v+””); 

Q.11. Give the value after executing following java code.Also find how many times the following
loop will execute?
int a=10;
int b=12;
int x=5;
int y=6;
while(a<=b)
{
if(a%2==)
x=x+y;
else
x=x-y;
a=a+1;

Q.12.What will be the output produced by following code fragment?
float x=9;
float y=5;
int z=(int)(x/y);
switch(z)
{
 case 1:x=x+2;
case 2: x=x+3;
default: x=x+1;
}
System,.out.println(“value of x:”+x); 

Q.13. Predict the output of the following code fragment:
int i,n;
n=0;i=1;
do
{
 n++;i++;
}while(i<=5); 

Q.13. What will be the values of x and y after executing the following expressions.
 int x=20,y=35;
 x= y++ + x++;
 y= ++y + ++x; 

Q.14. What will be the values of x and y after executing the following expressions.
 int y=-1;
 System.out.println(“x:”+(-y--));
 System.out.println(“y:”+y);


Q.15. What will be the values of x and y after executing the following expressions.
 int x = 45;
 x = x + x++;
 System.out.println(x);
 int y = 45;
 y = y++ + y;
 System.out.println(y); 

Q.16. What values will be assigned to the variable ua,ub,uc and fail after execution of the
following program segment:
int i=0,ua=0,ub=0,uc=0,fail=0;
while(i<=5){
switch(i++)
{
case 1:++ua;
case 2:++ub;uc++;break;
case 3;
case 4:++uc;ua++;ub++;break;
default:++fail;

Q.17. Predict an output of the following code fragment:
 int i=1,j=0,n=0;
while)i<4)
{
for(j=1;j<=I;j++)
{
n+=1;
i=i+1;
}
System.out.println(n);

Q..18. Give the output of the following code:
int m=100;
while(m>0)
{
if(m<10)
break;
m=m-10;
}
System.out.println(“m is “+m); 

B. Error Finding Questions:
Q.1. The following cade has some errors. Rewrite the corrected code:
 int  i=2,j=5;
while j>i
{jTextField1.getText(“j is greater”);
j--;++ I;
}
JOptionPane.showMessageDialog(“Hello”);

Q.2. Identify the errors:
switch(ch)
{
case ‘a’:
case ‘A’:
case ‘e’:
case ‘E’:
case ‘i’:
case ‘E’:
case ‘u’:
case ‘U’:++vowels;
break;
default:++others;


Q.3. int j=5;
i==j+5;
if(i=j)
jTextField1.setText(“I and j are equal”);
else
 jTextField1.settext(“ I and j are unequal”);


Q.4. Rewrite the code after making correction. Underline the correction.
Int sum;value;inct;
Int i
For(i==0;i<=10;i++)
Sum=sum+I;
Inct++;


Q.5. The following code has some error(s).Rewrite the correct code underlining all the corrections
made.
Int y=3;
Switch(y)
{
 case 1: System.out.println(“yes its one”);
case >2: System.out.println(“yes it is more than two”);
break;
case else: System.out.println(“invalid number”);


Q.6. Rewrite the following java code after underlining the correction made:
int x==0;
int n=Integer.parseInt(jLabel1.getText());


Q.7. find out errors if any:
M=1;n=0;
For(;m+n<19;++n)
System.out.println(“hello”);
M=m+10;


Q.8. The following code has some error(s).Rewrite the correct code underlining all the
corrections made.
int y=6,p;
Do
{
y=3.14*y;
p=y%10;
If p=2
System.out.print(“two”);
While(y>1)


C. Rewrite the following program code using a for loop:
Q1.  int I,sum=0;
while(I<10)
{
sum+= I ;
I+=2;
}


Q.2. Rewrite the following code using while loop:
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=I;++j)
System.out.print(j);
}
System.out.println();
}

Q.3. Write a equivalent while loop for the following code:
int sz=25;
for(int i=0,sum=0;i<sz;i++)
sum+=I;
System.out.println(sum);


Q.4.Rewrite the following if-else segment using switch –case statement
char ch=’A’;
if(ch==’A’)
System,out.println(“Account”);
if((ch==’C’)||(ch==’G’))
System.out.println(“Admin”);
if(ch==’F’)
System.out.println(“advisor”);


Q..5. Rewrite the following code using while loop
int i, j;
for(i=1,j=2;i<=6;i++,j+=2)
System.out.println(i++);
System.out.println(“finished!!!”);


Q.6. Rewrite the following code using for loop.
int i=0;
while(++i<20)
{
if(i==8)
break;
System.out.println(i++);
}


Q.7.Rewrite the code using switch statement:
if(k==1)
day=”Monday”;
else if(k==2)
day=”Tuesday”;
else if (k==3)
day=”Wednesday”;
else day=”-“;
}


Q8. What will be the output of :.
 if (aNumber >= 0)
 if (aNumber == 0)
 System.out.println("first string");
 else System.out.println("second string");
 System.out.println("third string");
If aNumber is (i) 0 (ii) 2

Q9. What will be the output of the program?
 int count = 1;
 do
{
System.out.println("Count is: " + count);
 count++;
 } while (count < 11);

Q10. What will be the output of the program
int i=1,j=-1;
switch(i)
{
case 1,-1: j=1;
case 2 : j=2;
default :j=0;
}
Q11.  What will be the output of the program?
int i = 1, j = 10;
do
{
 if(i > j)
 {
 break;
 }
 j--;
} while (++i < 5);
System.out.println("i = " + i + " and j = " + j);

CLASS-XII C++ INHERITANCE


ASSIGNMENT OF INHERITANCE

Q1. Consider the following c++ code and answer the questions from (i) to (iv):
class Personal
{
int Class,Rno;
char Section;
protected:
char Name[20];
public:
personal(); void
pentry();
void Pdisplay();
};
class Marks: private Personal
{
float M[5];
protected:
char Grade[5];
public:
Marks();
void Mentry();
void Mdisplay();
};
class Result: public Marks
{
float Total, Agg;
public:
char FinalGrade, comments[20];
Result();
void Rcalculate();
void Rdisplay();
};
(i) Which type of inheritance is shown in the above example?
(ii) Write the names of those data members, which can be directly accessed from the objects of class Result.
(iii) Write the names of those member functions which can be directly accessed from the objects of class Result.
(iv) Write names of those data members, which can be directly accessed from the Mentry() function of class Marks.


Q2. Answer the questions (i) to (iv) based on the following:
class COMPANY
{
char Location[20];
double Budget,Income;
protected:
void Accounts( );
public:
COMPANY();
void Register( );
void Show( );
};
class FACTORY: public COMPANY
{
char Location[20];
int Workers;
protected:
double Salary;
void Computer();
public:
FACTORY();
void Enter( );
void show( );
};
class SHOP: private COMPANY
{
char Location[20];
float Area;
double Sale;
public:
SHOP();
void Input();
void Output();
};
(i) Name the type of inheritance illustrated in the above C++ code.
(ii) Write the names of data members, which are accessible from member functions of class SHOP.
(iii) Write the names of all the member functions, which are accessible from objects belonging to class FACTORY.
(iv) Write the names of all the members, which are accessible from objects of class SHOP.

Q3. Answer the questions (i) to (iv) based on the following:
class FaceToFace
{
 char CenterCode [10] ;
public:
 void Input ( ) ;
 void Output ( ) ;
} ;
class Online
{
 char website [50] ;
public:
 void SiteIn ( ) ;
 void SiteOut ( ) ;
} ;
class Training: public FaceToFace, private
Online
{
 long Tcode ;
 float charge;
 int period;
public:
 void Register ( ) ;
 void Show ( ) ;
} ;
(i) Which type of Inheritance is shown in the above example?
ii) Write names of all the member functions accessible from Show( ) function of class Training.
iii) Wri t e name of all the members accessible through an object of class Training.
iv) Is the function Output( ) accessible inside the function SiteOut( )? Justify your answer.

Q4 Consider the following and answer the questions given below :                               
class Medicine                                                                 
{
char Category[10];
             char Date_of_manufacture[10];
             char Company[20];
             public:
             Medicine();
             void entermedicinedetails();
             void showmedicinedetails();
};
     class capsule:public Medicine
     {
protected:
                                    char capsule_name[30];
char volume_lable[20];
public:
float Price;
capsules();
void entercapsuledetails();
void showcapsuledetails();
     };
     class Antibiotics:public Capsule
     {
 int Dosage_units;
             char side_effects[20];
             int Use_within_days;
      public:
             Antibiotics();
             void enterdetails();
             void showdetails();
     };
     (i)     How many bytes will be required by an object of class Medicines and an object of class Antibiotics respectively?
      (ii)   Write the names of all the member functions accessible from the object of class Antibiotics.
      (iii) Write the names of all the members accessible from member functions of class capsules.
      (iv)  Write names of all the data members which are accessible from objects of class antibiotics.

     Q5. Consider the following and answer the questions given below :                              
   class Dolls
   {
char Dcode[5];
           protected:
                   float Price;
                  void CalcPrice(float);
           public:
           Dolls();
           void DInput();
           void DShow();
   };
   class SoftDolls:public Dolls
   {
char SDName[20];
           float Weight;
           public:
           SoftDolls();
           void SDInput();
           void SDShow();
   };
   class ElectronicDolls:public Dolls
   {
char EDName[20];
           char BatteryType[10];
           int Batteries;
           public:
           ElecronicDolls();
           void EDInput();
           void EDShow();
   };
      (i)     Which type of inheritance is shown in the above example?
      (ii)   How many bytes will be required by an object of the class ElectronicDolls?
      (iii) Write name of all data members accessible from member function of the classSoftDolls.
      (iv)  Write name of member functions accessible an object of the class ElectronicDolls?

      Q6. Consider the following and answer the questions given below :
class Trainer
{
char TNo[5],Tname[20],specialization[10];
int Days;
protected :
float Remuneratoin;
void AssignRem(float);

public:
Trainer();
void TEntry();
void TDisplay();
};
class Learner
{
char Regno[10],LName[20],Program[10];
protected:
int Attendance,grade;
public:
Learner();
void LEntry();
void LDisplay();

};
class Institute : public Learner, public Trainer
{

 char ICode[10],IName[20];
public:
Institute();
void IEntry();
void IDisplay();

};
(i) Which type of inheritance is depicted by above example?
(ii) Identify the member function(s) that cannot be called directly from the objects of class Institute from the following: TEntry(), LDisplay(), IEntry()
 (iii) Write name of all member(s) accessible from member functions of class institute.
 (iv) If class institute was derived privately from class Learner and privately from class Trainer, then name the member function(s)that could be accessed through Objects of class Institute.

Q7.  Consider the following and answer the questions given below :                                                
class toys
{
char tcode[5];
protected:
float price;
void assign(float);
public:
toys();
void tentry();
void tdisplay();
};
class softtoys : public toys
{
char stname[20];
float weight;
public:
softtoys();
void stentry();
void stdisplay();
};
class electronictoys : public toys
{
char etname[20];
int no_of_batteries;
public:
electronictoys();
void etentry();
void etdisplay();
};

(i)     Which type of inheritance is shown in the above example?
(ii)   How many bytes will be required by an object of the class softtoys?
(iii) Write the name of all the data members accessible from member functions of class softtoys?
(iv)  Write the names of all the member functions which are accessible from an object of class electronictoys.