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

CPP Program-B.com (CA)

The document discusses several methods for calculating depreciation, interest, payroll, inventory costs and more. Code examples are provided to demonstrate how to calculate straight-line depreciation, diminishing balance depreciation, simple and compound interest, economic order quantity, employee payroll and net income. Various classes and functions are defined to obtain input values, perform calculations and output results.

Uploaded by

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

CPP Program-B.com (CA)

The document discusses several methods for calculating depreciation, interest, payroll, inventory costs and more. Code examples are provided to demonstrate how to calculate straight-line depreciation, diminishing balance depreciation, simple and compound interest, economic order quantity, employee payroll and net income. Various classes and functions are defined to obtain input values, perform calculations and output results.

Uploaded by

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

1.

Straight Line Method

#include<iostream.h>
#include<conio.h>
class depreciation
{
private:
long int c,s,l;
float amt,rate;
public:
void getdata();
void calculate();
void showresult();
};
void depreciation::getdata()
{
cout<<"enter the cost of asset:\n";
cin>>c;
cout<<"enter the value of scrap:\n";
cin>>s;
cout<<"enter the no.of years:\n";
cin>>l;
}
void depreciation::calculate()
{
amt=(c-s)/l;
rate=(amt/c)*100;
}
void depreciation::showresult()
{
cout<<"\n the amount of depreciation="<<amt;
cout<<"\n the rate of depreciation="<<rate;
}
void main()
{
clrscr();
depreciation d;
d.getdata();
d.calculate();
d.showresult();
getch();
}
Input

enter the cost of asset:


10000
enter the value of scrap:
1000
enter the no.of years:
5

Output
the amount of depreciation=1800
the rate of depreciation=18
2. Diminishing Balance Method

#include<iostream.h>
#include<conio.h>
class diminishing
{
float c,s,l,rate,dep[10];
public:
void getdata()
{
cout<<"enter the cost value:";
cin>>c;
cout<<"\n enter the scrap value:";
cin>>s;
cout<<"\n enter the life time:";
cin>>l;
cout<<"\n enter the rate of interest:";
cin>>rate;
}
void calculate()
{
for(int i=1;i<=1;i++)
{
dep[i]=((c*rate)/100);
cout<<"\n amount of the depriciation in year"<<i<<"->"<<dep[i]<<endl;
c=(c-(c*rate)/100);
}
}
};
void main()
{
clrscr();
diminishing d;
d.getdata();
d.calculate();
getch();
}
Input:

enter the cost value:15000

enter the scrap value:1000

enter the life time:5

enter the rate of interest:4

Output:

amount of the depreciation in year1->600

amount of the depreciation in year2->576

amount of the depreciation in year3->552.960022

amount of the depreciation in year4->530.841614

amount of the depreciation in year5->509.607941


3. Economic Order Quantity

#include<iostream.h>
#include<conio.h>
#include<math.h>
class quantity
{
private:
long int a,c,i;
float eoq,no,tg;
public:
void getdata();
void calculate();
void showresult();
};
void quantity::getdata()
{
cout<<"enter the annual consumption:"<<endl;
cin>>a;
cout<<"\n enter the ordering cost:"<<endl;
cin>>c;
cout<<"\n enter the carrying cost:"<<endl;
cin>>i;
calculate();
showresult();
}
void quantity::calculate()
{
eoq=sqrt((2*a*c)/i);
no=(a/eoq);
tg=365/no;
}
void quantity::showresult()
{
cout<<"economic ordering quantity="<<eoq;
cout<<"\n no of orders="<<no;
cout<<"\n time gap between orders="<<tg;
}
void main()
{
clrscr();
quantity ql;
ql.getdata();
}
Input
enter the annual consumption: 150000
enter the ordering cost: 60000
enter the carrying cost: 100000
Output
economic ordering quantity=90.559372
no of orders=1656.371948
time gap between orders=0.220361
4. Employee Payroll Statement

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
char name[20],dep[20];
int des,perk;
float basic,da,hra,cca,gross,sd,net;
clrscr();
cout<<"enter the name of the employee:"<<endl;
cin>>name;
cout<<"\n enter the department of employee:"<<endl;
cin>>dep;
cout<<"\n enter the basic pay per annum:"<<endl;
cin>>basic;
abc:
cout<<"\n enter the designation of employee:"<<endl;
cin>>des;
switch(des)
{
case 1:
perk=1000;
break;
case 2:
perk=750;
break;
case 3:
perk=500;
break;
case 4:
perk=250;
break;
default:
cout<<"\n enter the correct designation from 1 to 4";
goto abc;
}
da=basic*.20;
hra=basic*.12;
cca=basic*.10;
gross=(basic+da+hra+cca+perk);
if(gross<=75000)
{
sd=gross*.40;
}
else if(gross>75000 && gross<500000)
{
sd=30000;
}
else if(gross<500000)
{
sd=20000;
}
net=gross-sd;
cout<<"\n--------------------------------------";
cout<<"\n PAY ROLL STATEMENT";
cout<<"\n -------------------------------------";
cout<<"\n nameof the employee:"<<name;
cout<<"\n department of the employee:"<<dep;
cout<<"\n basic pay of the employee:"<<basic;
cout<<"\n da of the employee:"<<da;
cout<<"\n hra of the employee:"<<hra;
cout<<"\n cca of the employee:"<<cca;
cout<<"\n prerequisites of the employee:"<<perk;
cout<<"\n gp of the employee:"<<gross;
cout<<"\n sd of the employee:"<<sd;
cout<<"\n------------------------------------";
cout<<"\n net pay of the employee:"<<net;
cout<<"\
n==================================================="<<endl;
getch();
}
Input
enter the name of the employee: kowsi

