Objectorientedprogrammingusingc++Lab Cse Section Regd - No Week Date Programnumber Titleofexperiment Sourcecode
Objectorientedprogrammingusingc++Lab Cse Section Regd - No Week Date Programnumber Titleofexperiment Sourcecode
Objectorientedprogrammingusingc++Lab Cse Section Regd - No Week Date Programnumber Titleofexperiment Sourcecode
CSE Section:A
Programnumber:01
Sourcecode:
#include<iostream>
using namespace std;
class B;
class A
{
int a;
public:
void getdata1()
{
cout<<"enter a";
cin>>a;
}
friend void sum(A ob1,B ob2);
};
class B
{
int b;
public:
void getdata2()
{
cout<<"enter b";
cin>>b;
}
friend void sum(A ob1,B ob2);
};
void sum(A ob1,B ob2)
{
cout<<ob1.a+ob2.b;
}
int main()
{
A ob1;
B ob2;
ob1.getdata1();
ob2.getdata2();
// cout<<"enter values";
//cin>>ob1.a>>ob2.b;
sum(ob1,ob2);
return 0;
}
Output
Programnumber:02
Sourcecode:
#include<iostream>
using namespace std;
int main()
{
int a[20],i,n;
cout<<"enter size";
cin>>n;
for(i=0;i<n;i++)
cin>>*(a+i);
cout<<"enter the ele";
for(i=0;i<n;i++)
cout<<*(a+i);
}
Output
Programnumber:03
Sourcecode:
#include<iostream>
using namespace std;
int main()
{
int a[20],i,n,s=0;
cout<<"enter size";
cin>>n;
for(i=0;i<n;i++)
{
cin>>*(a+i);
}
for(i=0;i<n;i++)
{
s=s+*(a+i);
}
cout<<"sum="<<s;
}
Output
Programnumber:04
Sourcecode:
#include<iostream>
using namespace std;
class A
{
int a;
public:
void getdata()
{
cout<<"enter a";
cin>>a;
}
friend void fact(A ob);
};
void fact(A ob)
{
int i,fact=1;
for(i=1;i<=ob.a;i++)
{
fact=fact*i;
}
cout<<"fact="<<fact;
}
int main()
{
A ob;
ob.getdata();
fact(ob);
}
Output