Home Work - 1 Programming Oops CAP-320
Home Work - 1 Programming Oops CAP-320
PROGRAMMING OOPS
CAP-320
Course Instructor: _Mr. DEEPAK MEHTA Course Tutor (if applicable): ___________ _
Declaration:
I declare that this assignment is my individual work. I have not copied from any other student’s
work or from any other source except where due acknowledgment is made explicitly in the text,
nor has any part been written for me by another person.
Student’s Signature
DUSHYANT SINGH
Evaluator’s comments:
_______________________________________________________________
#include<iostream.h>
#include<conio.h>
void main()
{
float mtr,mrp,fp,disc;
clrscr();
cout<<"ENTER SIZE IN METERES:";
cin>>mtr;
cout<<"ENTER MRP OF CLOTHES:";
cin>>mrp;
if(mrp<=500 && mtr<=2)
{
disc=(mrp*3.5)/100;
fp=mrp-disc;
}
else if((mrp>500 && mrp<=1000) && (mtr>2 && mtr<=10))
{
disc=(mrp*6.5)/100;
fp=mrp-disc;
}
else if((mrp>1000 && mrp<=5000) && (mtr>10 && mtr<=40))
{
disc=(mrp*10)/100;
fp=mrp-disc;
}
else if(mrp>5000 && mtr>40)
{
disc=(mrp*14)/100;
fp=mrp-disc;
}
else
{
disc=0;
fp=mrp;
}
cout<<"\n\n\t\tYOUR BILL:\n\n";
cout<<"YOUR PRISE :"<<mrp;
cout<<"\nYOUR DISCOUNT :"<<disc;
cout<<"\nYOUR FINAL PRISE :"<<fp;
getch();
}
OUTPUT:
ENTER SIZE IN METERES:20
ENTER MRP OF CLOTHES:5000
YOUR BILL:
2. Write a program to find all the Armstrong numbers between 30000 &
100.
ANSWER:
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,k,sum;
clrscr();
cout<<"Armstrong numbers between 100 and 30000 are :\n";
for(i=100; i<=30000; i++)
{
j=i;
sum=0;
while(j>0)
{
k=j%10;
sum=sum+(k*k*k);
j=j/10;
}
if(i==sum)
cout<<"\n"<<i;
}
getch();
}
OUTPUT:
153
370
371
407
ANSWER:
#include<iostream.h>
#include<conio.h>
void main()
{
char name[10],gen;
int age;
long int salary,temp,tax=0;
clrscr();
cout<<"\nENTER EMPLOYE NAME : ";
cin>>name;
cout<<"\nENTER GENDER : ";
cin>>gen;
cout<<"\nENTER AGE : ";
cin>>age;
cout<<"\nENTER SALARY : ";
cin>>salary;
if(gen=='M' || gen=='m')
{
if(age>65)
{
if(salary<190000)
cout<<"\nNO TAX";
else if(salary>190000 && salary<=300000)
{
temp=salary-190000;
tax=(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
else if(salary>300000 && salary<=500000)
{
temp=salary-300000;
tax=tax+(temp*20)/100;
temp=300000-190000;
tax=tax+(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
else if(salary>500000 && salary<=1000000)
{
temp=salary-500000;
tax=tax+(temp*30)/100;
temp=500000-300000;
tax=tax+(temp*20)/100;
temp=300000-190000;
tax=tax+(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
else
{
temp=salary-1000000;
tax=tax+(temp*33)/100;
temp=1000000-500000;
tax=tax+(temp*30)/100;
temp=500000-300000;
tax=tax+(temp*20)/100;
temp=300000-190000;
tax=tax+(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
}
else
{
if(salary<160000)
cout<<"\nNO TAX";
else if(salary>160000 && salary<=300000)
{
temp=salary-160000;
tax=(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
else if(salary>300000 && salary<=500000)
{
temp=salary-300000;
tax=tax+(temp*20)/100;
temp=300000-160000;
tax=tax+(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
else if(salary>500000 && salary<=1000000)
{
temp=salary-500000;
tax=tax+(temp*30)/100;
temp=500000-300000;
tax=tax+(temp*20)/100;
temp=300000-160000;
tax=tax+(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
else
{
temp=salary-1000000;
tax=tax+(temp*33)/100;
temp=1000000-500000;
tax=tax+(temp*30)/100;
temp=500000-300000;
tax=tax+(temp*20)/100;
temp=300000-160000;
tax=tax+(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
}
}
else if(gen=='f' || gen=='F')
{
if(age>65)
{
if(salary<220000)
cout<<"\nNO TAX";
else if(salary>220000 && salary<=300000)
{
temp=salary-220000;
tax=(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
else if(salary>300000 && salary<=500000)
{
temp=salary-300000;
tax=tax+(temp*20)/100;
temp=300000-220000;
tax=tax+(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
else if(salary>500000 && salary<=1000000)
{
temp=salary-500000;
tax=tax+(temp*30)/100;
temp=500000-300000;
tax=tax+(temp*20)/100;
temp=300000-220000;
tax=tax+(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
else
{
temp=salary-1000000;
tax=tax+(temp*33)/100;
temp=1000000-500000;
tax=tax+(temp*30)/100;
temp=500000-300000;
tax=tax+(temp*20)/100;
temp=300000-220000;
tax=tax+(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
}
else
{
if(salary<190000)
cout<<"\nNO TAX";
else if(salary>190000 && salary<=300000)
{
temp=salary-190000;
tax=(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
else if(salary>300000 && salary<=500000)
{
temp=salary-300000;
tax=tax+(temp*20)/100;
temp=300000-190000;
tax=tax+(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
else if(salary>500000 && salary<=1000000)
{
temp=salary-500000;
tax=tax+(temp*30)/100;
temp=500000-300000;
tax=tax+(temp*20)/100;
temp=300000-190000;
tax=tax+(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
else
{
temp=salary-1000000;
tax=tax+(temp*33)/100;
temp=1000000-500000;
tax=tax+(temp*30)/100;
temp=500000-300000;
tax=tax+(temp*20)/100;
temp=300000-190000;
tax=tax+(temp*10)/100;
cout<<"\nSALARY = "<<salary;
cout<<"\nTAX = "<<tax;
}
}
}
getch();
}
OUTPUT:
ENTER GENDER :m
ENTER AGE : 76
SALARY = 460000
TAX = 43000
PART B
4. Write a program to calculate salary of an employee by using structures.
ANSWER:
#include<iostream.h>
#include<conio.h>
struct emp
{
char name[20];
float bs,gs,da,hra,pf,ns;
}e;
void main()
{
clrscr();
cout<<"\nENTER EMPLOYEE NAME : ";
cin>>e.name;
cout<<"\nENTER Basic Salary : ";
cin>>e.bs;
cout<<"NAME : "<<e.name;
if(e.bs<20000)
{
e.hra=e.bs*10/100;
e.da=e.bs*15/100;
e.pf=((e.bs+e.da)*8)/100;
e.gs=e.bs+e.da+e.hra;
e.ns=e.gs-e.pf;
cout<<"\nNET SALARY : "<<e.ns;
cout<<"\nGROSS SALARY : "<<e.gs;
}
else
{
e.hra=e.bs*20/100;
e.da=e.bs*25/100;
e.pf=((e.bs+e.da)*15)/100;
e.gs=e.bs+e.da+e.hra;
e.ns=e.gs-e.pf;
cout<<"\nNET SALARY : "<<e.ns;
cout<<"\nGROSS SALARY : "<<e.gs;
}
getch();
}
OUTPUT:
ENTER EMPLOYEE NAME : dushyant
ENTER Basic Salary : 200000
NAME : dushyant
NET SALARY : 252500
GROSS SALARY : 290000
ANSWER:
This programming task, is to calculate ANY binomial coefficient.
#include<iostream.h>
#include<conio.h>
double result_next;
double pc = nValue;
do
result_next = result*(pc-1);
result = result_next;
pc--;
}while(pc>2);
nValue = result;
return nValue;
double result;
nValue2 = result;
return nValue2;
int main()
int a,b;
clrscr();
cin>>a>>b;
cout<<EvaluateBinomialCoefficient(a,b);
getch();
}
OUT PUT:
The Binomial Coefficient of 5 and 3 is equal to: 10
ANSWER:
#include<iostream.h>
#include<conio.h>
#include<string.h>
#define MAX 1000
struct company{
char name[20];
long int employee_id;
char sex[5];
int age;
// nested block defination
struct date dob;
};
// functions calling
CollectInformtion(employee, n);
Display(employee, n);
cin.get();
return 0;
}
// collecting information form the user
void CollectInformtion(company employee[MAX], int n){
cout << "Enter the following information:";
cout << endl << endl;