class MyEx extends Exception{
MyEx(String s){
super(s);
//System.out.println(s);
}
}
class TestMyEx{
public static void main(String args[]){
int i=10;
if(i==10){
try{
throw new MyEx(“MY Exception is raised”);
}
catch(MyEx e){
System.out.println(e);
}
}
System.out.println(i);
}
}
//——————————– PROGRAM -1 ————————————-
#include<iostream.h>
class A{
public:
void af1(){
cout<<“af1() called from B”;
}
};
/*class B:A{
};*/
/*class B:protected A{
};*/
class B:public A{
};
void main(){
B b1;
b1.af1();
}
//———————————————– PROGARM – 2—————————————
#include<iostream.h>
class A{
protected:
void af1(){
cout<<“af1() called from A”<<endl;
}
};
class B:public A{
public:
void bf1(){
af1();
cout<<“bf1() called from B”<<endl;
}
};
void main(){
B b1;
//b1.A::af1();
b1.bf1();
}
//———————————————– PROGRAM -3 ————————————-
#include<iostream.h>
class A{
protected:
void af1(){
cout<<“af1() called from A”<<endl;
}
};
class B:public A{
public:
void af1(){
A::af1();
cout<<“af1() called from B”<<endl;
}
};
void main(){
B b1;
//b1.A::af1();
b1.af1();
}
//—————————————– PROGRAM – 4—————————————————–
#include<iostream.h>
class A{
public:
/*A(){
cout<<“A() cons called”<<endl;
}*/
};
class B:public A{
public:
B(){
cout<<“B() cons called”<<endl;
}
};
void main(){
B b1;
}
//—————————————- PROGRAM -5 —————————————
#include<iostream.h>
class A{
public:
A(){
cout<<“A()”<<endl;
}
A(int n){
cout<<“A(int n) cons called”<<endl;
}
};
class B:public A{
public:
B(){
A(30);
cout<<“B() cons called”<<endl;
}
};
void main(){
B b1;
}
Confirmation and deletion featured have been added
JSP Sample Project-1 (Partial Code-2)
//concat strings
#include<stdio.h>
void main(){
char st1[50],st2[50],st3[100];
int i,j;
printf(“Enter First string: “);
gets(st1);
printf(“Enter First string: “);
gets(st2);
for(i=0;st1[i]!=’\0′;i++){
st3[i]=st1[i];
}
j=i;
for(i=0;st2[i]!=’\0′;i++){
st3[j]=st2[i];
j++;
}
//puts(st3);
}
//reverse strings
#include<stdio.h>
void main(){
char st1[100];
int i,j;
printf(“Enter First string: “);
gets(st1);
for(i=0;st1[i]!=’\0′;i++);
for(j=i-1;j>=0;j–){
printf(“%c”,st1[j]);
}
}
//compare strings
#include<stdio.h>
void main(){
char st1[100],st2[100];
char ch;
int i,j,k,flg=0;
printf(“Enter First string: “);
gets(st1);
printf(“Enter Second string: “);
gets(st2);
for(i=0;st1[i]!=’\0′;i++);// to get the length of st1
for(j=0;st2[j]!=’\0′;j++);// to get the length of st2
if(i==j){
for(k=0;k<i;k++){
if(st1[k]!=st2[k]){
flg=1;
break;
}
}
if(flg==0)
printf(“Both Strings are same”);
else
printf(“Both Strings are not same”);
}
else{
printf(“Both Strings are not same”);
}
}
/*
HELLO
HELL
HEL
HE
H
*/
#include<stdio.h>
void main(){
char st[100];
char ch;
int i,j,k;
printf(“Enter a string: “);
gets(st);
for(i=0;st[i]!=’\0′;i++);
for(j=i-1;j>=0;j–){
for(k=0;k<=j;k++){
printf(“%c”,st[k]);
}
printf(“\n”);
}
}