473,657 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

logische ausdrücke

hallo zusammen!

habe ein problem, ich muss als studienleistung ein programm schreiben mit
folgender aufgabenstellun g:
--------------------------------------------------------------------------------------------------------------------------
Berechnung des Werts eines logischen Ausdrucks

Eingabe (in Hauptprogramm):

Wahrheitswerte Wahr/Falsch in der Form W,w,F oder f

Verknüpfungszei chen:
- Und (Zeichen *),
- inklusives Oder (Zeichen +)
- exklusives Oder (Zeichenfolge xor, XOR oder auch Mischung
Klein-/Großbuchstaben)

Behandlung mit folgender Hierarchie:
*/xor höher als + (die beiden Operatoren * und xor in gleicher Vorrangstufe,
d.h. Abarbeitung von links nach rechts)

Leerzeichen beliebig (auch innerhalb xor)

max. Länge etwa 80 Zeichen (Eingabe als eine Zeichenkette), innerhalb dieser
Länge beliebig viele Operatoren und zugehörige Operanden.

Gesatprogramm als Schleife; Ende bei Eingabe eines $-Zeichens.

----------------------------------------------------------------------------------------------------------------------------

habe hier jetzt ein programm, das diesen zweck erfüllt. könnte man noch was
verbessern (siehe kommentare im text)?
----------------------------------------------------------------------------------------------------------------------------

*********** Berechnung des Wertes eines logischen Ausdrucks ********/

#include <iostream.h>

const int max=80;

//hier werden die Funktionen deklariert
int umwandlung(char zeile[max]);
int loeschBlanks(ch ar zeile[max]);
int logischesUnd(ch ar zeile[max]);
int logischesOderXo r(char zeile[max]);

int main()
{
char zeile[max];
cout << "Dieses Programm berechnet einen korrekten logischen Wert," <<
endl;
cout << "der in folgenden Zeile eingegeben werden kann." << endl;
cout << "Sie koennen es durch Eingabe eines -$- beenden." << endl;

//die Schleife fuehrt das programm aus,
//bis ein $ eingegeben wird
while(zeile[0]!= '$') {
cout << "Bitte geben sie einen korrekten logischen Wert in die zeile
ein:" << endl;

//einlesen der Zeile
cin.getline(zei le,sizeof(zeile ));

umwandlung(zeil e);

cout << "Hier wird die eingegebene Zeile in eine einheitliche Form
umgewandelt" << endl;
cout << zeile << endl;
loeschBlanks(ze ile);

cout << "Hier werden alle Leerzeichen entfernt" << endl;
cout << zeile << endl;
logischesUnd(ze ile);

cout << "Hier werden die Werte die mit und verknüpft wurden ermitelt" <<
endl;
cout << zeile << endl;
logischesOderXo r(zeile);

cout << "Hier werden nun noch die Werte die mit xor bzw oder vernüpft
wurden ermitelt" << endl;
cout << zeile << endl;

if (zeile[0] == '1')
cout << endl << "Der eingegebene Wert der Zeile war WAHR " << endl <<
endl<< endl;
if (zeile[0] == '0')
cout << endl << "Der eingegebene Wert der Zeile war FALSCH " << endl <<
endl<< endl;
if (zeile[0] == '$')
cout << endl << "Abbruch durch den Benutzer" << endl << endl<< endl;
//anmerkung: diese bedingung findet einige Fehler aber nicht alle.
//Fehler wie: fer for w*wghghg werden hier nicht erkannt
if (zeile[0] != '$' && zeile[0] != '1' && zeile[0] != '0')
cout << endl << "Sie haben einen fehlerhaften zeile eingegeben!" << endl <<
endl<< endl;
}

return 0;

}

//hier werden die Funktionen definiert

