/* Program using Structure and output to file*/
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
void main()
{
FILE *fileOut;
struct income {
float nSalary; //Salary Received
float nRentRec; //Rent Received from home at native place
float nOtherIn; //Any other income
};
struct expenses {
float nRentPaid; //Rent
float nPUB; //Public Utility Bill (water, electricity)
float nTele; //Telephone, mobile bills
float nEdKid; //Education for kids
float nEdSelf; //Education for self
float nMed; //Medical expenses
float nInsur; //Insurance premium payable
};
struct income MyIncome;
struct expenses MyExpenses;
float nInTotal, nExTotal, nBalance;
int i;
char cOption;
fileOut = fopen("C:\\ex03.txt","w+");
clrscr();
cOption='Y';
do
{
cout<<"Monthly Expenses Vs Income\n";
cout<<"--------------------------\n";
cout<<"INCOME\n";
cout<<"======\n";
cout<<"Salary :";cin>>MyIncome.nSalary;
cout<<"Rent Received :";cin>>MyIncome.nRentRec;
cout<<"Other Income :";cin>>MyIncome.nOtherIn;
cout<<"EXPENSES\n\n";
cout<<"========\n";
cout<<"Rent Paid :";cin>>MyExpenses.nRentPaid;
cout<<"Public Utility :";cin>>MyExpenses.nPUB;
cout<<"Telephone :";cin>>MyExpenses.nTele;
cout<<"Education-Kids :";cin>>MyExpenses.nEdKid;
cout<<"Education-Self :";cin>>MyExpenses.nEdSelf;
cout<<"Medical :";cin>>MyExpenses.nMed;
cout<<"Insurance :";cin>>MyExpenses.nInsur;
nInTotal = MyIncome.nSalary + MyIncome.nRentRec + MyIncome.nOtherIn;
nExTotal = MyExpenses.nRentPaid + MyExpenses.nPUB
+ MyExpenses.nTele + MyExpenses.nEdKid
+ MyExpenses.nEdSelf + MyExpenses.nMed
+ MyExpenses.nInsur;
nBalance = nInTotal - nExTotal;
cout<<"\nTotal Income : "<<nInTotal;
cout<<"\nTotal Expenses : "<<nExTotal;
if (nBalance<0)
cout<<"\nDeficit : ";
else
cout<<"\nSurplus : ";
cout<<nBalance;
fprintf(fileOut,
"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f",
MyIncome.nSalary, MyIncome.nRentRec, MyIncome.nOtherIn,
MyExpenses.nRentPaid, MyExpenses.nPUB, MyExpenses.nTele,
MyExpenses.nEdKid, MyExpenses.nEdSelf, MyExpenses.nMed,
MyExpenses.nInsur);
cout<<"\n\nContinue <Y/N> ? ";cin>>cOption;
} while(cOption=='Y' || cOption=='y');
fclose(fileOut);
getch();
}
/* Program using Structure and output to file*/
/* Write multiple records */
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
void main()
{
FILE *fileOut;
struct income {
float nSalary; //Salary Received
float nRentRec; //Rent Received from home at native place
float nOtherIn; //Any other income
};
struct expenses {
float nRentPaid; //Rent
float nPUB; //Public Utility Bill (water, electricity)
float nTele; //Telephone, mobile bills
float nEdKid; //Education for kids
float nEdSelf; //Education for self
float nMed; //Medical expenses
float nInsur; //Insurance premium payable
};
struct income MyIncome;
struct expenses MyExpenses;
float nInTotal, nExTotal, nBalance;
int i;
char cOption;
fileOut = fopen("C:\\ex03.txt","w+");
clrscr();
cOption='Y';
do
{
cout<<"Monthly Expenses Vs Income\n";
cout<<"--------------------------\n";
cout<<"INCOME\n";
cout<<"======\n";
cout<<"Salary :";cin>>MyIncome.nSalary;
cout<<"Rent Received :";cin>>MyIncome.nRentRec;
cout<<"Other Income :";cin>>MyIncome.nOtherIn;
cout<<"EXPENSES\n\n";
cout<<"========\n";
cout<<"Rent Paid :";cin>>MyExpenses.nRentPaid;
cout<<"Public Utility :";cin>>MyExpenses.nPUB;
cout<<"Telephone :";cin>>MyExpenses.nTele;
cout<<"Education-Kids :";cin>>MyExpenses.nEdKid;
cout<<"Education-Self :";cin>>MyExpenses.nEdSelf;
cout<<"Medical :";cin>>MyExpenses.nMed;
cout<<"Insurance :";cin>>MyExpenses.nInsur;
nInTotal = MyIncome.nSalary + MyIncome.nRentRec + MyIncome.nOtherIn;
nExTotal = MyExpenses.nRentPaid + MyExpenses.nPUB
+ MyExpenses.nTele + MyExpenses.nEdKid
+ MyExpenses.nEdSelf + MyExpenses.nMed
+ MyExpenses.nInsur;
nBalance = nInTotal - nExTotal;
cout<<"\nTotal Income : "<<nInTotal;
cout<<"\nTotal Expenses : "<<nExTotal;
if (nBalance<0)
cout<<"\nDeficit : ";
else
cout<<"\nSurplus : ";
cout<<nBalance;
fprintf(fileOut,
"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f",
MyIncome.nSalary, MyIncome.nRentRec, MyIncome.nOtherIn,
MyExpenses.nRentPaid, MyExpenses.nPUB, MyExpenses.nTele,
MyExpenses.nEdKid, MyExpenses.nEdSelf, MyExpenses.nMed,
MyExpenses.nInsur);
cout<<"\n\nContinue <Y/N> ? ";cin>>cOption;
} while(cOption=='Y' || cOption=='y');
fclose(fileOut);
getch();
}
No comments:
Post a Comment