473,508 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Absolute C++ counter problem

6 New Member
There is a programming project that I just don't know how to implement. Here is what it is asking:

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 the store if she bought everything in the basket. The counter had a four digit display, increment buttons for each digit, and a reset button. An overflow indicator came up red if more money was entered than the $99.99 it would register.

How would I implement this idea into C++ code? just some hints, I can't figure this one out, any hint would be greatly appreciated. If anyone has the book and can help me, I would be very thankful

Thanks in advance.
Feb 21 '07 #1
10 4689
sicarie
4,677 Recognized Expert Moderator Specialist
There is a programming project that I just don't know how to implement. Here is what it is asking:

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 the store if she bought everything in the basket. The counter had a four digit display, increment buttons for each digit, and a reset button. An overflow indicator came up red if more money was entered than the $99.99 it would register.

How would I implement this idea into C++ code? just some hints, I can't figure this one out, any hint would be greatly appreciated. If anyone has the book and can help me, I would be very thankful

Thanks in advance.
So it seems you need a number for the total, an indicator if you have overflowed or not, and a test to see if you have overflowed.

If you put those things into a loop that exited on a sentinel (possibly overflow, possibly a character), you'd have it.

Is there something specific you are having trouble with?
Feb 21 '07 #2
captainMarkis
6 New Member
The problem is that I need to make this using a class Counter (sorry I omitted that) and using at least two constructors. I am a beginner in this, but I am really interested in knowing classes, I just don't know how to implement this problem into a program.
Feb 22 '07 #3
sicarie
4,677 Recognized Expert Moderator Specialist
The problem is that I need to make this using a class Counter (sorry I omitted that) and using at least two constructors. I am a beginner in this, but I am really interested in knowing classes, I just don't know how to implement this problem into a program.
Oh, well that's pretty easy to do as well - those attributes are just going to go into the class (just not the loop).

Are you having difficulty with the concept of a class, or is the "two constructors" thing throwing you (or even something else)?
Feb 22 '07 #4
captainMarkis
6 New Member
I wanted to use a shorter idea on this, but it seems I left it out a whole bunch of vital info in order for you to help me. Here is the rest of the problem:

Write and implement the member functions of a class Counter that simulates and slightly generalizes the behavior of this grocery store counter. The constructor should create a Counter object that can count up to the constructor's argument. That is Counter(9999) should provide a counter that can count up to 9999. A newly constructed counter displays a reading of 0. The member function void reset(); sets the counter's number to 0. The member function void incr1(); increments the units digits by 1, void incr10(); increments the tens digit by 1, and void100(); and void1000(); increments the next two digits respectively. Accounting for any carrying when you increment should require no further action than adding an appropriate number to the private data member. A member function bool overFlow(); detects overflow.

Thank you for your help.
Feb 22 '07 #5
captainMarkis
6 New Member
Oh, well that's pretty easy to do as well - those attributes are just going to go into the class (just not the loop).

Are you having difficulty with the concept of a class, or is the "two constructors" thing throwing you (or even something else)?
Yep that is the problem, I have started with C++ about 2 months ago, I am a graphics designer, but live in a city where finding a job in that field is like finding a needle in a haystack. I understand the idea of class, just don't know the implementation, the theory, the logic of it that stumbles me, same goes for the constructors, I understand what they do, just having trouble understanding their logic.

Thank you for your input and help.
Feb 22 '07 #6
sicarie
4,677 Recognized Expert Moderator Specialist
Yep that is the problem, I have started with C++ about 2 months ago, I am a graphics designer, but live in a city where finding a job in that field is like finding a needle in a haystack. I understand the idea of class, just don't know the implementation, the theory, the logic of it that stumbles me, same goes for the constructors, I understand what they do, just having trouble understanding their logic.

