Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Is there ANYBODY out there who can help me with this (programming) problem?

Options
  • 07-04-2011 11:15pm
    #1
    Closed Accounts Posts: 119 ✭✭


    A person making a phone call enters a number of 10p, 20p, 50p, 100p coins and dials
    the number. When the number is dialled the display on the phone shows the amount
    of time available to the user for the phone call. Write a program that simulates the
    operation of making a phone call.
    An outline solution for the program is:
    {
    int totalCoins;
    String phoneNum;
    totalCoins = getCoins();
    phoneNum = getPhone();
    displayTime(totalCoins, phoneNum);
    }
    getCoins() reads a list of valid coins and computes their total value. (Note: Any
    invalid coins on the list should be ignored.)
    getPhone() returns a phone number. The function should only accept a valid phone
    number from the user.
    displayTime(totalCoins, phoneNum) displays the total time in seconds available
    for the phone call. Calls are charged at the following rates:
    a local call costs 5p for 15 seconds;
    a national call costs 12p for 20 seconds;
    an international call costs 20p for 10 seconds.


    I need to have this question completed very soon. Any help at all would be appreciated.


Comments

  • Banned (with Prison Access) Posts: 1,007 ✭✭✭knird evol


    Does it do the prepaid phone cards. is this an english phone box?


  • Registered Users Posts: 220 ✭✭dueyfinster


    ElasticMan wrote: »
    getCoins()
    Read that in as a list of doubles the user enters (how are you doing user input?) and do if statement to check it (or a case statement). if it matches if or case, add them together. Simples!
    ElasticMan wrote: »
    getPhone()
    A bit more difficult, valid numbers are a lot of formats. If your inexperienced, try it as a char array and then you can do an if to match against number's your checking for (use for loop to scroll it, match char, char[i+1] etc). Again, are you going to specify every area code in Ireland? Easiest to do is check for National number, then else it must be local :D


    ElasticMan wrote: »
    displayTime(totalCoins, phoneNum)
    Get total coinage above from variable added and passed in (say double totalCost). I'd suggest making phoneNum a boolean (true/false) and return true from getPhone() if it's a local number, or false if national. then you can do if loop if(isNational=true){ // NationalCost}else if (isNational=false){ // localCost code }.

    Lastly, practice and chip away at programming problems task by task. It only gets easier with practice (and StackOverflow is a good site for these questions).


  • Registered Users Posts: 15,065 ✭✭✭✭Malice


    ElasticMan wrote:
    I need to have this question completed very soon. Any help at all would be appreciated.
    What have you done so far? Where are you having problems?


  • Registered Users Posts: 21 Enda_of_Eire


    Malice wrote: »
    What have you done so far? Where are you having problems?

    Exactly, show some effort atleast.


  • Registered Users Posts: 5,246 ✭✭✭conor.hogan.2


    Also what language do you want it in?


  • Advertisement
  • Registered Users Posts: 15,065 ✭✭✭✭Malice


    Also what language do you want it in?
    The target language shouldn't matter and I would hope that no one posts up a ready-made solution. The OP won't learn a lot in that case.


  • Registered Users Posts: 1,657 ✭✭✭komodosp


    Where's the input coming from? input file? User input? Do you have to detect the end of coin entry and the beginning of the number dialling.. Judging by the outline you've given I'm guessing no... Does it have to automatically detect the number having been dialled?

    getCoins() should loop through your input of coins adding to the total, obviously ignoring any value other than the ones you've given, and terminated by the end of the file or something. Then it returns the total.

    then getPhone()... well as I said does it have to detect the end of the number like a real phone or can you press the "Send" button? If the latter then
    Loop until valid-phone-entered
    Read input
    if it's a valid number, valid-phone-entered = true
    End loop
    return phone number (the input)

    Otherwise loop character by character and if it's a valid number, return it.

    As for how to check if it's a valid phone number... I'm sure there's something on the 'net about the format of a phone number, or even better a regular expression that you can use (though I'm not sure if you are at that the stage of using regular expressions yet)

    Then displayTime(Money, number)

    {assuming we're in Ireland}

    if number begins with 00
    - totalTime = calculate for international
    else if number begins with 0 but not your own area code
    - totalTime = calculate for national
    else
    - totalTime = calculate for local


  • Closed Accounts Posts: 577 ✭✭✭Galtee


    The most important part of this problem as far as I can see is the ability to calc the time remaining based on the number of coins entered and the type of phone number dialled. And so, an integral part of modelling the solution is the breakdown of the phone number, this can obviously be done in many ways with the simplest being a user choice, Local, National / International and the most comprehensive (without being hooked up to a telephone exchange) being the ability to define a number and location, ie What defines a local number x number of digits etc, what is the current location of my phone and what are the national locations and how are they identified by digits. What is the international dialling prefix will also need to be captured obviously.
    Once all of these are defined the solution pretty much writes itself with the only task left to be able to calculate the time remaing based on the coinTotal where you're ringing, what the associated costs are and how long you've been on and this you should be able to do yourself with a little thought.


Advertisement