Autor Beitrag
Tolgakan
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mo 20.11.06 16:42 
Tag alle mit einander!Bin neu im Forum,besser gesagt bin ein Anfänger im Programmierbereich Delphi:)In letzter Zeit beschäftige ich mich oft mit Delphi und bin bei einer Aufgabe hängen geblieben.Ich weiß nicht genau , ob die Aufgabenstellung in diese Kategorie des Forums passt,wenn nicht könnt ihr es ja mir ja sagen.Also und zwar folgende Aufgabe:

Schreibe ein Programm,das nach Eingabe eines Datums bestimmt,um den wievielten Tag des Jahres es sich handelt.

Hinweis: Jede Jahreszahl,die durch 4 aber nicht durch 100 teilbar ist,ist ein Schaltjahr.Ausnahme:Alle durch 400teilbaren Jahreszahlen sind ebenfalls Schaltjahre.

So lautet halt die Aufgabe,die ich bewältigen will.

Ich denke mit einem SpinButton zu arbeiten wäre angebracht.

Könnte mir einer sagen , wie eine mögliche Lösung aussehen sollte.Würde mich echt freuen,wenn mir einer oder eine weiterhelfen könnte.

MfG Tolgakan
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mo 20.11.06 16:47 
Ist das Problem der Algorithmus an sich oder das Umsetzen in Delphi-Language?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Tolgakan Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mo 20.11.06 18:57 
das umsetzen in delphilanguage wie es halt in delphisprache geschrieben sein muss.ich kann halt mit der Aufgabe ehrlich gesagt nix anfangen.würde mich auf deine Hilfe freuen.Danke.

MfG
tolgakan
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 20.11.06 19:09 
Moin und :welcome: im Forum!

Naja, das ist ein Einzeiler (und ich rate dir auch davon ab, dass deinem Lehrer zu zeigen :mahn: fällt sofort auf...): ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
uses
  ..., DateUtils;

ShowMessage('Heute ist der '+IntToStr(DayOfTheYear(Now))+'. Tag des Jahres.');

Allerdings glaube ich nicht, dass dein Lehrer das so haben wollte. :zwinker:

Zeig dochmal deinen Code/Ansatz, dann sehen wir weiter. Du musst dir doch schon irgend einen Gedanken gemacht haben, wie du da ran gehen willst, oder? ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.


Zuletzt bearbeitet von Narses am Mi 22.11.06 01:04, insgesamt 2-mal bearbeitet
Tolgakan Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Di 21.11.06 18:55 
Hier ist mein Versuch es selbst zu machen aber irgendwie klappt es nicht.Hoffe,du kannst mir weiterhelfen.

