Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 2 Weeks Ago   #1 (permalink)
Intel Overclocker
 
intel ati

Join Date: Oct 2004
Posts: 5,626

Rep: 238 Mikey122687 is acknowledged by manyMikey122687 is acknowledged by manyMikey122687 is acknowledged by many
Unique Rep: 176
FAQs Submitted: 2
Hardware Reviews: 5
Trader Rating: 48
Default C++: Class Time

PHP Code:
#include <iostream>
#include <ctime>
using namespace std;



class 
Time
{
public:
    
int hour;
    
int minute;
    
int second;
    
int time;

    
Time()
    {
        
time time(0);
    }

    
Time(int newTime)
    {
        
time newTime;
    }

};

int main()
{
  
Time time;
  
cout << time.getHour() << ":" << time.getMinute() << ":" << time.getSecond() << endl;

  
Time time1(555550);
  
cout << time1.getHour() << ":" << time1.getMinute() << ":" << time1.getSecond() << endl;

  return 
0;
}


int time()
{
  
int totalSeconds time(0);

  
int currentSecond totalSeconds 60;

  
int totalMinutes totalSeconds 60;

  
int currentMinute totalMinutes 60;

  
int totalHours totalMinutes 60;

  
int currentHour totalHours 24;

  return 
currentHourcurrentMinutecurrentSecond;

Ok so i have that so far.

The purpose of this code is to display the current time, and display the time if the seconds were 555550. The result should be something like:

Current Time is hh/mm/ss

Current Time for 555550 seconds is 10 hours, 19 minutes, 9 seconds.

I don't know where to go from here.

As with my other threads, any help deserves REP++
__________________


System: Main Rig
CPU
Intel C2Q 6600
Motherboard
DFI LP UT P35-T2R
Memory
GSkill F2-6400CL5D-4GBPQ
Graphics Card
Diamond 4870 1GB
Hard Drive
WD Raptor 74GB RAID0
Sound Card
Creative XFi Fatal1ty FPS
Power Supply
Silverstone Zeus 850W
Case
Lian Li V2000B
CPU cooling
TRUE 120
OS
Windows Vista Ultimate x64
Monitor
SAMSUNG 2253BW Black 22" LCD
Mikey122687 is offline   Reply With Quote
Old 2 Weeks Ago   #2 (permalink)
Intel Overclocker
 
intel ati

Join Date: Oct 2004
Posts: 5,626

Rep: 238 Mikey122687 is acknowledged by manyMikey122687 is acknowledged by manyMikey122687 is acknowledged by many
Unique Rep: 176
FAQs Submitted: 2
Hardware Reviews: 5
Trader Rating: 48
Default

K so i revised it and here is what i have now

PHP Code:
#include <iostream>
#include <ctime>
using namespace std;



class 
Time
{
public:
    
int hour;
    
int minute;
    
int second;
    
int time;

    
Time()
    {
        
time time(0);
    }

    
Time(int newTime)
    {
        
time newTime;
    }

    
int getHour()
    {
        
int totalSeconds time(0);
        
int currentSecond totalSeconds 60;
        
int totalMinutes totalSeconds 60;
        
int currentMinute totalMinutes 60;
        
int totalHours totalMinutes 60;
        return 
totalHours;
    }

    
int getMinute()
    {
         
int totalSeconds time(0);
         
int currentSecond totalSeconds 60;
         
int totalMinutes totalSeconds 60;
         
int currentMinute totalMinutes 60;
         return 
currentMinute;
    }

     
int getSecond()
    {
        
int totalSeconds time(0);
        
int currentSecond totalSeconds 60;
        return 
currentSecond;
    }

};

int main()
{
  
Time time;
  
cout << time.getHour() << ":" << time.getMinute() << ":" << time.getSecond() << endl;

  
Time time1(555550);
  
cout << time1.getHour() << ":" << time1.getMinute() << ":" << time1.getSecond() << endl;

  return 
0;

__________________


System: Main Rig
CPU
Intel C2Q 6600
Motherboard
DFI LP UT P35-T2R
Memory
GSkill F2-6400CL5D-4GBPQ
Graphics Card
Diamond 4870 1GB
Hard Drive
WD Raptor 74GB RAID0
Sound Card
Creative XFi Fatal1ty FPS
Power Supply
Silverstone Zeus 850W
Case
Lian Li V2000B
CPU cooling
TRUE 120
OS
Windows Vista Ultimate x64
Monitor
SAMSUNG 2253BW Black 22" LCD
Mikey122687 is offline   Reply With Quote
Old 2 Weeks Ago   #3 (permalink)
Intel Overclocker
 
intel ati

Join Date: Oct 2004
Posts: 5,626

Rep: 238 Mikey122687 is acknowledged by manyMikey122687 is acknowledged by manyMikey122687 is acknowledged by many
Unique Rep: 176
FAQs Submitted: 2
Hardware Reviews: 5
Trader Rating: 48
Default

Any suggestion as to what i should do next?
__________________


System: Main Rig
CPU
Intel C2Q 6600
Motherboard
DFI LP UT P35-T2R
Memory
GSkill F2-6400CL5D-4GBPQ
Graphics Card
Diamond 4870 1GB
Hard Drive
WD Raptor 74GB RAID0
Sound Card
Creative XFi Fatal1ty FPS
Power Supply
Silverstone Zeus 850W
Case
Lian Li V2000B
CPU cooling
TRUE 120
OS
Windows Vista Ultimate x64
Monitor
SAMSUNG 2253BW Black 22" LCD
Mikey122687 is offline   Reply With Quote
Old 2 Weeks Ago   #4 (permalink)
Programmer
 
Korben's Avatar
 
intel nvidia

Join Date: Oct 2008
Location: Florida
Posts: 2,410

Rep: 86 Korben is acknowledged by some
Unique Rep: 77
Trader Rating: 13
Default

Seems to work fine. I had to change the time(0) as time because they can't be used as functions.

Code:
#include <iostream>
#include <ctime>
using namespace std;



class Time
{
public:
    int hour;
    int minute;
    int second;
    int time;

    Time()
    {
        time = time;
    }

    Time(int newTime)
    {
        time = newTime;
    }

    int getHour()
    {
        int totalSeconds = time;
        int currentSecond = totalSeconds % 60;
        int totalMinutes = totalSeconds / 60;
        int currentMinute = totalMinutes % 60;
        int totalHours = totalMinutes / 60;
        return totalHours;
    }

    int getMinute()
    {
         int totalSeconds = time;
         int currentSecond = totalSeconds % 60;
         int totalMinutes = totalSeconds / 60;
         int currentMinute = totalMinutes % 60;
         return currentMinute;
    }

     int getSecond()
    {
        int totalSeconds = time;
        int currentSecond = totalSeconds % 60;
        return currentSecond;
    }

};

int main()
{
  Time time;
  cout << time.getHour() << ":" << time.getMinute() << ":" << time.getSecond() << endl;

  Time time1(555550);
  cout << time1.getHour() << ":" << time1.getMinute() << ":" << time1.getSecond() << endl;
  
  cin.get();
  return 0;
}
__________________
Currently Playing: Aion
Steam - KForKorben X-Fire - kforkorben
I did Latty's Linux Challenge and I now have tried Linux!
I am 54% addicted to Counterstrike. What about you?
4Ghz

System: Core i7 Build
CPU
i7 920 | 3.8Ghz
Motherboard
Asus | P6T Deluxe
Memory
Corsair | 6GB | 1600Mhz
Graphics Card
2x | EVGA | GTX 260 | SLI
Hard Drive
2x | VR 300GB + 1TB | Raid 0
Sound Card
Asus | Xonar DX
Power Supply
Corsair | 1000HX
Case
Antec 1200 | Window Mod
CPU cooling
TRUE 1366 | 2x Ultra Kaze
GPU cooling
Stock
OS
Windows 7 Ultimate| x64
Monitor
Samsung | T260
Korben is offline   Reply With Quote
Old 2 Weeks Ago   #5 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 236

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

Quote:
Originally Posted by Korben View Post
Seems to work fine. I had to change the time(0) as time because they can't be used as functions.
That change negates the whole purpose of the class.


As written, the class's time data member clashes with the time() function. A better "fix" would be to rename the time data member to totalSeconds.

Don't re-fetch the the current time() in your class's member functions i.e. int a t1.getHour(); int b t1.getHour(); a should equal b.

Check your algorithms with simpler test code i.e. Time t(61); int h = t.getHour(); int m = t.getMinutes();, etc.
__________________
Rich
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 01:43 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.09981 seconds with 8 queries