0% found this document useful (0 votes)
3 views3 pages

lab_inline_constructor

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

lab_inline_constructor

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. WAP to find sum of series 1+x+x2+x3+….+xn using constructors.

#include<iostream.h>
#include<conio.h>
#include<math.h>
class series
{
private: int x, n, i, s;
public: series()
{
s=0;
}
void input()
{
cout<<"Enter the value of x and n";
cin>>x>>n;
}
voidprocess()
{
for(i=0; i<=n; i++)
s=s+pow(x,i);
}
void output()
{
cout<<"Sum of series="<<s;
}
};
main()
{
series obj;
obj.input();
obj.process();
obj.output();
getch();
}

2. Create a base class containing data members rollno and name. Also create a
member function to read and display the data using the concept of single
level inheritance. Create a derived class that contains marks of two subjects
and total marks as data members.
#include<iostream.h>
#include<conio.h>
class student
{
private: intrno;
char name[30];
public: void input1()
{
cout<<"Enter the roll no";
cin>>rno;
cout<<"Enter the name";
cin>>name;
}
void output1()
{
cout<<"Roll No="<<rno;
cout<<"\n Name="<<name;
}
};
class marks : public student
{
private: int m1,m2,total;
public: void input2()
{
cout<<"Enter the marks in 2 subjects";
cin>>m1>>m2;
total=m1+m2;
}
void output2()
{
cout<<"\n Subject1 mark="<<m1;
cout<<"\n Subject2 mark="<<m2;
cout<<"\n Total="<<total;
}
};
main()
{
marks obj;
obj.input1();
obj.input2();
obj.output1();
obj.output2();
getch();
}

3.Create a class containing following data members Register no, name and fees.
Also create a member functions to read and display the data using concepts of
pointer to objects.
#include<iostream.h>
#include<conio.h>
class student
{
private:intrno,fees;
char name[30];
public: void input()
{
cout<<"Enter the register no";
cin>>rno;
cout<<"Enter the name";
cin>>name;
cout<<"Enter the fees";
cin>>fees;
}
void output()
{
cout<<"Register Number="<<rno;
cout<<"\n Name="<<name;
cout<<"\n Fees="<<fees;
}
};
main()
{
student obj,*pobj;
pobj=&obj;
pobj->input();
pobj->output();
getch();
}

4. WAP to find cube of a number using inline function.


#include<iostream.h>
#include<conio.h>
inline int cube(int a)
{
return a*a*a;
}

main()
{
clrscr();
in obj;
int a;
cout<<"Enter a number";
cin>>a;
cout<<"Cube of a number="<<cube(a);
}

You might also like