MfG tolgakan


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
unit Unit_datum;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Spin, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    SpinEdit1: TSpinEdit;
    SpinEdit2: TSpinEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    SpinEdit3: TSpinEdit;
    Panel1: TPanel;
    procedure SpinEdit1Change(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.SpinEdit1Change(Sender: TObject);
var tag,monat,jahr,anzahl:integer;
    schalt:boolean;
begin
   //spinfelder auslesen
   tag:=spinedit1.value;
   monat:=spinedit2.value;
   jahr:=spinedit3.value;

case monat of
1:Anzahl:=tag;
2:Anzahl:=tag+31;
3:Anzahl:=tag+59;
4:Anzahl:=tag+90;
5:Anzahl:=tag+120;
6:Anzahl:=tag+151;
7:Anzahl:=tag+181;
8:Anzahl:=tag+212;
9:Anzahl:=tag+243;

10:Anzahl:=tag+273;
11:Anzahl:=tag+304;
12:Anzahl:=tag+334;
end;       // von case

// prüfen auf Schaltjahr
if ((jahr mod 4=0 and (jahr mod 100<>0)) or (jahr mod 400=0)
   then schalt:=true;
   else schalt:=false;

//schaltjahr berücksichtigen

if schalt and(monat>=3)then inc(anzahl);    //anzahl:=anzahl+1;

end.


Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 21.11.06 20:11 
Moin!

Ich würde die Bedingung mal so formulieren:
ausblenden Delphi-Quelltext
1:
2:
3:
// prüfen auf Schaltjahr
schalt := ((jahr mod 4) = 0and ((jahr mod 100) <> 0)
       or ((jahr mod 400) = 0);

Du kannst übrigend einer Bool´schen Variablen direkt einen Ausdruck zuweisen, dafür brauchst du kein if. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Tolgakan Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Di 21.11.06 20:34 
danke aber klappt trotzdem nicht:)....das letzte END in der Unit macht bei mir Probleme.Delphi will das irgendwie nicht schlucken.
Was könnte der Grund sein und ist der Rest meines Programms akzeptabel???danke für deine Aufmerksamkeit

MfG tolgakan
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 21.11.06 22:46 
www.delphibasics.co....sp?Name=DayOfTheYear

Example code : Show the day of the year for a TDateTime variable
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  DateUtils,   // Unit containing the DayOfTheYear command
  SysUtils,
  Forms, Dialogs, Classes, Controls, StdCtrls;
 
type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
  end;
 
var
  Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);
var
  myDate : TDateTime;

begin
  myDate := EncodeDate(19960301);
  Memo1.Lines.Add('01/03/1996 day of year  = '+IntToStr(DayOfTheYear(myDate)));

  myDate := EncodeDate(19980301);
  Memo1.Lines.Add('01/03/1998 day of year  = '+IntToStr(DayOfTheYear(myDate)));

  myDate := EncodeDate(20000301);
  Memo1.Lines.Add('01/03/2000 day of year  = '+IntToStr(DayOfTheYear(myDate)));

  myDate := EncodeDate(20020301);
  Memo1.Lines.Add('01/03/2002 day of year  = '+IntToStr(DayOfTheYear(myDate)));

  myDate := EncodeDate(20040301);
  Memo1.Lines.Add('01/03/2004 day of year  = '+IntToStr(DayOfTheYear(myDate)));

end;
 
end.


Ausgabe:
01/03/1996 day of year = 61
01/03/1998 day of year = 60
01/03/2000 day of year = 61
01/03/2002 day of year = 60
01/03/2004 day of year = 61


Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt


Zuletzt bearbeitet von hathor am Mi 22.11.06 00:25, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 21.11.06 23:16 
Moin!

@user profile iconhathor: Hehe, stimmt, DayOfTheYear() gab´s ja auch noch... ;) Aber nutzt ihm doch nix, das hatten wir ja schon. :D

@user profile iconTolgakan: Du hast ein end vergessen und ein Semikolon zuviel. So sollte es dann gehen:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
procedure TForm1.SpinEdit1Change(Sender: TObject);
  var
    tag,monat,jahr,anzahl: Integer;
    Schalt: Boolean;
