Thread: Newbie question

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    20

    Question Newbie question

    I have to write a class called time, which has a set member function that takes no arguments which prompts the user to enter the time and assigns them to hour, minute and second. My question is if the function takes no arguments how would you assign the user's input to those values? Here's the code how i understand it, please let me know if i have approached this in the right way.

    #include <iostream>
    #include <iomanip>

    using namespace std;

    class Time
    {
    private:
    int hour;
    int minute;
    int second;
    char ch;

    public:
    bool setTime()
    {
    cout << endl << "Enter a time of the appointment (HH:MM:SS
    ===> ";
    cin >> hour >> ch >> minute >> ch >> second;

    if (!cin.good() )
    {
    cout << "Invalid time!";
    cout << endl;
    cin.clear();
    cin.ignore(1024, '\n');
    }
    else
    {
    return true;
    }
    }
    void Print()
    {
    cout << (hour < 10 ? "0" : "") << hour << ":";
    cout << (minute < 10 ? "0" : "") << minute << ":";
    cout << (second < 10 ? "0" : "") << second << endl;
    };

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > My question is if the function takes no arguments how would you assign the user's input to those values?

    The same way you did. You just ask for the input in the function itself - that way the function doesn't need arguments passed to it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 06:45 PM
  3. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 04:38 PM
  4. confusion with integers (newbie question)
    By imortal in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 04:09 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM