Q. Write a function two digit inverse() that reverse the digits of a two-digit integer.
Q. WAP for class account which contains two private data elements, an integer account no and a floating point account balance, and three member function.
Q. Program for Inline functions concept.
Q. WAP for area of circle square and rectangle.
Q. WAP to convert Fahrenheit into Celsius.
Q. WAP that will convert fraction into a mixed number.your function is required in decimal.
Q. WAP to show the use of friend class concept.
Q. WAP to show the concept of Friend Function
Q. WAP to use the concept of constructors and destructors.
Q. Use of default constructor without argument.
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
C++
1. Q. Write a function two digit inverse() that reverse the digits of a two digit integer.
Code:-
#include<iostream.h>
#include<conio.h>
class rev
{
private:
int a,b,c,d;
public:
void getdata()
{
cout<<"enter the no u wanna rev:";
cin>>a;
}
void getrev()
{
c=a%10;
b=a/10;
d=c*10+b;
}
void display()
{
cout<<"nthe no after reversing is:"<<d;
}
};
void main()
{
clrscr();
rev a1;
a1.getdata();
a1.getrev();
a1.display();
getch();
}
3. Q. WAP for class account which contains two private data elements, an integer account no
and a floating point account balance, and three member function.
CODE:-
#include<iostream.h>
#include<conio.h>
class accclass
{
private:
int accno;
int bal;
public:
void getdata()
{
cout<<"nenter the account number for acc1:";
cin>>accno;
cout<<"nenter the balance:";
cin>>bal;
}
void setdata(int accin)
{
accno=accin;
bal=0;
}
void setdata(int accin,float balin)
{
accno=accin;
bal=balin;
}
void display()
{
cout<<"naccount no is: "<<accno;
cout<<"nbalance is: "<<bal;
}
void moneytransfer(accclass &acc,float amount);
};
void accclass::moneytransfer(accclass &acc,float amount)
{
bal=bal-amount;
acc.bal=acc.bal+amount;
}
void main()
{
clrscr();
int trans_money;
8. Q. WAP for area of circle square and rectangle.
CODE:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int choice;
float a,r,c,b,d,areac,arear,areas;
cout<<"enter ur choice:";
cout<<"nenter 1 for area of sqre:nenter 2 for circle areanenter 3 for area of rectanglen";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"nenter the side:";
cin>>a;
areas=a*a;
cout<<"narea="<<areas;
}
case 2:
{
cout<<"enter the radius";
cin>>r;
areac=3.14*r*r;
cout<<"nthe area="<<areac;
}
case 3:
{
cout<<"enter the sides of rectangle:";
cin>>b>>d;
arear=b*d;
cout<<"area="<<arear;
}
}
getch();
}
12. Q. WAP that will convert fraction into a mixed number.your function is required in
decimal.
CODE:-
#include<iostream.h>
#include<conio.h>
class converter
{
private:
int mixed;
float deci,n1;
public:
void getdata()
{
cout<<"enter the no:";
cin>>n1;
}
void cal()
{
mixed=n1/1;
deci=n1-mixed;
cout<<"nnow the number is mixed="<<mixed;
cout<<"ndeci="<<deci;
}
};
void main()
{
clrscr();
converter c1;
c1.getdata();
c1.cal();
getch();
}
14. Q. WAP to show the use of friend class concept.
CODE:-
#include<iostream.h>
#include<conio.h>
class girl;
class boy
{
int income1,income2;
public:
void setdata(int in1,int in2)
{
income1=in1;
income2=in2;
}
friend class girl;
};
class girl
{
int income;
public:
int girlfunc(boy b1)
{
return b1.income1+b1.income2;
}
void show()
{
boy d;
d.setdata(100,200);
cout<<"n boy's income in show():"<<d.income1;
}
};
void main()
{ boy b1;
girl g1;
b1.setdata(500,1000);
cout<<"n boy b1 total income:"<<g1.girlfunc(b1);
g1.show();
getch();
}
16. Q. WAP to show the concept of Friend Function
CODE:-
#include<iostream.h>
#include<conio.h>
class two;//forward declaration
class one
{
int i;
public:
void get()
{
cout<<"n enter the value:";
cin>>i;
}
friend void disp(one num1,two num2);
};
class two
{
int j;
public:
void get()
{
cout<<"n enter the value:";
cin>>j;
}
friend void disp(one num1,two num2);
};
void disp( one num1,two num2)
{
int c;
c=num1.i+num2.j;
cout<<"n the sum is:"<<c;
}
void main()
{ clrscr();
one num1;
two num2;
num1.get();
num2.get();
disp(num1,num2);
getch();
}