//Schreibe logischen zeile in einheitliche Form um, wichtig, damit die
//folgenden Schleifen die Operatoren erkennen
int umwandlung(char zeile[max]) {

int zeichen;

zeichen = 0;
while (zeichen!=max)
{
if (zeile[zeichen] == 'f' || zeile[zeichen] == 'F')
zeile[zeichen] = '0';
if (zeile[zeichen] == 'w' || zeile[zeichen] == 'W')
zeile[zeichen] = '1';
if (zeile[zeichen] == 'X')
zeile[zeichen] = 'x';
if (zeile[zeichen] == 'O')
zeile[zeichen] = 'o';
if (zeile[zeichen] == 'R')
zeile[zeichen] = 'r';
++zeichen;

}
return zeile[max];
}

//entferne alle blanks aus der Zeile
int loeschBlanks(ch ar zeile[max]) {

int zeichen, kopieZeichen;

for (zeichen=0; zeichen!=max; ++zeichen)
{
if (zeile[zeichen] == ' ')
{for (kopieZeichen=z eichen; kopieZeichen!=m ax; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+1];
zeichen=0;}
}

return zeile[max];
}
// zunächst das "und", da es höherrangig als oder und xor ist bekommt es
// eine eigene Schleife und wird zuerst ausgewertet
int logischesUnd(ch ar zeile[max]) {

int zeichen, kopieZeichen;

for (zeichen=0; zeichen!=max; ++zeichen)
{

if (zeile[zeichen] == '*' )
{if (zeile[zeichen-1] == '1' && zeile[zeichen+1] == '1')
{zeile[zeichen-1] = '1';
for (kopieZeichen=z eichen; kopieZeichen!=m ax; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+2];
zeichen=0;
}

if (zeile[zeichen-1] == '0' || zeile[zeichen+1] == '0' )
{zeile[zeichen-1] = '0';
for (kopieZeichen=z eichen; kopieZeichen!=m ax; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+2];
zeichen=0;
}
}
}
return zeile[max];

}

// nun das "oder", das oder und das xor können in eine gemeinsame
//schleife berechnet werden
int logischesOderXo r(char zeile[max]) {

int zeichen, kopieZeichen;

for (zeichen=0; zeichen!=max; ++zeichen)
{

if (zeile[zeichen] == '+' )
// "oder"
{if (zeile[zeichen-1] == '1' || zeile[zeichen+1] == '1')
{zeile[zeichen-1] = '1';
for (kopieZeichen=z eichen; kopieZeichen!=m ax; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+2];
zeichen=0;
}

if (zeile[zeichen-1] == '0' && zeile[zeichen+1] == '0' )
{zeile[zeichen-1] = '0';
for (kopieZeichen=z eichen; kopieZeichen!=m ax; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+2];
zeichen=0;
}
}
else {
//nun noch das "xor"
if (zeile[zeichen] == 'x' && zeile[zeichen+1] == 'o' &&
zeile[zeichen+2] == 'r')
{if (zeile[zeichen-1] == '1' && zeile[zeichen+3] == '0')
{zeile[zeichen-1] = '1';
for (kopieZeichen=z eichen; kopieZeichen!=m ax; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+4];
zeichen=0;
}
if (zeile[zeichen-1] == '0' && zeile[zeichen+3] == '1')
{zeile[zeichen-1] = '1';
for (kopieZeichen=z eichen; kopieZeichen!=m ax; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+4];
zeichen=0;
}

if (zeile[zeichen-1] == '0' && zeile[zeichen+3] == '0' )
{zeile[zeichen-1] = '0';
for (kopieZeichen=z eichen; kopieZeichen!=m ax; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+4];
zeichen=0;
}
if (zeile[zeichen-1] == '1' && zeile[zeichen+3] == '1' )
{zeile[zeichen-1] = '0';
for (kopieZeichen=z eichen; kopieZeichen!=m ax; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+4];
zeichen=0;
}
}
}
}

return zeile[max];
}

---------------------------------------------------------------------------------------------------
Mar 14 '06 #1
7 3773
jack sparrow wrote:
hallo zusammen!

[snip]

In English, please.

Cheers! --M

Mar 14 '06 #2
jack sparrow wrote:
hallo zusammen!

habe ein problem, ich muss als studienleistung ein programm schreiben mit
folgender aufgabenstellun g:
[...]


