473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

logische ausdrücke

hallo zusammen!

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

Eingabe (in Hauptprogramm):

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

Verknüpfungszeichen:
- 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(char zeile[max]);
int logischesUnd(char zeile[max]);
int logischesOderXor(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(zeile,sizeof(zeile));

umwandlung(zeile);

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

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

cout << "Hier werden die Werte die mit und verknüpft wurden ermitelt" <<
endl;
cout << zeile << endl;
logischesOderXor(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(char zeile[max]) {

int zeichen, kopieZeichen;

for (zeichen=0; zeichen!=max; ++zeichen)
{
if (zeile[zeichen] == ' ')
{for (kopieZeichen=zeichen; kopieZeichen!=max; ++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(char 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=zeichen; kopieZeichen!=max; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+2];
zeichen=0;
}

if (zeile[zeichen-1] == '0' || zeile[zeichen+1] == '0' )
{zeile[zeichen-1] = '0';
for (kopieZeichen=zeichen; kopieZeichen!=max; ++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 logischesOderXor(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=zeichen; kopieZeichen!=max; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+2];
zeichen=0;
}

if (zeile[zeichen-1] == '0' && zeile[zeichen+1] == '0' )
{zeile[zeichen-1] = '0';
for (kopieZeichen=zeichen; kopieZeichen!=max; ++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=zeichen; kopieZeichen!=max; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+4];
zeichen=0;
}
if (zeile[zeichen-1] == '0' && zeile[zeichen+3] == '1')
{zeile[zeichen-1] = '1';
for (kopieZeichen=zeichen; kopieZeichen!=max; ++kopieZeichen)
zeile[kopieZeichen] = zeile[kopieZeichen+4];
zeichen=0;
}

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

return zeile[max];
}

---------------------------------------------------------------------------------------------------
Mar 14 '06 #1
7 3759
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 aufgabenstellung:
[...]


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.********@comAcast.net> wrote:
jack sparrow wrote:
hallo zusammen!

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


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.iso-c++

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

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


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.iso-c++

--
Bob Hairgrove
No**********@Home.com

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

jack sparrow wrote:

hallo zusammen!

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

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.iso-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.iso-c++


My ISP has both.


Interesting, considering that de.comp.lang.c++ has been renamed to
de.comp.lang.iso-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.iso-c++


My ISP has both.

Interesting, considering that de.comp.lang.c++ has been renamed to
de.comp.lang.iso-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
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,...
3
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.