473,324 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

the counter

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

Oct 7 '07 #1
1 1211

"CuTe_Engineer" wrote:

Note that // comments are a disaster on Usenet posts. They cause many
errors on compile.
As I understand it, the program doesn't work AND you want to change it, too.
I suggest doing one thing at a time, get it working first.
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
Comment is wrong. You are *opening* a file. Print an error message if the
file doesn't open.
>
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();
}
You are overwriting the data in the array. Shouldn't you also clear the
data collected during the first filling? (The two static variables.) You
went to the effort of writing a destructor and then you don't call it. Does
this make sense?
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 ??
Not sure I understand. How about reading and discarding the first 7
records? Does that make any sense to you? I doubt if you want a new
function.
>
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

Oct 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Shane | last post by:
:) I am following a tutorial for php (hudzilla.org) absolutely loving it however I am having trouble with the counter example <?php // your content here... $filename = 'counter.txt'; // our...
16
by: Paul Rubin | last post by:
I'd like to have a function (or other callable object) that returns 0, 1, 2, etc. on repeated calls. That is: print f() # prints 0 print f() # prints 1 print f() # prints 2 # etc. ...
7
by: JellyON | last post by:
Hi. Is there a way to delay a call to a page counter (ie. call to a server script from an IMG tag) for the purpose to not lock the page loading awaiting counter be displayed. Maybe a...
0
by: Earl Anderson | last post by:
KB Article Q140908 provided the following function to create an Auto Incrementing Counter: Function Next_Custom_Counter () On Error GoTo Next_Custom_Counter_Err Dim MyDB As Database Dim...
7
by: mistral | last post by:
I use htaccess to protect directory and granting access to download file only for the authorized users. Just want implement simple PHP file download counter for single file. I need track the number...
0
by: Trevor L. | last post by:
I decide to put a custom Hit Counter on my page (below). Then I won't be reliant on the standard FrontPage one which uses webbots. It is called by <b>Hit Counter: </b><!--#include...
12
by: devospice | last post by:
Hi, I'm trying to create a download counter for individual files on a web site and I'm not sure how to do this. Right now I'm using Webalizer to just read the log files and see how many times...
5
by: jasonchan | last post by:
How would you set up a counter in javascript that goes from 5 to 0 This is what i have so far and it is not displaying in the div container "counter" for some reason... <!DOCTYPE html PUBLIC...
3
blackstormdragon
by: blackstormdragon | last post by:
Here were our instructions: "My mother always took a little red counter to the grocery store. The counter was used to keep tally of the amount of money she would have spent so far on that visit to...
2
by: gumbercules | last post by:
I am designing a site that is regulary updated with new podcasts. I would like to be able to have a counter next to each podcast showing how many hits/listens/plays/views each particular podcast has...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.