0% found this document useful (0 votes)
33 views

Assignment 7

The document discusses 3 C++ programs - the first defines classes for 1D, 2D and 3D coordinates with inheritance, the second defines classes for currency conversion between rupees to dollars and euros with inheritance, and the third defines classes for employee data and tax calculation with a nested struct and inheritance to calculate income tax.

Uploaded by

Soumyadeep Maji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Assignment 7

The document discusses 3 C++ programs - the first defines classes for 1D, 2D and 3D coordinates with inheritance, the second defines classes for currency conversion between rupees to dollars and euros with inheritance, and the third defines classes for employee data and tax calculation with a nested struct and inheritance to calculate income tax.

Uploaded by

Soumyadeep Maji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1

Assignment 7
Question 1
Ans:
PROGRAM:
#include <iostream>
using namespace std;
class one_d
{public:
int x;
one_d(int a)
{x=a;
}
one_d()
{x=0;
}
void display(void)
{cout<<"x coordinate: "<<x<<endl;
}
};
class two_d: public one_d
{public:
int y;
two_d()
{x=0;
y=0;
}
two_d(int a,int b)
{y=b;
x=a;
}
void display(void)
2

{cout<<"x coordinate: "<<x<<endl;


cout<<"y coordinate: "<<y<<endl;
}
};
class three_d: public two_d
{public:
int z;
three_d()
{x=0;
y=0;
z=0;
}
three_d(int a,int b,int c)
{z=c;
x=a;
y=b;
}
void display(void)
{cout<<"x coordinate: "<<x<<endl;
cout<<"y coordinate: "<<y<<endl;
cout<<"z coordinate: "<<z<<endl;
}
};
int main()
{cout<<"Enter 3 D coordinates: ";
int a,b,c;
cin>>a>>b>>c;
three_d a1(a,b,c);
a1.display();
cout<<"Enter 2 D coordinates: ";
cin>>a>>b;
two_d a2(a,b);
3

a2.display();
cout<<"Enter 1 D coordinates: ";
cin>>a;
one_d a3(a);
a3.display();
}

OUTPUT:

Question 2:
Ans.:
PROGRAM:
#include<iostream>
using namespace std;
class Exchange
{protected :
double rs,exchangeRate,amount;
public:
double rupees,rate;
void convert();
void display();
Exchange()
4

{rs=rupees;
exchangeRate=rate;
}
};
class Rs_to_Dollar:public Exchange
{public:
Rs_to_Dollar()
{rate=70;
}
};
class Rs_to_Euro: public Exchange
{public:
Rs_to_Euro()
{rate=75;
}
};
void Exchange::convert()
{amount=rupees/rate;
}
void Exchange::display()
{cout<<"The amount is "<<amount<<endl;
}
int main()
{Rs_to_Dollar A;
Rs_to_Euro B;
cout<<"Please enter the amounts to be converted"<<endl;
cin>>A.rupees>>B.rupees;
cout<<" for Dollars: ";
A.convert();
A.display();
cout<<" for Euros: ";
B.convert();
B.display();
5

OUTPUT:

Question 3:
Ans:
PROGRAM:
#include <iostream>
using namespace std;
class Employee
{public:
int pan, taxin;
string name;
void inputdata(void)
{cout<<"Enter name :";
cin>>name;
cout<<"Enter PAN: ";
cin>>pan;
cout<<"Enter taxable income: ";
cin>>taxin;
}
void displaydata(void)
6

{cout<<"Name "<<name<<" PAN "<<pan<<" Total taxable income


"<<taxin;
}
};
struct Address{
char Street[12];
char Place[12];
long Pincode;
};
class Taxcalc: public Employee
{private:
float Tax;
Address add;
public:
void computetax(int taxin)
{if(taxin<60000)
{Tax=0;
}
else if(taxin<150000)
{Tax=taxin*0.05;
}
else if(taxin<500000)
{Tax=taxin*0.10;
}
else
{Tax=taxin*0.15;
}
cout<<" Tax "<<Tax<<endl;
}
};
int main()
{for(int i=0;i<10;i++)
{Employee e;
e.inputdata();
7

Taxcalc t;
e.displaydata();
t.computetax(e.taxin);
}
}
OUTPUT:

You might also like