This is an English-speaking newsgroup. If you want to address
a German-speaking audience, post to 'de.comp.lang.c ++'.

Danke.
Mar 14 '06 #3
On Tue, 14 Mar 2006 16:41:03 -0500, Victor Bazarov
<v.********@com Acast.net> wrote:
jack sparrow wrote:
hallo zusammen!

habe ein problem, ich muss als studienleistung ein programm schreiben mit
folgender aufgabenstellun g:
[...]


This is an English-speaking newsgroup. If you want to address
a German-speaking audience, post to 'de.comp.lang.c ++'.

Danke.


It's actually de.comp.lang.is o-c++

--
Bob Hairgrove
No**********@Ho me.com
Mar 14 '06 #4
thx!
"Bob Hairgrove" <in*****@bigfoo t.com> schrieb im Newsbeitrag
news:h1******** *************** *********@4ax.c om...
On Tue, 14 Mar 2006 16:41:03 -0500, Victor Bazarov
<v.********@com Acast.net> wrote:
jack sparrow wrote:
hallo zusammen!

habe ein problem, ich muss als studienleistung ein programm schreiben
mit
folgender aufgabenstellun g:
[...]


This is an English-speaking newsgroup. If you want to address
a German-speaking audience, post to 'de.comp.lang.c ++'.

Danke.


It's actually de.comp.lang.is o-c++

--
Bob Hairgrove
No**********@Ho me.com

Mar 14 '06 #5
"Bob Hairgrove" <in*****@bigfoo t.com> schrieb im Newsbeitrag
news:h1******** *************** *********@4ax.c om...
On Tue, 14 Mar 2006 16:41:03 -0500, Victor Bazarov
<v.********@c omAcast.net> wrote:

jack sparrow wrote:

hallo zusammen!

habe ein problem, ich muss als studienleistung ein programm schreiben
mit
folgender aufgabenstellun g:
[...]

This is an English-speaking newsgroup. If you want to address
a German-speaking audience, post to 'de.comp.lang.c ++'.

Danke.


It's actually de.comp.lang.is o-c++


My ISP has both.

V
--
Please remove capital As from my address when replying by mail
Mar 14 '06 #6
Victor Bazarov wrote:
This is an English-speaking newsgroup. If you want to address
a German-speaking audience, post to 'de.comp.lang.c ++'.

Danke.

It's actually de.comp.lang.is o-c++


My ISP has both.


Interesting, considering that de.comp.lang.c+ + has been renamed to
de.comp.lang.is o-c++ in the past millennium. Seems your ISP's newsgroup
list is a bit outdated.

Mar 15 '06 #7
Rolf Magnus wrote:
Victor Bazarov wrote:

>This is an English-speaking newsgroup. If you want to address
>a German-speaking audience, post to 'de.comp.lang.c ++'.
>
>Danke.

It's actually de.comp.lang.is o-c++


My ISP has both.

Interesting, considering that de.comp.lang.c+ + has been renamed to
de.comp.lang.is o-c++ in the past millennium. Seems your ISP's newsgroup
list is a bit outdated.


Or it is an alias... I don't really speak or read German, it's all Greek
to me, so ...
Mar 15 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2436
by: Fredrik Henricsson | last post by:
Hey, I'm building an ontology in Protégé and I want to transform parts of it (e.g. the instances) to HTML with XSL. When I was transforming another file with 'simple' XML-tags like <author> before, I got it working, but the OWL-file is formatted differently and I don't know how to access the elements. I'll post the .owl file below, but this is basically what I want to get from the file (the course name): <Course...
3
4165
by: Mario.Reif | last post by:
We have developed an application which was running under DB2 v7.2.5 quite well for some years. Four weeks ago we installed DB2 v8.1.5 Express Fixpak 5 on a new Server (hardware is nearly the same as on the DB2 v7.2.5 machine). The new Server runs on Windows 2003. Last week we installed another server with the same hardware with DB2 8.1.5 Workgroup Server Fixpak 5 under Windows 2000 Server. Both servers running DB2 v8 databases are about...
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.