Home » Coding » c++ » the counter
the counter [message #17397] Sun, 07 October 2007 12:00
CuTe_Engineer  is currently offline CuTe_Engineer
Messages: 5
Registered: September 2007
Junior Member
hii,

i wrote this prog

//header file


#include <string>

using namespace std;

class expenditure
{
public: //public member function
void set(string, int,int,int);
void get(string&, int&,int&,int&) const;
static int getCount();
static int gettotalexpenditure( );
void print() const;
expenditure (string = "Al-Mullah", int= 800, int = 2400, int= 1200);
~ expenditure ();
static double averageExpenditure();

private: // private member function
string name;
int utilities ;
int food;
int personal;
int subtotal;
static int count;
static int totalexpenditure ;
};

// ExpenditureImp.cpp



#include<iostream>
#include<string>
#include"Ex.h"

using namespace std;

int expenditure :: count=0;
int expenditure ::totalexpenditure=0;

void expenditure::set(string N , int u , int f, int p) // set
function
{

totalexpenditure -=subtotal;

name=N;
utilities = u;
food=f;
personal=p;

subtotal=food+personal+utilities;

totalexpenditure += subtotal;
}
void expenditure::get(string& N , int& u , int& f , int& p)const //
get function
{
N=name;
f=food;
p=personal;
u=utilities;
}
expenditure::expenditure(string N, int u, int f , int p) //
constructor
{

subtotal=0;
set(N,u,f,p);

count++;

}

int expenditure::getCount() // get count
{

return count;

}


int expenditure::gettotalexpenditure( ) //return totalexpenditure
{
return totalexpenditure;
}

expenditure::~expenditure() //distructor
{
count--;
totalexpenditure -= subtotal;
cout << "Number of families is: " << count << " and total Expenditure
is: " << totalexpenditure <<endl;
}

void expenditure::print() const // print
{

cout << name << " Expenditure is: " << subtotal << endl;
}
double expenditure::averageExpenditure( )
{
return totalexpenditure/count;

}

#include <iostream>
#include <fstream>
#include <string>
#include "Ex.h"

using namespace std;
const int arraySize = 10;
int main()
{
string N;
int p ,f ,u;
int i;
int numberoffamilies=0;
ifstream inFile("expenditure.txt", ios::in); // reading from file



expenditure A[arraySize]; // array
for(i=0; i<arraySize; i++)
{
A[i].print();
}

cout << "Number of families is: " << expenditure::getCount() << " and
total Expenditure is: " << expenditure::gettotalexpenditure( ) <<
endl;


while(inFile >>N >> u >> f >>p)
A[numberoffamilies++].set(N,u,f,p); // number of families
for(i=0; i<numberoffamilies; i++)
{
A[i].print();
}
cout << "Number of families is: " << expenditure::getCount() << "
and total Expenditure is: " << expenditure::gettotalexpenditure( ) <<
endl;
cout<<" Average families expenditure is:
"<<expenditure::averageExpenditure()<<endl;
return 0;

}

my Question is that when i want to start counting families from the
number 7 instead of 10 what should i do ?do i need to use a new
function or what ??

this is the output i want get

Al-Mullah expenditure is: 4400
Al-Mullah expenditure is: 4400
Al-Mullah expenditure is: 4400
Al-Mullah expenditure is: 4400
Al-Mullah expenditure is: 4400
Al-Mullah expenditure is: 4400
Al-Mullah expenditure is: 4400
Al-Mullah expenditure is: 4400
Al-Mullah expenditure is: 4400
Al-Mullah expenditure is: 4400
Number of families is: 10 and total expenditure is: 44000
Al-Mullah expenditure is: 5100
Al-Issa expenditure is: 5300
Al-Roome expenditure is: 5457
Al-Shebani expenditure is: 4150
Al-Kurdi expenditure is: 4880
Al-Ali expenditure is: 4720
Al-Walled expenditure is: 3940
Number of families is: 7 and total expenditure is: 33547<<<< here is
my mistake instead of 7 i
Average families expenditure is:
4792.4 am getting 10

Total number of families is: 6 and total expanditure is: 29147
Total number of families is: 5 and total expanditure is: 24747
Total number of families is: 4 and total expanditure is: 20347
Total number of families is: 3 and total expanditure is: 16407
Total number of families is: 2 and total expanditure is: 11687
Total number of families is: 1 and total expanditure is: 6807
Total number of families is: 0 and total expanditure is: 2657
Total number of families is: -1 and total expanditure is: -2800
Total number of families is: -2 and total expanditure is: -8100
Total number of families is: -3 and total expanditure is: -13200
Previous Topic:looped include
Next Topic:Initializing inherited protected Members of superclass
Goto Forum:
  


Current Time: Fri May 16 02:42:57 EDT 2008

Total time taken to generate the page: 0.52300 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software