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

Home Work - 1 Programming Oops CAP-320

This document contains a homework assignment for a programming course with 3 programming questions. The first question asks to write a program to print a sale bill for a garment house applying different discount rates based on the item price and quantity. The second question asks to write a program to find all Armstrong numbers between 100 and 30000. The third question asks to write a program to calculate income tax for an employee according to the current Indian income tax slabs.

Uploaded by

Dushyant Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Home Work - 1 Programming Oops CAP-320

This document contains a homework assignment for a programming course with 3 programming questions. The first question asks to write a program to print a sale bill for a garment house applying different discount rates based on the item price and quantity. The second question asks to write a program to find all Armstrong numbers between 100 and 30000. The third question asks to write a program to calculate income tax for an employee according to the current Indian income tax slabs.

Uploaded by

Dushyant Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 16

HOME WORK – 1

PROGRAMMING OOPS
CAP-320

Homework Title / No. : ___ 1_____________Course Code: __CAP-320 _

Course Instructor: _Mr. DEEPAK MEHTA Course Tutor (if applicable): ___________ _

Date of Allotment: _____21-Jan-2011 _____ Date of submission: __ 04-fab-2011______

Student’s Roll No. B55 Section No. : D3002


.

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:
_______________________________________________________________

Marks obtained: ___________ out of ______________________


PART-A

1. Write a Program to Print Sale Bill of a Garment House, with following

terms of discount on each product :-

• if MRP is less than or equals to 500 and quantity sold is less


than or equals to 2 Mtr, then discount = 3.5%
• if MRP is greater than 500 and less than or equals to 1000 and
quantity sold is more than 2 mtr and less than or equals to 10 Mtr,
then discount = 6.5%
• if MRP is greater than 1000 and less than or equals to 5000
and quantity sold is more than 10 mtr and less than 40 mtr., then
discount = 10%
• otherwise discount is 14%.
ANSWER:

#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:

YOUR PRISE :5000


YOUR DISCOUNT :500
YOUR FINAL PRISE :4500

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:

Armstrong numbers between 100 and 30000 are :

153
370
371
407

3. Write a program to calculate income tax for a employee according to

current Income Tax criteria that is being followed.

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 EMPLOYE NAME : dushyant

ENTER GENDER :m

ENTER AGE : 76

ENTER SALARY : 460000

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 if(e.bs>=20000 && e.bs<50000)


{
e.hra=e.bs*15/100;
e.da=e.bs*20/100;
e.pf=((e.bs+e.da)*12)/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

5. Write a program to calculate binomial coefficient using functions.

ANSWER:
This programming task, is to calculate ANY binomial coefficient.

However, it has to be able to output , which is 10.

This formula is recommended:

#include<iostream.h>

#include<conio.h>

double Factorial(double nValue)

double result = nValue;

double result_next;

double pc = nValue;

do

result_next = result*(pc-1);
result = result_next;

pc--;

}while(pc>2);

nValue = result;

return nValue;

double EvaluateBinomialCoefficient(double nValue, double nValue2)

double result;

if(nValue2 == 1)return nValue;

result = (Factorial(nValue))/(Factorial(nValue2)*Factorial((nValue - nValue2)));

nValue2 = result;

return nValue2;

int main()

int a,b;

clrscr();

cout<<"emter two values for binomial cofficient:";

cin>>a>>b;

cout<<"The Binomial Coefficient of "<<a<<"and"<<b<<"is equql to:";

cout<<EvaluateBinomialCoefficient(a,b);

getch();

}
OUT PUT:
The Binomial Coefficient of 5 and 3 is equal to: 10

6. Write a program to show usage of nested structures in C++.

ANSWER:

#include<iostream.h>
#include<conio.h>
#include<string.h>
#define MAX 1000

// structure block defination


struct date{
// members of structure definition
int day;
int month;
int year;
};

struct company{
char name[20];
long int employee_id;
char sex[5];
int age;
// nested block defination
struct date dob;
};

// structuer object defination


company employee[MAX];
// main function starts
int main()
{
company employee[MAX];
int n;
clrscr();
cout << "A program for collecting employee information";
cout << endl;
cout << "And displaying the collected information";
cout << endl << endl;
cout << "How many employees:";
cin >> n;
cout << endl;
// functions defination
void CollectInformtion(company employee[MAX], int n);
void Display(company employee[MAX], int n);

// 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;

for (int i=1; i<=n; i++){


cout << "Enter information for employee no: " << i;
cout << endl;
cout << "Name :"; cin >> employee[i].name;
cout << "ID :"; cin >> employee[i].employee_id;
cout << "Sex :"; cin >> employee[i].sex;
cout << "Age :"; cin >> employee[i].age;
cout << "Date of Birth:" << endl;
cout << "Day :"; cin >> employee[i].dob.day;
cout << "Month :"; cin >> employee[i].dob.month;
cout << "Year :"; cin >> employee[i].dob.year;

cout << endl;


}
}
// displaying entered information to the standard output
void Display(company employee[MAX], int n){
cout << "Employee entered information:";
cout << endl;
cout << "Name ID Sex Age Date of Birth" << endl;
for (int i=1; i<=n; i++)
{
cout << employee[i].name << "\t";
cout << employee[i].employee_id << "\t";
cout << employee[i].sex; cout << "\t";
cout << employee[i].age; cout << "\t";
cout << employee[i].dob.day << ".";
cout << employee[i].dob.month << ".";
cout << employee[i].dob.year ;

cout << endl;


}
getch();
}

Output of the program

You might also like