Archive for the ‘CSE Sem3’ Category

Question 3.

Posted: August 29, 2012 in Lab 5
#include<iostream.h>
class vector
{
int a[50],n;
public:
vector(){}

void getdata()
{
cout<<"Enter n=";
cin>>n;
cout<<"\nEnter Vector=\n";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}
void show()
{
cout<<"n="<<n;

cout<<"\nVector is=\n";
cout<<"(";
for(int i=0;i<n;i++)
{
cout<<a[i];
if(i!=n-1)
cout<<",";
}
cout<<")";
}

add(vector v1,vector v2)
{
vector v;
for(int i=0;i<v1.n;i++)
{
a[i]=v1.a[i]+v2.a[i];
}
n=v1.n;
}
};
int main()
{
vector v1,v2,v;
cout<<"Create 2 Vectors \n";
v1.getdata();
v2.getdata();

cout<<"Adding 2 vectors \n";
v.add(v1,v2);

cout<<"\nDisplaying Vector \n";
v.show();
return 0;
}
Advertisements

Question 2.

Posted: August 29, 2012 in Lab 5
#include<iostream.h>
class vector
{
int a[25],n;
public:
vector(){}
void getdata()
{
cout<<"Enter n=";
cin>>n;
cout<<"\nEnter Vector=\n";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}
void show()
{
cout<<"\nVector is=\n";
cout<<"(";
for(int i=0;i<n;i++)
{
cout<<a[i];
if(i!=n-1)
cout<<",";
}
cout<<")";
}
void modify()
{
int num;
cout<<"\nWhich element you want to modify ?\n";
cin>>num;
cout<<"Enter Element=";
cin>>a[num-1];
cout<<"\nSuccessfull \n";
}
void scaler()
{
int sc;
cout<<"\nEnter Scaler Element=";
cin>>sc;
for(int i=0;i<n;i++)
{
a[i]=sc*a[i];
}
}
};

int main()
{
vector v;
cout<<"Create a Vector\n";
v.getdata();

cout<<"Modify Value of Given Element\n";
v.modify();

cout<<"Multiply Vector by a Scaler\n";
v.scaler();

cout<<"Displaying Vector\n";
v.show();
return 0;
}

Question 1.

Posted: August 29, 2012 in Lab 5, Uncategorized
#include<iostream.h>
class DB;
class DM{
float m;
public :
DM (){}
DM(float met)
{
m=met;
}
void show()
{
cout<<"\n METERS="<<m;
}
DM::DM(DB m1);
friend DM operator+(DM b1,DM b2);
};
class DB{
float f,i;
public :
DB(){}
DB(float ft,float in)
{
f=ft;
i=in;
}
DB(DM b1);
friend DM::DM(DB m1);
};

DM::DM(DB m1)
{
m=(m1.f*12+m1.i)/39.37;
}

DM operator+(DM b1,DM b2)
{
float a=b1.m+b2.m;
return (a);
}

 main()
{
 DM d1(3),d3(5),d;
 DB d2(2,1),d4(4,2);
 d=d1+d2;
 d.show();
 d=d2+d1;
 d.show();
 d=d1+d3;
 d.show();
 d=d2+d4;
 d.show();
 }