enter the department of employee: commerce

enter the basic pay per annum: 100000

enter the designation of employee: 1


Output
--------------------------------------
PAY ROLL STATEMENT
-------------------------------------
nameof the employee:kowsi
department of the employee:commerce
basic pay of the employee:100000
da of the employee:20000
hra of the employee:12000
cca of the employee:10000
prerequisites of the employee:1000
gp of the employee:143000
sd of the employee:30000
------------------------------------
net pay of the employee:113000
===================================================
5. Simple Interest & Compound Interest

#include<iostream.h>
#include<conio.h>
#include<math.h>
class simple
{
private:
long int p,n;
float r,si;
public:
void getdata();
void calculate();
void display();
class compound
{
private:
long int p,n;
float c,r,ci;
public:
void getdata();
void calculate();
void display();
};
};
void simple::getdata()
{
cout<<"\n enter the amount of principal:";
cin>>p;
cout<<"\n enter the no of years:";
cin>>n;
cout<<"\n enter the rate of interest:";
cin>>r;
}
void simple::compound::getdata()
{
cout<<"\n enter the amount of principal:";
cin>>p;
cout<<"\n enter the no of years:";
cin>>n;
cout<<"\n enter the rate of interest:";
cin>>r;
}
void simple::calculate()
{
si=(p*n*r)/100;
}
void simple::compound::calculate()
{
c=pow(1+(r/100),n);
ci=p*c;
}
void simple::display()
{
cout<<"\n simple interest="<<si;
}
void simple::compound::display()
{
cout<<"\n:compound interest="<<ci;
}
void main()
{
clrscr();
simple s;
simple::compound c;
s.getdata();
s.calculate();
c.getdata();
c.calculate();
s.display();
c.display();
getch();
}
Input
enter the amount of principal:200000

enter the no of years:10

enter the rate of interest:10

enter the amount of principal:500000

enter the no of years:5

enter the rate of interest:10

Output
simple interest=200000
compound interest=805255
6. Net Income Of a Family

#include<iostream.h>
#include<conio.h>
class husband;
class wife
{
private:
float salary;
public:
void getdata()
{
cout<<"enter the amount of salary received from wife:";
cin>>salary;
}
friend void calculate(wife,husband);
};
class husband
{
private:
float salary;
public:
void getdata()
{
cout<<"enter the amount of salary received from husband:";
cin>>salary;
}
friend void calculate(wife,husband);
};
void calculate(wife w,husband h)
{
float c;
c=w.salary+h.salary;
cout<<"\n net income of the family is:"<<c;
}
void main()
{
clrscr();
wife w1;
husband h1;
w1.getdata();
h1.getdata();
calculate(w1,h1);
getch();
}
Input
enter the amount of salary received from wife:20000
enter the amount of salary received from husband:400000

Output
net income of the family is:420000
7. Library Book List

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class book
{
private:
int acc_no;
char title[20];
char author[20];
float price;
public:
void getdata()
{
cout<<"enter the accession number:";
cin>>acc_no;
cout<<"enter the title of the book:";
cin>>title;
cout<<"enter the name of the author:";
cin>>author;
cout<<"enter the price of the book:";
cin>>price;
}
void display()
{
cout<<acc_no<<'\t'<<title<<'\t'<<author<<'\t'<<setprecision(2)<<price<<endl;
}
};
void main()
{
clrscr();
book b[100];
int n,i;
cout<<"enter the number of book to add:";
cin>>n;
for(i=0;i<n;i++)
b[i].getdata();
cout<<"-----------------------------------"<<endl;
cout<<"Acc_no Title Author price"<<endl;
cout<<"-----------------------------------"<<endl;
for(i=0;i<n;i++)
b[i].display();
getch();
}
INPUT
enter the number of book to add:2
enter the accession number:12305
enter the title of the book:c++
enter the name of the author:kowsi
enter the price of the book:250
enter the accession number:12307
enter the title of the book:gf
enter the name of the author:hgt
enter the price of the book:678

