You are on page 1of 4

Day 1:

Q1:
#include <iostream>

using namespace std;

class Time
{
int hour,minute,second;
public:
Time()
{
hour=0;
minute=0;
second=0;
}
Time(int h,int m,int s)
{
hour=h;
minute=m;
second=s;
}
void resetTime(int h,int m,int s)
{
hour=h;
minute=m;
second=s;
}
void addTime(Time &T)
{
second=T.second+second;
minute=T.minute+minute+second/60;
hour=T.hour+hour+minute/60;
minute%=60;
second%=60;
}
void showTime()
{
cout<<"**********"<<endl;
cout<<"Hours : "<<hour<<endl;
cout<<"Minutes : "<<minute<<endl;
cout<<"Seconds : "<<second<<endl;
}
};
int main()
{

Time t1(22,44,55), t2(12,50,45);


t1.showTime();
t2.showTime();
t1.addTime(t2);
t1.showTime();
t2.resetTime(0,0,0);
t2.showTime();
return 0;
}

Q2.
#include <iostream>

using namespace std;

class Bank
{
int accountNumber;
double balanceAmount;
public:
Bank(int accN,double ba)
{
accountNumber=accN;
balanceAmount=ba;
}
void displayDetails()
{
cout<<"The account number is : "<<accountNumber<<endl;
cout<<"The balance amount : "<<balanceAmount<<endl;
cout<<"*******************"<<endl;
}
void MoneyTransfer(Bank *B)
{
double amount;
cout<<"Enter the amount to be transfered from account number "<<accountNumber<<" to
account number :"<<B->accountNumber<<endl;
cin>>amount;
if(amount<=balanceAmount)
{
B->balanceAmount+=amount;
balanceAmount-=amount;
}
else
{
cout<<"Not enough funds to transfer"<<endl;
}
}

};

int main()
{
Bank b1(1234,1000),b2(1245,8000);
b2.MoneyTransfer(&b1);
b1.displayDetails();
b2.displayDetails();
b1.MoneyTransfer(&b2);

return 0;
}

Q3.
#include <iostream>
using namespace std;
class Complex
{
double real,imaginary;
public:
void getData()
{
cout<<"Enter the real part : "<<endl;
cin>>real;
cout<<"Enter the imaginary part : "<<endl;
cin>>imaginary;
}
void showData()
{
cout<<"*****************"<<endl;
cout<<"The real part : "<<real<<endl;
cout<<"The imaginary part : "<<imaginary<<endl;

}
Complex addComplex(Complex *C)
{
real+=C->real;
imaginary+=C->imaginary;
return *this;
}
};
int main()
{
Complex C1,C2;
C1.getData();
C2.getData();
C1.showData();
C2.showData();
Complex C3=C1.addComplex(&C2);
C3.showData();
return 0;
}

You might also like