Uploaded by pahe pahe

examly question java

advertisement
1
public:
// You are using GCC
void area(T a)
{
cout<<(1.732*a*a)/4.0<<endl;
}
void area(T a,T b)
{
cout<<(0.5*a*b)<<endl;
}
void area(T a,T b,T c)
{
T s=(a+b+c)/2.0;
double ar=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<ar<<endl;
}
};
2
list<int> l;
// You are using GCC
int n,i,temp;
cin>>n;
for(i=0;i<n;i++)
{
cin>>temp;
l.push_back(temp);
}
list<int>::iterator it,it1;
it=min_element(l.begin(),l.end());
it1=max_element(l.begin(),l.end());
cout<<*it<<endl<<*it1<<endl;
cin>>temp;
l.insert(it,temp);
cin>>temp;
l.insert(it1,temp);
for(it=l.begin();it!=l.end();it++)
{
cout<<*it<<" ";
}
cout<<endl;
l.reverse();
for(it=l.begin();it!=l.end();it++)
{
cout<<*it<<" ";
}
cout<<endl;
l.sort();
for(it=l.begin();it!=l.end();it++)
{
cout<<*it<<" ";
}
3
// You are using GCC
void operate(vector<int> v,int n)
{
int a;
vector<int> v1;
v1=v;
reverse(v1.begin(),v1.end());
for(a=0;a<v1.size();a++)
{
cout<<v1[a]<<" ";
}
cout<<endl;
for(a=0;a<v.size();a++)
{
if(v[a]!=v1[a])
{
break;
}
}
if(a==v.size())
{
cout<<"EQUAL";
}
else
{
cout<<"NOT EQUAL";
}
}
4
// You are using GCC
void compute(int n,int arr[50],set<int> s)
{
int a,count=0;
for(a=0;a<n;a++)
{
s.insert(arr[a]);
}
set<int>::iterator it;
for(it=s.begin();it!=s.end();it++)
{
cout<<*it<<" ";
if((*it)<40)
{
count++;
}
}
cout<<endl<<count;
}
5
double arr[35];
int size;
// You are using GCC
public:
void enter()
{
cout<<"Enter the numbers of data:\n";
cin>>size;
cout<<"Enter number:\n";
for(int a=0;a<size;a++)
{
cin>>arr[a];
}
}
void total()
{
double sum=0;
for(int a=0;a<size;a++)
{
sum+=arr[a];
}
cout<<"total sum of numbers is :"<<sum<<endl;
cout<<"Average = "<<(sum/size)<<endl;
}
void avg()
{
}
void sort()
{
int a,b;
for(a=0;a<size;a++)
{
for(b=0;b<size;b++)
{
if(arr[a]<arr[b])
{
arr[a]+=arr[b];
arr[b]=arr[a]-arr[b];
arr[a]-=arr[b];
}
}
}
cout<<"Elements of array in sorted ascending order:\n";
for(a=0;a<size;a++)
{
cout<<arr[a]<<endl;
}
}
};
6
// You are using GCC
vector<int> v;
int a,b,c;
cout<<"Enter the size of array:\n";
cin>>a;
cout<<"enter elements of array:\n";
for(b=0;b<a;b++)
{
cin>>c;
v.push_back(c);
}
print(v);
sort(v.begin(),v.end());
print(v);
reverse(v.begin(),v.end());
print(v);
cout<<"enter element you want to search:\n";
cin>>c;
b=count(v.begin(),v.end(),c);
if(b)
{
cout<<"Found";
}
else
{
cout<<"not found";
}
return 0;
}
7
// You are using GCC
int a,b,c;
vector<int> v;
cin>>a;
cout<<a<<endl;
for(b=0;b<a;b++)
{
cin>>c;
v.push_back(c);
}
print(v);
reverse(v.begin(),v.end());
print(v);
cout<<"enter element you want to search:\n";
cin>>c;
b=0;
b=count(v.begin(),v.end(),c);
if(b)
{
cout<<"the number "<<c<<" is in the list";
}
else
{
cout<<"the number "<<c<<" is not in the list";
}
return 0;
}
void print(vector<int> &v)
{
int a;
for(a=0;a<v.size();a++)
{
cout<<v[a]<<" ";
}
cout<<endl;
}
8
template<class t1,class t2>
BHK_req<t1,t2> :: BHK_req()
{
cin>>room;
cin.ignore();
cin>>r_furniture>>k_furniture>>h_furniture;
cost(room,r_furniture);
cost(h_furniture,k_furniture);
}
template<class t1,class t2>
// You are using GCC
void BHK_req<t1,t2> :: cost(t1 room,t2 r_furniture)
{
if(r_furniture=="full")
{
r_cost=room*2500000;
}
else
{
r_cost=room*1300000;
}
}
template<class t1,class t2>
void BHK_req<t1,t2> :: cost(t2 h_furniture,t2 k_furniture)
{
if(h_furniture=="full")
{
h_cost=3500000;
}
else
{
h_cost=1800000;
}
if(k_furniture=="full")
{
k_cost=2000000;
}
else
{
k_cost=1000000;
}
}
template<class t1,class t2>
void BHK_req<t1,t2> :: show()
{
cout<<room<<endl<<r_cost<<endl<<k_cost<<endl<<h_cost;
cout<<endl<<r_cost+k_cost+h_cost;
}
9
// You are using GCC
void s_name :: insert_word()
{
int a,b;
string c;
cin>>a;
for(b=0;b<a;b++)
{
cin>>c;
v.push_back(c);
}
}
void s_name :: delete_word()
{
if(!v.empty())
{ string s;
cin>>s;
t=find(v.begin(),v.end(),s);
v.erase(t);
}
}
void s_name :: replace_word()
{
if(!v.empty())
{
string s,s1;
cin>>s>>s1;
replace(v.begin(),v.end(),s,s1);
}
}
void s_name :: display()
{
if(!v.empty())
{ for(int a=0;a<v.size();a++)
{
cout<<v[a]<<endl;
}
}
else
{
cout<<"listempty";
}
}
10
// You are using GCC
{
list<int>::iterator it;
for(it=l1.begin();it!=l1.end();it++)
{
(*it)*=2;
}
for(it=l1.begin();it!=l1.end();it++)
{
cout<<*it<<" ";
}
cout<<endl;
it=max_element(l1.begin(),l1.end());
cout<<*it<<endl;
it=min_element(l1.begin(),l1.end());
cout<<*it<<endl;
}
11
// You are using GCC
{
list<int> l;
for(int b=0;b<size;b++)
{
int c;
cin>>c;
l2.push_back(c);
}
list<int>::iterator it=l2.begin();
int a;
for(a=0;a<size/2;a++)
{
if((*it)%2==0)
{
l.push_back((*it));
}
it++;
}
return l;
}
void print(list<int> &l)
{
list<int>::iterator it;
for(it=l.begin();it!=l.end();it++)
{
cout<<*it<<" ";
}
}
12
// You are using GCC
int i,j,size=0;
T arr3[100];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(arr2[i]==arr1[j])
{
arr3[size]=arr2[i];
size++;
}
}
}
//reverse(arr3,arr3+size);
for(i=0;i<size;i++)
{
cout<<arr3[i]<<" ";
}
}
13
// You are using GCC
for(i=0;i<size;i++)
{
sum=sum+g1[i];
}
mean=(float)sum/size;
cout<<mean<<endl;
for(i=0;i<size;i++)
{
sum1=sum1+pow((g1[i]-mean),2);
}
float s1;
s1=(float)sum1/size;
cout<<s1<<endl;
s1=sqrt(s1);
cout<<s1;
14
// You are using GCC
sort_array(int n)
{
a=new T[n];
size=n;
}
void print()
{
int i,j;
T temp;
for(i=0;i<size;i++)
{
cin>>a[i];
}
for(i=0;i<size;i++)
{
for(j=i+1;j<size;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<size;i++)
{
cout<<a[i]<<endl;
}
}
};
int main()
{
int n;
cin>>n;
sort_array<int> a(n);
sort_array<float> b(n);
sort_array<string> c(n);
int ch;
cin>>ch;
if(ch==1)
{
a.print();
}
else if(ch==2)
{
b.print();
}
else if(ch==3)
{
c.print();
}
else
{
cout<<"WRONG CHOICE";
}
}
15
// You are using GCC
for(int i=0;i<vec1.size()-1;i++)
{
int sum;
sum=vec1[i]+vec1[i+1];
cout<<sum<<endl;
}
}
int main()
{
vector<int> v;
int n;
cin>>n;
int i;
if(n==1)
{
cout<<"No Adjacent Value";
}
else
{
int temp;
for(i=0;i<n;i++)
{
cin>>temp;
v.push_back(temp);
}
displaySum(v);
}
}
16
// You are using GCC
int a,b,c;
cin>>a;
for(b=0;b<a;b++)
{
cin>>c;
if(c!=10)
V.push(c);
else
{
c=V.top();
c=10-c;
V.pop();
V.push(c);
b--;
}
}
for(b=0;b<a;b++)
{
cout<<V.top()<<endl;
V.pop();
}
return 0;
}
17
// You are using GCC
int i,temp;
int n;
cin>>n;
for(i=0;i<n;i++)
{
cin>>temp;
s.push(temp);
}
while(!s.empty())
{
cout<<s.top()<<" ";
18
// You are using GCC
void read()
{
int i,j;
for(i=0;i<size;i++)
{
cin>>a[i];
}
}
void sort1()
{
int i,j;
T tem;
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
if(a[i]<a[j])
{
tem=a[i];
a[i]=a[j];
a[j]=tem;
}
}
}
}
void print()
{
for(int i=0;i<size;i++)
{
cout<<a[i]<<endl;
}
}
};
19
// You are using GCC
class derived:public base
{
public:
derived()
{
base();
cout<<w*l<<endl<<2*(w+l);
}
};
20
// You are using GCC
void Paint::getdata()
{
cin>>l>>b>>h>>cost;
}
class Calculate:public Paint
{
public:
void total_cost()
{
int a=l*b;
int d=2*h*(l+b);
int c=a+d;
float total_cost=cost*(float)c;
cout<<total_cost;
}
};
21
// You are using GCC
class Square_root:public puzzle
{
public:
double task1()
{
double d,f;
f=fun();
d=sqrt(f);
return d;
}
};
class Square:public puzzle
{
public:
double task2()
{
double d,f;
f=fun();
d=f*f;
return d;
}
};
22
// You are using GCC
int super :: get(int a){
x=a;
return a;
}
class class1 : public virtual super
{
int a;
char na[20];
public:
void getdata1()
{
cin>>a>>na;
}
void show()
{
cout<<a<<endl<<na;
}
};
class class2 : public virtual super
{
int ag;
char n[20];
public:
void getdata2()
{
cin>>ag>>n;
}
void show()
{
cout<<ag<<endl<<n;
}
};
23
// You are using GCC
vendor::vendor()
{
cin>>cust_id;
cin.ignore();
cin.getline(name,20);
}
void vendor::show_cust()
{
cout<<cust_id<<endl<<name<<endl;
}
class wheat: public virtual vendor
{
public:
int qty,price;
wheat()
{
cin>>price>>qty;
}
};
class rice: public virtual vendor
{
public:
int qty1,price1;
rice()
{
cin>>price1>>qty1;
}
};
class final:public wheat,public rice
{
public:
int total;
final()
{
total=0;
}
void show_total()
{
total=((price1*qty1)+(price*qty));
cout<<total;
}
};
24
// You are using GCC
void Triangle::get_bh()
{
cin>>base>>height;
}
class Hypo:public Triangle
{
int c;
public:
void display()
{
get_bh();
c=(base*base)+(height*height);
c=sqrt(c);
cout<<c<<endl;
}
};
class Area:public Hypo
{
public:
void get_Area()
{
display();
int d=base*height;
cout<<d/2;
}
};
25
float polygon :: area(){}
// You are using GCC
void polygon :: get_data()
{
cin>>a>>b;
}
float rectangle :: area()
{
return a*b;
}
float triangle :: area()
{
return (a*b)/2;
}
int main()
{
polygon *p;
rectangle r;
triangle t;
r.get_data();
t.get_data();
26
// You are using GCC
void fun_try(int x,string name,string type,double cost)
{
try
{
if(x<=0)
{
throw(x);
}
else
{
cout<<name<<endl<<type<<endl<<fixed<<setprecision(2)<<cost/x;
}
}
catch(int a)
{
cout<<"Days cannot be negative or zero";
}
}
27
// You are using GCC
class Onetier:public Train
{
public:
void get()
{
cin>>number_of_tickets>>price_per_ticket;
}
void bill()
{
int a=number_of_tickets*price_per_ticket;
if(a<5000)
{
cout<<a;
}
else
{
cout<<a;
a=a-(0.2*a);
cout<<"Lucky customer you will get 20% discount.The modified bill for Onetier is "<<a;
}
cout<<endl;
}
};
class Twotier:public Train
{
public:
void get()
{
cin>>number_of_tickets>>price_per_ticket;
}
void bill()
{
int b=number_of_tickets*price_per_ticket;
if(b<5000)
{
cout<<b;
}
else
{
cout<<b;
b=b-(0.2*b);
cout<<"Lucky customer you will get 20% discount.The modified bill for Twotier is "<<b;
}
}
};
28
// You are using GCC
class Doctor:public virtual Person
{
public:
int d;
void get()
{
cin>>d;
}
int calculate()
{
return 500*d;
}
};
class Teacher:public virtual Person
{
public:
int t;
void get()
{
cin>>t;
}
int calculate()
{
return 200*t;
}
};
class Total:public Doctor,public Teacher
{
public:
void get()
{
}
int calculate()
{
}
void total(int a,int b)
{
cout<<endl<<a+b;
}
};
29
// You are using GCC
class man:public bank
{
public:
int a;
void read()
{
cin>>a;
}
void terminate()
{
if(a>10000)
{
cout<<"not terminate"<<a-10000;
}
else
{
cout<<"terminate";
}
}
};
class exe:public bank
{
public:
int b;
void re()
{
cin>>b;
}
void terminate()
{
if(b>20)
{
cout<<"not terminate"<<b-20;
}
else
{
cout<<"terminate";
}
}
};
30
// You are using GCC
public:
virtual void getdata()
{
cin>>bags;
}
};
class steel
{
public:
int tons;
virtual void getdata()
{
cin>>tons;
}
};
class wood
{
public:
int q;
virtual void getdata()
{
cin>>q;
}
};
class house:public virtual cement,public virtual steel,public virtual wood
{
public:
int c;
void getdata()
{
}
void cost()
{
c=(150*bags)+(tons*28000)+(q*1500);
cout<<c;
}
};
31
// You are using GCC
#include<iostream>
using namespace std;
int main()
{
double a,b,c;
double ar,ar1;
cin>>a>>b>>c;
ar=3.14*a*b*a;
ar1=3.14*c*c;
cout<<ar<<endl<<ar1<<endl;
if(ar>ar1)
{
cout<<"area of cylinder is greater";
}
else
{
cout<<"area of circle is greater";
}
}
32
// You are using GCC
public:
void getdata()
{
cin>>cname;
cin.ignore();
cin>>pprc>>Iprc;
ratio=pprc/Iprc;
cout<<cname<<endl<<pprc<<endl<<Iprc<<endl<<ratio<<endl;
}
void display()
{
//MMMMMMMMMMM
}
};
class state:public country
{
public:
};
33
// You are using GCC
void displaySum(vector<int> v)
{
int b;
if(v.size()<=1)
{
cout<<"No Adjacent Value";
}
else
{
for(b=0;b<v.size()-1;b++)
{
cout<<v[b]+v[b+1]<<endl;
}
}
}
34
// You are using GCC
void read()
{
int i,j;
for(i=0;i<size;i++)
{
cin>>a[i];
}
}
void sort1()
{
int i,j;
T tem;
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
if(a[i]<a[j])
{
tem=a[i];
a[i]=a[j];
a[j]=tem;
}
}
}
}
void print()
{
int i,j;
for(i=0;i<size;i++)
{
cout<<a[i]<<endl;
}
}
};
35
// You are using GCC
// You are using GCC
void displaySum(vector<int> v)
{
int b;
if(v.size()<=1)
{
cout<<"No Adjoining Value";
}
else
{
for(b=0;b<v.size()-1;b++)
{
cout<<v[b]+v[b+1]<<endl;
}
}
}
36
sort_array(int b)
{
size=b;
a=new T[size];
}
void read()
{
int i,j;
for(i=0;i<size;i++)
{
cin>>a[i];
}
}
void sort1()
{
int i,j;
T tem;
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
if(a[i]<a[j])
{
tem=a[i];
a[i]=a[j];
a[j]=tem;
}
}
}
}
void print()
{
int i,j;
for(i=0;i<size;i++)
{
cout<<a[i]<<endl;
}
}
};
37
// You are using GCC
int a,b,c;
for(;;)
{
cin>>c;
myvector.push_back(c);
if(c==0)
{
break;
}
}
reverse(myvector.begin(),myvector.end());
for(b=0;b<myvector.size();b++)
{
cout<<myvector[b]<<endl;
sum=sum+myvector[b];
}
cout<<myvector.size()<<endl<<sum;
return 0;
}
38
// You are using GCC
Array::Array()
{
arr[0]=0;
}
Array::Array(int a)
{
for(int b=0;b<a;b++)
{
cin>>arr[b];
}
size=a;
}
int Array :: find_val(Array a,int i)
{
return a.arr[i];
}
Array operator+(int x,Array a)
{
Array a1;
for(int b=0;b<a.size;b++)
{
a1.arr[b]=x+a.arr[b];
}
a1.size=a.size;
return a1;
}
void Array :: find_even_largest()
{
int b,c;
c=arr[0];
for(b=0;b<size;b++)
{
if(arr[b]>c&&arr[b]%2==0)
{
c=arr[b];
}
}
cout<<"largest number is: "<<c;
}
39
// You are using GCC
void operator=(Kilometer &k);
void display()
{
cout<<mt<<"mt";
}
};
class Kilometer
{
public:
int km;
public:
Kilometer()
{
}
Kilometer(int k)
{
km=k;
}
};
Meter :: Meter()
{
mt=0;
}
void Meter :: operator = (Kilometer &k)
{
mt=k.km*1000;
}
40
// You are using GCC
void bill :: get_info()
{
cin>>h_no>>unit;
}
void bill :: calculate()
{
if(unit>=300)
{
bill_value=unit*5;
}
else if(unit>=200)
{
bill_value=unit*4.5;
}
else if(unit>=100)
{
bill_value=unit*3.5;
}
else
{
bill_value=unit*2;
}
}
bill bill :: operator+(bill b)
{
bill b1;
b1.bill_value=b.bill_value+bill_value;
return b1;
}
void bill :: show()
{
cout<<"House number "<<h_no<<" has electricity bill Rs "<<bill_value<<endl;
}
41
// You are using GCC
void square :: area()
{
cout<<"Area of square formed is "<<a*a<<endl;
}
void square :: perimeter()
{
cout<<"Perimeter of square formed is "<<a*4;
}
class rectangle:public square
{
int l,b;
public:
void get_data()
{
cin>>l>>b;
if(l>b)
{
a=b;
}
else
{
a=l;
}
cout<<"Side of the square formed from rectangle "<<l<<"*"<<b<<" is "<<a<<endl;
}
};
42
// You are using GCC
class A
{
public:
void get(float arr[],int n)
{
int i;
for(i=0;i<n;i++)
{
cin>>arr[i];
}
}
void show(float arr[],int n)
{
int i;
for(i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
}
float average(float arr[],int n)
{
int i;
float avg=0;
for(i=0;i<n;i++)
{
avg=avg+arr[i];
}
return avg/n;
}
void check(float arr[],int n,float ans)
{
int i,c=0;
for(i=0;i<n;i++)
{
if(arr[i]<ans)
{
c++;
}
}
cout<<endl<<c;
}
};
43
// You are using GCC
public:
void accept()
{
int i;
for(i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cin>>a[i][j];
}
}
}
void display()
{
int i;
for(i=0;i<3;i++)
{
cout<<"\n";
for(int j=0;j<3;j++)
{
cout<<a[i][j]<<"\t";
}
}
}
void operator -- (int)
{
int i;
for(i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
a[i][j]--;
}
}
}
};
44
// You are using GCC
void stringg::read()
{
cin>>str;
}
void stringg::print()
{
cout<<str;
}
stringg stringg::operator+(stringg s)
{
stringg s1;
int a,b;
for(a=0;str[a]!='\0';a++)
{
s1.str[a]=str[a];
}
for(b=0;s.str[b]!='\0';b++)
{
s1.str[a+b]=s.str[b];
}
return s1;
}
int stringg::operator==(stringg s)
{
for(int a=0;s.str[a]!='\0';a++)
{
if(str[a]!=s.str[a])
{
return 0;
}
}
return 1;
}
45
// You are using GCC
Time :: Time(int h,int m)
{
hrs=h;
min=m;
}
Time :: operator int()
{
return (hrs*60+min);
}
46
// You are using GCC
class emp
{
public:
void read(int *arr,int size)
{
for(int a=0;a<size;a++)
{
cin>>arr[a];
}
}
void check(int *arr,int size)
{
int a,count=0;
for(a=0;a<size;a++)
{
if(arr[a]>5)
{
cout<<a<<" ";
count++;
}
}
cout<<endl<<count;
}
};
47
// You are using GCC
{
int a;
for(a=0;a<4;a++)
{
o.arr1[a]--;
}
}
void operator++()
{
int a;
for(a=0;a<4;a++)
{
++arr1[a];
}
}
};
void Array1 :: get()
{
for(int a=0;a<4;a++)
{
cin>>arr1[a];
}
}
void Array1 :: display()
{
for(int a=0;a<4;a++)
{
cout<<arr1[a]<<" ";
}
cout<<endl;
}
48
// You are using GCC
long int sum;
double avg;
public:
void get()
{
int a;
for(a=0;a<5;a++)
{
cin>>arr[a];
}
}
operator long int()
{
long int sum=0;
for(int a=0;a<5;a++)
{
sum+=arr[a];
}
avg=sum/5.0;
return sum;
}
operator double()
{
return avg;
}
};
int main()
{
demo *ptr1,d;
d.get();
49
// You are using GCC
public:
int mat[3][3];
public:
friend class demo2;
demo1()
{
int a,b;
for(a=0;a<3;a++)
{
for(b=0;b<3;b++)
{
cin >> mat[a][b];
}
}
}
};
class demo2
{
int mat1[3][3];
public:
demo2(demo1 &d)
{
int a,b;
for(a=0;a<3;a++)
{
for(b=0;b<3;b++)
{
mat1[a][b]=d.mat[a][b];
}
}
}
friend void operator+(demo1 d,demo2 d1)
{
int a,b;
for(a=0;a<3;a++)
{
for(b=0;b<3;b++)
{
cout<<d.mat[a][b]+d1.mat1[a][b]<<" ";
}
cout<<endl;
}
}
};
50
// You are using GCC
class Minute
{
int min;
public:
void display()
{
cout<<min;
}
void operator=(Time t)
{
min= t.getMinutes();
}
};
51
public:
double l,b;
// You are using GCC
demo1()
{
l=b=0;
}
demo1(int a)
{
cin>>l>>b;
cout<<l*b<<endl;
}
void area(int a,int c)
{
}
};
52
// You are using GCC
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
vector<int> v;
int a,b,c;
cout<<"\nEnter the number of elements :";
cin>>a;
for(b=0;b<a;b++)
{
cin>>c;
v.push_back(c);
}
cout<<"\n The sorted array is : ";
sort(v.begin(),v.end());
for(b=0;b<v.size();b++)
{
cout<<v[b]<<" ";
}
return 0;
}
53
// You are using GCC
public:
String()
{
str=new char [50];
}
void accept_string()
{
cout<<"Enter String:\n";
cin>>str;
}
String operator+(String s1)
{
String s2;
int a,b;
for(a=0;str[a]!='\0';a++)
{
s2.str[a]=str[a];
}
for(b=0;s1.str[b]!='\0';b++)
{
s2.str[a+b]=s1.str[b];
}
return s2;
}
void display_string()
{
cout<<str;
}
};
Download