OUTPUT
-----------------------------------
Acc_no Title Author price
-----------------------------------
12305 c++ kowsi 250
12307 gf hgt 678
8. Cost Sheet

#include<iostream.h>
#include<conio.h>
class cost
{
protected:
long int pc,dm,dl,de;
public:
void getdata()
{
cout<<"enter the direct material"<<endl;
cin>>dm;
cout<<"enter the direct labour"<<endl;
cin>>dl;
cout<<"enter the direct expenses"<<endl;
cin>>de;
}
void calculate()
{
pc=dm+dl+de;
}
void display()
{
cout<<"prime cost"<<pc<<endl;
}
};
class sheet:public cost
{
protected:
long int wc,foh,ooh,soh,cop,cos,profit,sales;
public:
void getdata1()
{
getdata();
cout<<"enter the factory overhead"<<endl;
cin>>foh;
cout<<"enter the office overhead"<<endl;
cin>>ooh;
cout<<"enter the selling overhead"<<endl;
cin>>soh;
cout<<"enter the sales"<<endl;
cin>>sales;
}
void calculate1()
{
calculate();
wc=pc+foh;
cop=wc+ooh;
cos=cop+soh;
profit=sales-cos;
}
void display1()
{
cout<<"-----------------------------------"<<endl;
cout<<" COST SHEET "<<endl;
cout<<"----------------------------------"<<endl;
cout<<"direct matreial "<<dm<<endl;
cout<<"direct labour "<<dl<<endl;
cout<<"direct expenses "<<de<<endl;
cout<<"...................................."<<endl;
cout<<"prime cost =" <<pc<<endl;
cout<<"factory overhead "<<foh<<endl;
cout<<"..................................."<<endl;
cout<<"work cost ="<<wc<<endl;
cout<<"office overhead "<<ooh<<endl;
cout<<"....................................."<<endl;
cout<<"cost of production ="<<cop<<endl;
cout<<"selling overhead "<<soh<<endl;
cout<<"....................................."<<endl;
cout<<"cost of sales ="<<cos<<endl;
cout<<"profit "<<profit<<endl;
cout<<"----------------------------------"<<endl;
cout<<"sales ="<<sales<<endl;
}
};
void main()
{
clrscr();
sheet cs;
cs.getdata1();
cs.calculate1();
cs.display1();
getch();
}
INPUT

enter the direct material


100000
enter the direct labour
10000
enter the direct expenses
12000
enter the factory overhead
5000
enter the office overhead
4500
enter the selling overhead
6000
enter the sales
175000

OUTPUT
-----------------------------------
COST SHEET
----------------------------------
direct matreial 100000
direct labour 10000
direct expenses 12000
....................................
prime cost =122000
factory overhead 5000
...................................
work cost =127000
office overhead 4500
.....................................
cost of production =131500
selling overhead 6000
.....................................
cost of sales =137500
profit 37500
----------------------------------
sales =175000
9. Margin Of Safety

#include<iostream.h>
#include<conio.h>
class a
{
public:
float as;
};
class b: public a
{
public:
float bes;
void get()
{
cout<<"\n enter value for actual sales:";
cin>>as;
cout<<"\n enter the values for breakeven sales:";
cin>>bes;
}
};
class c:public b
{
public:
float mos;
void margin()
{
mos=as-bes;
cout<<"\n margin of safety="<<mos;
}
};
void main()
{
clrscr();
cout<<"\n\n magrin of safety\n\n";
c c1;
c1.get();
c1.margin();
getch();
}
INPUT

magrin of safety
enter value for actual sales:12000
enter the values for breakeven sales:20000

OUTPUT

