tutorials.de Buch-Aktion 05/2012
Like Tree2Danke
  • 1 Beitrag von Matthias Reitinger
  • 1 Beitrag von Matthias Reitinger
ERLEDIGT
JA
ANTWORTEN
3
ZUGRIFFE
216
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Googlehupf Googlehupf ist offline Mitglied Silber
    Registriert seit
    Jun 2011
    Beiträge
    76
    Hallo,

    ich hab ein Programm geschrieben das Komplexe Zahlen addiert, subthariert und multipliziert.
    Aber nur tritt einer Fehlermeldung(oder so) auf, wenn ich mit Einzelschritt durchgehe.

    Das Programm besteht aus einem H-File und 2 C-Files.

    Header-File:

    Code cpp:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    
    struct complex_struct
    {
      double real;
      double imag;
    };
    typedef struct complex_struct complex;
     
     
    complex c_add(complex a, complex b);
     
     
    complex c_sub(complex a, complex b);
     
    complex c_multi(complex a, complex b);
     
     
     
    void c_print_add(complex a);
     
    void c_print_sub(complex a);
     
     
    void c_print_multi(complex a);

    1. C-File(Unterprogramme):

    Code cpp:
    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
    
    #include "compl.h"
    #include <stdio.h>
     
    complex c_add(complex a, complex b)
    {
      complex result;
      result.real = a.real + b.real;
      result.imag = a.imag + b.imag;
      return result;
    }
     
    void c_print_add(complex a)
    {
      printf("%lf + j%lf",a.real,a.imag);
    }
     
     
    complex c_sub(complex a, complex b)
    {
      complex result;
        result.real = a.real - b.real;
        result.imag = a.imag - b.imag;
        return result;
    }
     
    void c_print_sub(complex a)
    {
      printf("%lf - j%lf",a.real,a.imag);
    }
     
    complex c_multi(complex a, complex b)
    {
      complex result;
     
      result.real = (a.real*b.real) + ((-1)*(a.imag*b.imag));
      result.imag = (a.imag*b.real) + (b.imag*a.real);
    }
     
    void c_print_multi(complex a)
    {
      printf("%lf j%lf",a.real,a.imag);
    }

    2.C-file(Hauptprogramm):

    Code cpp:
    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
    
    #include <stdio.h>
    #include "compl.h"
     
    void main()
    {
      complex c1 = {4.0,5.9};
      complex c2;
      complex c3;
     
      c2.real=7;
      c2.imag=0.1;
      c3 = c_add(c1,c2);
      c_print_add(c1);
      printf(" + ");
      c_print_add(c2);
      printf(" = ");
      c_print_add(c3);
      printf("\n");
     
      c2.real=7;
      c2.imag=0.1;
      c3 = c_sub(c1,c2);
      c_print_sub(c1);
      printf(" - ");
      c_print_sub(c2);
      printf(" = ");
      c_print_sub(c3);
      printf("\n");
     
      c2.real=7;
      c2.imag=0.1;
      c3 = c_multi(c1,c2);//hier kommt die Fehlermeldung(siehe pic)
      c_print_multi(c1);
      printf(" * ");
      c_print_multi(c2);
      printf(" = ");
      c_print_multi(c3);
      printf("\n");
    }

    Was könnte es da haben?

    Danke im voraus!

    mfg googlehupf
    Miniaturansicht angehängter Grafiken Miniaturansicht angehängter Grafiken Fehlermeldung(Unbehandlete Ausnahme bei...), Strukturen-error.png  
     

  2. #2
    Registriert seit
    Dec 2001
    Ort
    Bayern
    Beiträge
    5.802
    Blog-Einträge
    5
    Hallo,

    du hast in c_multi vergessen, einen Wert zurückzugeben. Hat dich dein Compiler etwa nicht darauf hingewiesen!?

    \edit: %lf gibt es bei printf nicht, es sollte einfach nur %f heißen.

    Grüße,
    Matthias
    Googlehupf bedankt sich. 
    „Gib einem Menschen einen Fisch, und er wird für einen Tag satt. Lehre ihn Fischen, und er wird ein Leben lang satt.“
    “For every complex problem, there is an answer that is short, simple and wrong.”
    “Pessimism is safe, but optimism is a lot faster!”


    Aktuelles Coding Quiz: #17 - Wörter kreuz und quer

  3. #3
    Googlehupf Googlehupf ist offline Mitglied Silber
    Registriert seit
    Jun 2011
    Beiträge
    76
    Ok, stimmt danke

    Ich hab ein Problem mit der komplexen Division, ich weis nicht wie ich die schreiben könnte..., weil wenn wir z.B haben 2+5,9j/7+0,5j dann müsste man konjungiert komplex erweitern und das ist irgendwie zu aufwendig zu programmieren finde ich.. gibts da keine einfachere Lösung?
     

  4. #4
    Registriert seit
    Dec 2001
    Ort
    Bayern
    Beiträge
    5.802
    Blog-Einträge
    5
    Zitat Zitat von Googlehupf Beitrag anzeigen
    Ich hab ein Problem mit der komplexen Division, ich weis nicht wie ich die schreiben könnte..., weil wenn wir z.B haben 2+5,9j/7+0,5j dann müsste man konjungiert komplex erweitern und das ist irgendwie zu aufwendig zu programmieren finde ich.. gibts da keine einfachere Lösung?
    Was ist denn daran zu aufwändig? Die Multiplikation hast du doch auch geschafft. Mehr musst du für die Division auch nicht beherrschen.

    Grüße,
    Matthias
    Googlehupf bedankt sich. 
    „Gib einem Menschen einen Fisch, und er wird für einen Tag satt. Lehre ihn Fischen, und er wird ein Leben lang satt.“
    “For every complex problem, there is an answer that is short, simple and wrong.”
    “Pessimism is safe, but optimism is a lot faster!”


    Aktuelles Coding Quiz: #17 - Wörter kreuz und quer

Ähnliche Themen

  1. Ausnahme für IE6 und der W3C Validator
    Von Eagle-PsyX- im Forum HTML & XHTML
    Antworten: 13
    Letzter Beitrag: 25.10.08, 23:13
  2. Einstellungen für die Ausnahme SQLException
    Von JSteinhilber im Forum Java
    Antworten: 1
    Letzter Beitrag: 07.02.08, 20:13
  3. Ausnahme bei new
    Von jokey2 im Forum VisualStudio & MFC
    Antworten: 5
    Letzter Beitrag: 17.09.06, 12:08
  4. Order by Ausnahme
    Von piti66 im Forum Relationale Datenbanksysteme
    Antworten: 5
    Letzter Beitrag: 13.01.06, 11:02
  5. [C++] - Unbehandelte Ausnahme...
    Von Rofi im Forum C/C++
    Antworten: 1
    Letzter Beitrag: 29.10.05, 00:28