cpp_rookie
Grünschnabel
Hallo,
ich soll den folgenden Code der derzeit noch als Datenstruktur deklariert ist, in eine Klasse "umwandeln":
Ich komm aber nicht so wirklich voran.
Derzeit hab ich meine Header datei verfasst:
Stimmt das schonmal ?
Nun komm ich auch schon nicht mehr weiter, müsste ja nun in der cpp datei meine Methoden implementieren oder?
Quasi
?
Funktioniert aber mal gar nicht irgendwie..
Kann mir da jemand auf die Schnelle auf die Sprünge helfen?
Gruß
rookie
ich soll den folgenden Code der derzeit noch als Datenstruktur deklariert ist, in eine Klasse "umwandeln":
#include <iostream>
using namespace std;
struct Time
{
int hour;
int minute;
int second;
};
void print24hFormat( Time );
void print12hFormat( Time );
int main()
{
struct Time begin;
begin.hour = 18;
begin.minute = 05;
begin.second = 00;
cout << "Abendessen ist um ";
print24hFormat( begin );
cout << " im 0-24h Format,\nbzw. ";
print12hFormat( begin );
cout << " im 0-12h Format.\n";
}
void print24hFormat ( Time begin )
{
cout << ( begin.hour < 10 ? "0" : "" ) << begin.hour << ":"
<< ( begin.minute < 10 ? "0" : "" ) << begin.minute << ":"
<< ( begin.second < 10 ? "0" : "" ) << begin.second << endl;
}
void print12hFormat ( Time begin )
{
cout << (( begin.hour==0 || begin.hour==12 ) ? 12 : begin.hour % 12 )
<< ":" << ( begin.minute < 10 ? "0" : "" ) << begin.minute
<< ":" << ( begin.second < 10 ? "0" : "" ) << begin.second
<< ( begin.hour < 12 ? " AM" : " PM" ) << endl;
}
Ich komm aber nicht so wirklich voran.
Derzeit hab ich meine Header datei verfasst:
#pragma once
class time
{
private:
int hour, minute, second;
public:
time(void);
~time(void);
void print24hFormat();
void print12hFormat();
};
Stimmt das schonmal ?
Nun komm ich auch schon nicht mehr weiter, müsste ja nun in der cpp datei meine Methoden implementieren oder?
Quasi
#include "time.h"
#include <iostream>
time:: print24hFormat()
{
code...
}
time:: print12hFormat()
{
code...
}
?
Funktioniert aber mal gar nicht irgendwie..
Kann mir da jemand auf die Schnelle auf die Sprünge helfen?
![Roll eyes :rolleyes: :rolleyes:](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f644.png)
Gruß
rookie