Results 1 to 2 of 2

c++ problems

This is a discussion on c++ problems within the C++ forums, part of the Courses category; 1. Create a class called time that has separate int member data for hours minutes, and seconds. One constructor should ...

  1. #1
    iTT Student jhrathore's Avatar
    Join Date
    Jul 2010
    Location
    Hyderabad
    Age
    28
    Posts
    6

    c++ problems

    1. Create a class called time that has separate int member data for hours minutes, and seconds. One constructor should initilize this data to 0, and another should initilize it to fixed values. Another member function should display it in, 11:59:59 format. The final member function should add two objects of type time passed arguments.
    A main() program should create two initialized time objects (should they be const?) and one that isn't initialized. then it should add the two initialzed value together, leaving the result in the third time variable Finally it should display the value of this third variable. Make appropriate member funciton const.

  2. #2
    iTT Student
    Join Date
    May 2010
    Location
    Pakistan
    Age
    28
    Posts
    1

    Thumb up Re: c++ problems

    // i have just read the post!
    // if any error found plz email me at me.shikari(AT)yahoo.com
    // i will try my best to solve in simple way... :wiggle: yes really :atyourservice:

    #include <iostream.h>
    #include <conio.h>
    #include <iomanip.h>
    class Time
    {
    // private data members
    private:
    int hour;
    int minute;
    int second;
    public:
    Time(); // constructor
    void setTime(int, int, int);
    void printUniversal();
    void printStandard();
    };

    // definitions of the class member functions
    Time::Time()
    {
    hour = minute = second = 0;
    }
    void Time::setTime(int h, int m, int s)
    {
    hour = (h >= 0 && h < 24) ? h : 0;
    minute = (m >= 0 && m < 60) ? m : 0;
    second = (s >= 0 && s < 60) ? s : 0;
    }
    void Time::printUniversal()
    {
    cout<<setfill('0')<<setw(2)<<hour<<":"<<setw(2)<<m inute<<":"<<setw(2)<<second<<endl;
    }
    void Time::printStandard()
    {
    cout<<setw(2)<<((hour == 0 || hour == 12) ? 12 : hour % 12)
    <<":" <<setw(2)<<minute<<":"<<setw(2)<<second<<((hour < 12) ? " AM":" PM")<<endl;
    }
    void main()
    {
    clrscr();
    Time s;
    s.setTime(15,10,0);
    cout<<"\nThe initial Universal Time is ";
    s.printUniversal();
    cout<<"The initial Standard Time is ";
    s.printStandard();
    s.setTime(13,27,6);
    cout<<"\n\nUniversal Time after setTime ";
    s.printUniversal();
    cout<<"Standard Time after setTime ";
    s.printStandard();
    s.setTime(99,99,99);
    cout<<"\n\nAfter attempting wrong values:"<<endl;
    cout<<"Universal Time is ";
    s.printUniversal();
    cout<<"Standard Time is ";
    s.printStandard();
    getch();
    }

Similar Threads

  1. Problems se bahir Aoo? Come out of Problems?
    By Ishaq in forum Quran e Kareem
    Replies: 3
    Last Post: 24th October 2009, 02:09 AM
  2. .....PROBLEMS.....
    By sahrish in forum Baat Cheet
    Replies: 29
    Last Post: 2nd December 2008, 03:48 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •