0% found this document useful (0 votes)
4 views14 pages

OOPSDA

The document contains code implementations for various programming tasks, including employee salary calculations using function overloading, a banking system with hierarchical inheritance for savings and current accounts, smart device management using multiple inheritance, and complex number addition with operator overloading. Each section includes class definitions, methods, and example usage in the main function. The code demonstrates key object-oriented programming concepts such as inheritance, polymorphism, and operator overloading.

Uploaded by

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

OOPSDA

The document contains code implementations for various programming tasks, including employee salary calculations using function overloading, a banking system with hierarchical inheritance for savings and current accounts, smart device management using multiple inheritance, and complex number addition with operator overloading. Each section includes class definitions, methods, and example usage in the main function. The code demonstrates key object-oriented programming concepts such as inheritance, polymorphism, and operator overloading.

Uploaded by

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

Oops assessment

(set3) and [set-4]


Name-pratyaksh Sharma
Reg.no-24bit0094
[set-3]
Q1=Employee Salary Calculation: A company needs an
overloaded function to calculate the salary of hourly employees
(based on hourly rate and hours worked) and full-me employees
(based on a fixed monthly salary). Design an overloaded function to
handle both cases.
=#include<iostream>

#include<iomanip>

using namespace std;

class calc{

public:

double calcsalary(double rate,int hrs){

return(rate*(double)hrs);

double calcsalary(double monthly){

return monthly;

};

int main() {

calc c1;

double rat=4000.73;

int hr=24;

double mnth=540456.32;

cout<<"Full time employee salary= "<<fixed<<setprecision(2)<<c1.calcsalary(mnth)<<endl;

cout<<"Hourly employee salary= "<<c1.calcsalary(rat,hr);


return 0;}

OUTPUT=

Q2=Banking System (Hierarchical Inheritance) A


BankAccount class has common attributes like
accountNumber and balance. Two derived classes:
SavingsAccount (adds interestRate calculation)
CurrentAccount (adds overdraftLimit feature) .Implement a
system where both account types inherit the base class
properties and implement their specific behaviors.
=#include <iostream>
#include <iomanip>
using namespace std;

class Account{
public:
string accno;
float inbalance;
void setdetails(string s,float init){
accno=s;
inbalance=init;
}
float deposit(float dep){
inbalance=inbalance+dep;
return (dep);
}
float withdraw(float wid){
if (inbalance < wid){
cout << "Invalid Withdraw amount" << endl;
}else{
inbalance=inbalance-wid;
return (wid);
}
}
float getbal(void){
return (inbalance);
}
};
class Savings:public Account{
public:
float interest;
float intam;
void setinterest(float in){
interest=in;
}
float getinterest(void){
return (interest);
}
float calcinterest(void){
float r = inbalance*interest/100.0;
cout << "r = " << r << endl;
inbalance = inbalance + r;
intam = r;
}
float getInt(){
return intam;
}
};
class Current:public Account{
public:
float limit;
void setlimit(float lim){
limit=lim;
}
float getlimit(){
return limit;
}

};
int main(){
string sacn;float sinb,siner,sdepo,swith;
string cacn;float cinb,ciner,cdepo,cwith,lim;
cout<<"Enter account number and initial balance:"<<endl;
cin>>sacn>>sinb;

Savings s1;
s1.setdetails(sacn,sinb);
s1.setinterest(siner);
cout<<"Saving Account:"<<endl;
cout<<"Enter the amount to be deposited in savings :"<<endl;
cin>>sdepo;
cout<<"enter the amount to be withdrawn in savings :"<<endl;
cin>>swith;
cout<<"Enter the interest to be addded:"<<endl;
cin>>siner;

Current c1;
c1.setdetails(sacn,sinb);
cout<<"Current account:"<<endl;
cout<<"Enter the amount to be deposited in current:"<<endl;
cin>>cdepo;
cout<<"enter the amount to be withdrawn in current :"<<endl;
cin>>cwith;
cout<<"Enter the limit :"<<endl;
cin>>lim;

cout << "\n\nSavings Account" <<endl;


cout << "Account No. "<< s1.accno << ", balance " << s1.getbal() << endl;
cout << "Deposited " << s1.deposit(sdepo)<<" successfully."<<endl;
cout << "Current Balance " << s1.getbal() << endl;
cout << "Withdrawn " << s1.withdraw(swith)<<" successfully."<<endl;
cout << "Current Balance " << s1.getbal() << endl;
s1.interest = siner;
s1.calcinterest();
cout << "Interest added on remaining balance= "<< fixed << setprecision(2)<<
s1.getInt() <<endl;
cout << "Current Balance " << s1.getbal() << endl;

cout << "Current Account" <<endl;


cout << "Account No. "<< c1.accno << ", balance " << c1.getbal() << endl;
cout << "Deposited " << c1.deposit(sdepo)<<" successfully."<<endl;
cout << "Current Balance " << s1.getbal() << endl;
cout << "Withdrawn " << c1.withdraw(swith)<<" successfully."<<endl;
cout << "Current Balance " << s1.getbal() << endl;
c1.setlimit(lim);
cout << "The limit for current account is "<<fixed <<
setprecision(2)<<c1.getlimit()<<endl;
cout << "Current Balance " << s1.getbal() << endl;
return 0;
}
OUTPUT=
INPUT-
OUTPUT=
[SET-4]
Q2=Smart Device Management (Multiple Inheritance) A
TouchScreenDevice class has a method touchInput(). A
VoiceAssistantDevice class has a method voiceCommand(). A
Smartphone class inherits from both and should be able to use both
touchInput() and voiceCommand(). Implement a program showing
multiple inheritance in action.
=#include<iostream>
#include<string>
using namespace std;

class touchscreendevice{
public:
string touch;
void settouchinput(string s){
touch=s;
cout<<"Touch input have been detected at "<<touch<<endl;
}
};

class voiceassistantdevice{
public:
string voice;
void setvoicecommand(string v){
voice=v;
cout<<"Voice command has been detected as : "<<voice<<endl;
}
};

class smartphone:public touchscreendevice,public voiceassistantdevice {


public:
void start(void){
cout<<"Enter the input: "<<endl;
}
};

int main() {
string tch,vc;
smartphone s1;
cout<<"Enter what app to touch: "<<endl;
cin>>tch;
cin.ignore();
cout<<"Enter the voice command: "<<endl;
getline(cin,vc);
s1.settouchinput(tch);
s1.setvoicecommand(vc);
return 0;
}
OUTPUT=

Q1=Complex Number Addition: Create a Complex class and overload


the + operator to allow the addition of two complex numbers. The
addition should be based on adding the real and imaginary parts
separately.
=#include <iostream>
using namespace std;

class Complex {

public:

double real, imag;

Complex(double r = 0.0, double i = 0.0) {

real = r;

imag = i;

Complex operator +(Complex& other) {

Complex result;

result.real = real + other.real;

result.imag = imag + other.imag;

return result;

void display() {

cout << real << " + " << imag << "i\n";

}};
int main() {

Complex c1(1, 2), c2(3, 4);

Complex c3 = c1+c2;

c3.display();

return 0;

OUTPUT=

You might also like