begin
  // spinfelder auslesen
  tag := SpinEdit1.Value;
  monat := SpinEdit2.Value;
  jahr := SpinEdit3.Value;
  // Tagebasis berechnen
  case monat of
     1: Anzahl := tag;
     2: Anzahl := tag  +31;
     3: Anzahl := tag  +59;
     4: Anzahl := tag  +90;
     5: Anzahl := tag +120;
     6: Anzahl := tag +151;
     7: Anzahl := tag +181;
     8: Anzahl := tag +212;
     9: Anzahl := tag +243;
    10: Anzahl := tag +273;
    11: Anzahl := tag +304;
    12: Anzahl := tag +334;
  end// von case
  // prüfen auf Schaltjahr
  schalt := ((jahr mod 4) = 0and ((jahr mod 100) <> 0)
         or ((jahr mod 400) = 0);
  // Schaltjahr berücksichtigen
  if (Schalt and (monat >= 3)) then
    Inc(Anzahl);
  // Ausgabe
  Label1.Caption := IntToStr(Anzahl);
end;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.


Zuletzt bearbeitet von Narses am Mi 22.11.06 01:09, insgesamt 1-mal bearbeitet
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 22.11.06 00:55 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button1(Sender: TObject);
var myDate : TDateTime;
    tag,monat,jahr : Integer;
begin
  // spinfelder auslesen
  tag := SpinEdit1.Value;
  monat := SpinEdit2.Value;
  jahr := SpinEdit3.Value;

  myDate := EncodeDate(jahr,monat,tag);
  Memo1.Lines.Add(DateToStr(myDate) +' day of year  = '+ IntToStr(DayOfTheYear(myDate)));

end;


//Die Datumsfunktionen berücksichtigen Schaltjahre

de.wikipedia.org/wiki/ISO_8601


Zuletzt bearbeitet von hathor am Mi 22.11.06 01:15, insgesamt 1-mal bearbeitet
VaNaTiC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 30



BeitragVerfasst: Mi 22.11.06 01:06 
Zwei Sachen sind mir in Deinem ursprünglichen Quellcode aufgefallen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
    // prüfen auf Schaltjahr 
    if ((jahr mod 4=0 and (jahr mod 100<>0)) or (jahr mod 400=0
      then schalt:=true //;FALSCH: hier bei einer einzelnen Anweisung KEIN Semikolon
      else schalt:=false; 


    //schaltjahr berücksichtigen 
    if schalt and(monat>=3)then inc(anzahl);    //anzahl:=anzahl+1; 

  end;//FEHLT: das ist das Ende Deiner Funktion!

end.// Das ist das Ende der UNIT, nicht das Ende Deiner Funktion
Tolgakan Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 22.11.06 19:50 
danke für eure tipps.Nach sorgfältigem Korrigieren bleibt dennoch ein Problem.Und zwar die Ausgabe.Wie muss die gemacht werden?Ich habe die Ausgabe mit Label4.caption gemacht , aber wenn ich das Programm starten will taucht bei der Ausgabe eine Fehlermeldung auf.danke euch allen
Tolgakan Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mi 22.11.06 19:52 
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
unit Unit_datum;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Spin, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    SpinEdit1: TSpinEdit;
    SpinEdit2: TSpinEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    SpinEdit3: TSpinEdit;
    Label4: TLabel;
    procedure SpinEdit1Change(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.SpinEdit1Change(Sender: TObject);
var tag,monat,jahr,anzahl:integer;
    schalt:boolean;
begin
   //spinfelder auslesen
   tag:=spinedit1.value;
   monat:=spinedit2.value;
   jahr:=spinedit3.value;

case monat of
1:Anzahl:=tag;
2:Anzahl:=tag+31;
3:Anzahl:=tag+59;
4:Anzahl:=tag+90;
5:Anzahl:=tag+120;
6:Anzahl:=tag+151;
7:Anzahl:=tag+181;
8:Anzahl:=tag+212;
9:Anzahl:=tag+243;
10:Anzahl:=tag+273;
11:Anzahl:=tag+304;
12:Anzahl:=tag+334;
end;       // von case



// prüfen auf Schaltjahr
if ((jahr mod 4)=0and ((jahr mod 100)<>0or ((jahr mod 400)=0)
      then schalt:=true
      else schalt:=false;









//schaltjahr berücksichtigen

if schalt and(monat>=3)then inc(anzahl);

end;  //anzahl:=anzahl+1;

Label4.caption := IntToStr(Anzahl);


end.





ich habe halt Label4.caption genommen , da ich die anderen(label1,label2,label3 )für die Bezeichungen Tag,Monat und Jahr verwendet habe.Das Ende stimmt angeblich nicht.

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8549
Erhaltene Danke: 478

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 22.11.06 19:57 
Vertausch mal die Zeilen 75 und 77.

Zusätzliche empfehle ich erstens mal ein vernünftiges Einrücken der einzelnen Codezeilen für einen besseren Überblick, und auch einen Blick in ein Einsteiger-Tutorial, wie z.B. dem hier.

_________________
We are, we were and will not be.
Tolgakan Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Do 23.11.06 13:35 
Vielen Dank Gausi.Nachdem ich die beiden Zeilen vertauscht habe,startes das Programm.Danke auch all den anderen, die mir ebenfalls geholfen haben.

MfG Tolgakan
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 23.11.06 13:48 
Moin!

Markierst du dann den Thread noch entsprechend, wenn dein Problem gelöst ist? Danke. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Tolgakan Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Fr 24.11.06 14:32 
Wie markiert man?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 24.11.06 14:39 
Moin!

Oben rechts in deinem ersten Beitrag auf den grünen Haken klicken.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.