margin of safety=-8000
10. Bank Transaction

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class account
{
private:
char name[25];
int accno;
float balance;
float rate;
public:
account();
~account();
void deposit();
void withdraw();
void getinterest();
void getbalance();
void menu();
};
account::account()
{
cout<<"enter the name:";
cin>>name;
cout<<"enter the number:";
cin>>accno;
cout<<"enter the balance:";
cin>>balance;
cout<<"enter the rate of interest:";
cin>>rate;
}
account::~account()
{
cout<<"delete the database"<<endl;
}
void account::deposit()
{
float amount;
cout<<"enter the amount of deposit:";
cin>>amount;
balance=balance+amount;
cout<<"amount after deposit="<<balance<<endl;
}
void account::withdraw()
{
float amount;
cout<<"how much amount do you want to withdraw?";
cin>>amount;
if(amount<balance)
{
balance=balance-amount;
cout<<"amount withdraw="<<amount<<endl;
cout<<"balance amount="<<balance<<endl;
}
else
{
cout<<"amount not sufficient"<<endl;
}
}
void account::getinterest()
{
float intamount;
intamount=(balance*rate)/100;
balance=balance+intamount;
cout<<"amount of interest="<<intamount<<endl;
cout<<"balance amount="<<balance<<endl;
}
void account::getbalance()
{
cout<<"currentbalance"<<balance;
}
void account::menu()
{
cout<<"d=deposit"<<endl;
cout<<"w=withdraw"<<endl;
cout<<"i=interest"<<endl;
cout<<"q=quit"<<endl;
cout<<"option,please?"<<endl;
}
void main()
{
clrscr();
account bank;
char ch;
bank.menu();
while((ch=getchar())!='q')
{
switch(ch)
{
case 'd':
bank.deposit();
break;
case 'w':
bank.withdraw();
break;
case 'i':
bank.getinterest();
break;
case 'g':
bank.getbalance();
break;
}
}
getch();
}
INPUT
enter the name:Kowsalya.P
enter the number:120897
enter the balance:1000000
enter the rate of interest:10
d=deposit
w=withdraw
i=interest
q=quit
option,please?
d

OUTPUT

enter the amount of deposit:10000


amount after deposit=1010000
w
how much amount do you want to withdraw?10500
amount withdraw=10500
balance amount=999500
i
amount of interest=99950
balance amount=1099450
11. Working Captial

#include<iostream.h>
#include<conio.h>
class over
{
long int asset,liability;
public:
void getdata();
void operator-(over&);
};
void over::getdata()
{
cout<<"enter the current asset=";
cin>>asset;
cout<<"enter the current liability=";
cin>>liability;
cout<<endl;
}
void over::operator-(over&b)
{
long int result1,result2;
result1=asset-b.asset;
if(result1>0)
cout<<"derease in working capital due to decrease in current asset="<<result1<<endl;
else if (result1<0)
cout<<"increase in working capital due to decrease in current="<<(1*result1)<<endl;
result2=liability-b.liability;
if(result2>0)
cout<<"increase in working capital due to decrease in current
liability="<<result2<<endl;
else if(result2<0)
cout<<"decrease in working capital due to increase in current
liability="<<(1*result2)<<endl;
}
void main()
{
clrscr();
over period1,period2;
cout<<"enter detalis for period1"<<endl;
period1.getdata();
cout<<"enter detalisfor period2"<<endl;
period2.getdata();
period1-period2;
getch();
}
INPUT

enter detalis for period1


enter the current asset=180000
enter the current liability=45000

enter detalisfor period2


enter the current asset=200000
enter the current liability=50000

OUTPUT

increase in working capital due to decrease in current=-20000


decrease in working capital due to increase in current liability=-5000
12. Students Mark List

#include<conio.h>
#include<fstream.h>
void main()
{
int rollno,m1,m2,m3,tot;
char name[20],line[20];
clrscr();
ofstream fout("student");
cout<<"\n the student mark list by using file\n";
for(int i=0;i<=1;i++)
{
cout<<"\nroll number:";
cin>>rollno;
cout<<"\n name:";
cin>>name;
cout<<"\n mark1:";
cin>>m1;
cout<<"\n mark2:";
cin>>m2;
cout<<"\n mark3:";
cin>>m3;
tot=m1+m2+m3;
fout<<rollno<<"\t"<<name<<"\t"<<m1<<"\t"<<m2<<"\t"<<m3<<"\t"<<tot<<"\n";
}
fout.close();
ifstream fin("student");
cout<<"\n the student mark list from file\n";
cout<<"\n.................................................";
cout<<"\n rollno name mark1 mark2 mark3 total";
cout<<"\n.................................."<<endl;
while(fin)
{
fin.getline(line,120);
cout<<line<<"\n";
}
fin.close();
getch();
}
INPUT

The student mark list by using file

roll number:102

name:Karthi

mark1:99

mark2:89

mark3:98

roll number:107

name:Senthil

mark1:98

mark2:90

mark3:99

OUTPUT

the student mark list from file

.................................................
rollno name mark1 mark2 mark3 total
..................................
102 Karthi 99 89 98 286
107 Senthil 98 90 99 287

You might also like