Technical Discussion
  >> Web Design / HTML / Web hosting Forum


Register (or login) on our website and you will not see this ad.


These posts have been archived and can no longer be replied to or modified.
Pages in this thread: 1 | 2 | 3 | 4 | (show all)   Print Thread
Standard User deleted
(deleted) Wed 09-Dec-09 14:18:09
Print Post

C++ coding


[link to this post]
 
Hi folks,

My university course has progressed onto C++ programming now, and im learning how to use various variables and functions within the program using Dev CPP compiler. If there is any coders out there, I would appreciate your help on this nagging issue.

Basically the first part of the program I have to calculate call charges for customers, charged at national rate at £1.50 a minute for the first 3 minutes, and 30p thereafter. However at certain days and times, theres discounts applied. For example between 8am and 4:59pm on weekends theres a 60% discount. I have been searching all over the net for C++ maths algorithms but couldn't find anything relevant.

Thanks for any help.
Standard User wrtpeeps
(eat-sleep-adslguide) Wed 09-Dec-09 14:23:52
Print Post

Re: C++ coding


[re: deleted] [link to this post]
 
Write your own. I guess that's what you're meant to do?

Signature.
Standard User deleted
(deleted) Wed 09-Dec-09 14:26:11
Print Post

Re: C++ coding


[re: deleted] [link to this post]
 
I'm not a C++ dev, but percentage calculations are the same no matter what language you are using..

Here's a PDF with the relevant formulas..


Register (or login) on our website and you will not see this ad.

Standard User deleted
(deleted) Wed 09-Dec-09 14:32:37
Print Post

Re: C++ coding


[re: deleted] [link to this post]
 
I don't think there's anything specifically C++ about the algorithms needed. Just think about how you would do it by hand, which seems fairly straightforward, and then convert that into code. Ideally, as it's a C++ course, you'll use classes and inheritance for your solution but I'm not sure what point you have reached in your course.

Just forget the programming language to start with and try and think about how you would actually solve the problem in less specific terms.

The details? Well, that's the point of your being set the exercise, isn't it?
Standard User deleted
(deleted) Wed 09-Dec-09 14:34:29
Print Post

Re: C++ coding


[re: deleted] [link to this post]
 
Try several nested IF Statements (or CASE Statements if you prefer).

Don't forget it is good practice to always put the curly brackets inside any IF even if it only has one line of code following it.
Standard User deleted
(deleted) Wed 09-Dec-09 14:37:42
Print Post

Re: C++ coding


[re: deleted] [link to this post]
 
Not good practice in C++! You really should be using polymorphism rather than case statements; that way it's easy to add in new rating bands. But it depends upon how advanced the C++ course currently is.
Standard User deleted
(deleted) Wed 09-Dec-09 14:42:31
Print Post

Re: C++ coding


[re: deleted] [link to this post]
 
Thank you for the assistance folks, I am writing this stuff down to try and make sense of it. I apologise if you thought I was asking someone to do the program for me, I wasn't I just want to get my head round the algorithm I could possibly use for these sort of tasks.

In regards to the progress this is the 9th week of C++ so I would class myself as a beginner currently.
Standard User wrtpeeps
(eat-sleep-adslguide) Wed 09-Dec-09 16:45:02
Print Post

Re: C++ coding


[re: deleted] [link to this post]
 
It's not really a c++ specific function, more just maths stuff.

Signature.
Standard User Kenneth
(legend) Wed 09-Dec-09 19:15:13
Print Post

Re: C++ coding


[re: deleted] [link to this post]
 
This is not really a mathematics problem, it is more of a logic problem.

First I'd start with some questions (or state assumptions since education exercise)
  • do they charge a whole minute, irrespective of whether 1 second or 60 seconds of minute used or do they pro-rata rate?
  • Does the discount kick in if the call starts before discount period but then goes into discount period? or do they not allow discount if some of call outside discount period


I think it might help you to make problem this visual - e.g. create a spreadsheet with columns
  • Time
  • Call minute
  • Minute Cost
  • Discount Rate
  • Actual Cost


Then build up a call�s cost minute by minute and calculate the costs -
e.g.

7:50

Text
1
23
4
07:57 _ 1 _ �1:50 _ 60% _ *
07:58 _ 2 _ �1:50 _ 60% _ *07:59 _ 3 _ �1:50 _ 60% _ *
08:00 _ 4 _ �0:30 _ 00% _ *


* I leave those value to you

This will allow you to build up some test cases, so you can check your process works correctly. You need to be especially careful of are when you hit boundaries - the change of rates and change of day being the main ones (and it is possible one call may span more than one), so build up some cases covering those

Hopefully these will give you pointers on how to tackle the problem

Ken

When arguing with a fool, pause and ponder - are they also arguing with a fool
Standard User deleted
(deleted) Wed 09-Dec-09 22:30:17
Print Post

Re: C++ coding


[re: deleted] [link to this post]
 
In reply to a post by lt567:
In regards to the progress this is the 9th week of C++ so I would class myself as a beginner currently.
they are teaching you c++ as a first language? that sucks. good luck.
Pages in this thread: 1 | 2 | 3 | 4 | (show all)   Print Thread

Jump to