Thank you for your input and help.
I really like this site - it's got good material and shows little examples, but this is a good readup on classes, with a bit of code to help.
Feb 22 '07 #7
captainMarkis
6 New Member
So I tried and basically it is lack of knowledge on my part, but how can I start eh class? This is really alien to me and an example of how this one would look would be greatly appreciated. Thanks in advance, but I feel like this is really important and I have no one to help in this field, I am learning this myself.
Feb 27 '07 #8
captainMarkis
6 New Member
Oh and also, this is how much I have actually done, but it doesn't work. Maybe something I am doing wrong.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream> 
  2. using namespace std;
  3.  
  4. class Counter {
  5. public:
  6.     Counter(int cents, int dimes, int dollars, int tensDollars);
  7.  
  8.     void reset();
  9.     void incr1(),
  10.          incr10(),
  11.          incr100(),
  12.          incr1000();
  13.     bool overflow();
  14.  
  15. };
  16.  
  17. int main() {
  18.     Counter(9, 9, 9, 9);
  19.     cout << "Please enter the amount of cents, dimes, dollars and tens of dollars \n";
  20.     cout << "by using keys a (for cents), s (for dimes), d (for dollars), f (for tens dollars) \n";
  21.     cout << "and o (for overflow) followed by numbers 1-9 to specify the amount of cents, dimes etc. \n";
  22.     cout << "Please enter amount of cents:\n";
  23.     cin >> money.incr1;
  24.     cout << "Please enter amount of dimes:\n";
  25.     cin >> money.incr10;
  26.     cout << "Please enter amount of dollars:\n";
  27.     cin >> money.incr100;
  28.     cout << "Please enter amount of tens pf dollars:\n";
  29.     cin >> money.incr1000;
  30.  
  31.     return 0;
  32. }
Feb 27 '07 #9
Ganon11
3,652 Recognized Expert Specialist
How is it not working? Are there errors during compilation? Is it compiling but giving unexpected results?
Feb 27 '07 #10
sicarie
4,677 Recognized Expert Moderator Specialist
How is it not working? Are there errors during compilation? Is it compiling but giving unexpected results?
I'm going to guess errors - he declares "Counter" instead of "money" in his main, the functions he uses money.increment are not called using parentheses, and there are no definitions of what those methods do in his class.

captainMarkis - you've got a good start - the right structure and ideas, there are just the finer points that are missing. This is a good tutorial/reference for classes - declaring and implementing. I like it because it usually comes with examples that are clear and concise and illustrate the code.

Other than that, and declaring your variables not only in the constructor, but also the class, you need to define what those increment methods do in your class. It's clear to the reader, but the compiler only sees that as an identifier - you can name them vodka(), tonic(), and martini() for all the compiler cares...

Check out that tutorial and let us know if it gives you any more trouble.
Feb 27 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
553
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...
2
1985
by: Mike Brearley | last post by:
I have a counter (alright one I found on asp101.com) that checks for a session variable to prevent the counter from incrmenting if a user refreshes the page or returns to the page during the same...
6
2808
by: Vincent Lefevre | last post by:
I would like to know if the base URI considered to resolve an unparsed entity defined by a relative URI should be the URI before or after its rewriting due to a possible catalog. Let's take an...
3
1851
by: JeffDotNet | last post by:
I wrote a small data processing application that writes a summary of several hundred files. I use drag and drop on a panel (Panel1) to grab the absolute path to each of these files. Then I begin...
3
2217
by: horusprim | last post by:
Is there a CSS absolute positioning rendering bug in FF1.02 and IE 6? I have been experimenting with precision absolute positioning in CSS. The following test content was used in the...
2
16395
by: nino9stars | last post by:
Hello, I have just started messing with absolute positioning on webpages, and it definitely let's you do some creative things. Well, after much searching and help, I got the images I was using...
12
2882
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...
9
2232
by: Pygmalion | last post by:
I have found dozen of useful PHP counters on the web. However, nobody is working for my web pages, since administrator does not want to enable the possibility that PHP could be called from HTML. ...
2
2842
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
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.